Skip to content

Commit

Permalink
Fixed render solution in CLI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
solital committed Aug 3, 2024
1 parent 1a8f5ef commit b235803
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Released Notes

## v3.3.1 - (2024-08-03)

### Fixed

- Fixed render solution in CLI mode

--------------------------------------------------------------------------

## v3.3.0 - (2024-07-17)

### Added
Expand Down
12 changes: 3 additions & 9 deletions src/ModernPHPException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
namespace ModernPHPException;

use Symfony\Component\Yaml\Yaml;
use ModernPHPException\Trait\{
RenderTrait,
HelpersTrait,
HandlerAssetsTrait
};
use ModernPHPException\Trait\{RenderTrait, HelpersTrait, HandlerAssetsTrait};

class ModernPHPException
{
use HelpersTrait;
use HandlerAssetsTrait;
use RenderTrait;
use HelpersTrait, HandlerAssetsTrait, RenderTrait;

public const VERSION = "3.3.0";
public const VERSION = "3.3.1";

/**
* @var Bench
Expand Down
32 changes: 9 additions & 23 deletions src/Trait/RenderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace ModernPHPException\Trait;

use ModernPHPException\Console\CliMessage;
use ModernPHPException\Occurrences;
use ModernPHPException\Solution;
use ModernPHPException\{Occurrences, Solution};
use ModernPHPException\Resources\{CpuUsage, HtmlTag, MemoryUsage};

trait RenderTrait
Expand Down Expand Up @@ -74,10 +73,7 @@ protected function registerOccurrence(): void
*/
private function render(): never
{
if (ob_get_contents()) {
ob_end_clean();
}

if (ob_get_contents()) ob_end_clean();
$this->renderCli();

if (
Expand All @@ -90,9 +86,7 @@ private function render(): never
$this->renderJson();
}

if ($this->config['production_mode'] === true) {
$this->productionMode();
}
if ($this->config['production_mode'] === true) $this->productionMode();

// Don't erase `$resources` variable
$resources = $this->loadResources();
Expand All @@ -116,9 +110,7 @@ private function render(): never
private function filterTrace(array $trace): array
{
foreach ($trace as $key => $value) {
if (!array_key_exists('file', $value) && !array_key_exists('line', $value)) {
unset($trace[$key]);
}
if (!array_key_exists('file', $value) && !array_key_exists('line', $value)) unset($trace[$key]);
}

return $trace;
Expand All @@ -131,13 +123,8 @@ private function filterTrace(array $trace): array
*/
private function loadResources(): array
{
if ($this->config['title'] !== "") {
$this->title = $this->config['title'];
}

if ($this->config['dark_mode'] === true) {
$this->useDarkTheme();
}
if ($this->config['title'] !== "") $this->title = $this->config['title'];
if ($this->config['dark_mode'] === true) $this->useDarkTheme();

$list_occurrences = null;
$cpu_usage = CpuUsage::getServerLoad();
Expand Down Expand Up @@ -298,15 +285,14 @@ private function renderSolutionCli(): void

if (method_exists($exception, "getSolution")) {
$exception->getSolution();

$solution = new Solution();

if (!empty($this->solution->getDescription()) || $this->solution->getDescription() != "") {
$this->success($solution->getTitle())->print();
CliMessage::success($solution->getTitle())->print();
echo " : ";
$this->success($solution->getDescription())->print()->break(true);
CliMessage::success($solution->getDescription())->print()->break(true);
} else {
$this->success($solution->getTitle())->print()->break(true);
CliMessage::success($solution->getTitle())->print()->break(true);
}
}
}
Expand Down

0 comments on commit b235803

Please sign in to comment.