Skip to content

Commit

Permalink
Fix (most of the) psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Aug 16, 2021
1 parent 6c71e79 commit d4b3146
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 37 deletions.
7 changes: 2 additions & 5 deletions psalm.xml
Expand Up @@ -35,13 +35,10 @@
<UndefinedClass>
<errorLevel type="suppress">
<file name="src/ErrorPage/ErrorPageViewModel.php" />
<file name="src/ErrorPage/IgnitionExceptionRenderer.php" />
<file name="src/IgnitionServiceProvider.php" />
</errorLevel>
</UndefinedClass>
<UnusedClosureParam>
<errorLevel type="suppress">
<file name="src/SolutionProviders/InvalidRouteActionSolutionProvider.php" />
</errorLevel>
</UnusedClosureParam>
</issueHandlers>

<plugins>
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/ShareReportAction.php
Expand Up @@ -153,7 +153,7 @@ protected function getCustomContextGroups(array $contextItems): array
];

return Collection::make($contextItems)
->reject(function ($value, $group) use ($predefinedContextItemGroups) {
->reject(function ($_value, $group) use ($predefinedContextItemGroups) {
return in_array($group, $predefinedContextItemGroups);
})
->keys()
Expand Down
4 changes: 3 additions & 1 deletion src/Context/LaravelRequestContext.php
Expand Up @@ -72,7 +72,9 @@ protected function getRouteParameters(): array
{
try {
return collect(optional($this->request->route())->parameters ?? [])
->map(fn ($parameter) => $parameter instanceof Model ? $parameter->withoutRelations() : $parameter)
->map(function ($parameter) {
return $parameter instanceof Model ? $parameter->withoutRelations() : $parameter;
})
->toArray();
} catch (Throwable $e) {
return [];
Expand Down
1 change: 1 addition & 0 deletions src/ErrorPage/IgnitionExceptionRenderer.php
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Foundation\ExceptionRenderer;

/** @psalm-suppress UndefinedClass */
class IgnitionExceptionRenderer implements ExceptionRenderer
{
/** @var \Facade\Ignition\ErrorPage\ErrorPageHandler */
Expand Down
2 changes: 1 addition & 1 deletion src/ErrorPage/Renderer.php
Expand Up @@ -22,7 +22,7 @@ public function render(string $viewName, array $_data): string
$viewFile = "{$this->viewPath}/{$viewName}.php";

try {
extract((array) $_data, EXTR_OVERWRITE);
extract($_data, EXTR_OVERWRITE);

include $viewFile;
} catch (Exception $exception) {
Expand Down
1 change: 1 addition & 0 deletions src/IgnitionServiceProvider.php
Expand Up @@ -504,6 +504,7 @@ protected function setupQueue(QueueManager $queue)
// Note: the $queue->looping() event can't be used because it's not triggered on Vapor
}

/** @psalm-suppress UndefinedClass */
protected function setupOctane()
{
$this->app['events']->listen(RequestReceived::class, function () {
Expand Down
20 changes: 10 additions & 10 deletions src/Logger/FlareHandler.php
Expand Up @@ -33,33 +33,33 @@ public function setMinimumReportLogLevel(int $level)
$this->minimumReportLogLevel = $level;
}

protected function write(array $report): void
protected function write(array $record): void
{
if (! $this->shouldReport($report)) {
if (! $this->shouldReport($record)) {
return;
}

if ($this->hasException($report)) {
if ($this->hasException($record)) {
/** @var Throwable $throwable */
$throwable = $report['context']['exception'];
$throwable = $record['context']['exception'];

collect(Ignition::$tabs)
->each(function (Tab $tab) use ($throwable) {
$tab->beforeRenderingErrorPage($this->flare, $throwable);
});

$this->flare->report($report['context']['exception']);
$this->flare->report($record['context']['exception']);

return;
}

if (config('flare.send_logs_as_events')) {
if ($this->hasValidLogLevel($report)) {
if ($this->hasValidLogLevel($record)) {
$this->flare->reportMessage(
$report['message'],
'Log ' . Logger::getLevelName($report['level']),
function (Report $flareReport) use ($report) {
foreach ($report['context'] as $key => $value) {
$record['message'],
'Log ' . Logger::getLevelName($record['level']),
function (Report $flareReport) use ($record) {
foreach ($record['context'] as $key => $value) {
$flareReport->context($key, $value);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/SolutionProviders/InvalidRouteActionSolutionProvider.php
Expand Up @@ -60,10 +60,10 @@ protected function findRelatedController(string $invalidController): ?string
$composerClassMap = app(ComposerClassMap::class);

$controllers = collect($composerClassMap->listClasses())
->filter(function (string $file, string $fqcn) {
->filter(function (string $_file, string $fqcn) {
return Str::endsWith($fqcn, 'Controller');
})
->mapWithKeys(function (string $file, string $fqcn) {
->mapWithKeys(function (string $_file, string $fqcn) {
return [$fqcn => class_basename($fqcn)];
})
->toArray();
Expand Down
2 changes: 1 addition & 1 deletion src/SolutionProviders/MergeConflictSolutionProvider.php
Expand Up @@ -51,7 +51,7 @@ protected function getCurrentBranch(string $directory): string
{
$branch = "'".trim(shell_exec("cd ${directory}; git branch | grep \\* | cut -d ' ' -f2"))."'";

if (! isset($branch) || $branch === "''") {
if ($branch === "''") {
$branch = 'current branch';
}

Expand Down
38 changes: 22 additions & 16 deletions src/SolutionProviders/UndefinedVariableSolutionProvider.php
Expand Up @@ -17,7 +17,7 @@ class UndefinedVariableSolutionProvider implements HasSolutionsForThrowable

public function canSolve(Throwable $throwable): bool
{
if (! $throwable instanceof ViewException) {
if (!$throwable instanceof ViewException) {
return false;
}

Expand All @@ -30,7 +30,7 @@ public function getSolutions(Throwable $throwable): array

extract($this->getNameAndView($throwable));

if (! isset($variableName)) {
if (!isset($variableName)) {
return [];
}

Expand All @@ -45,20 +45,26 @@ protected function findCorrectVariableSolutions(
string $variableName,
string $viewFile
): array {
return collect($throwable->getViewData())->map(function ($value, $key) use ($variableName) {
similar_text($variableName, $key, $percentage);

return ['match' => $percentage, 'value' => $value];
})->sortByDesc('match')->filter(function ($var, $key) {
return $var['match'] > 40;
})->keys()->map(function ($suggestion) use ($variableName, $viewFile) {
return new SuggestCorrectVariableNameSolution($variableName, $viewFile, $suggestion);
})->map(function ($solution) {
return $solution->isRunnable()
? $solution
: BaseSolution::create($solution->getSolutionTitle())
->setSolutionDescription($solution->getSolutionDescription());
})->toArray();
return collect($throwable->getViewData())
->map(function ($value, $key) use ($variableName) {
similar_text($variableName, $key, $percentage);

return ['match' => $percentage, 'value' => $value];
})
->sortByDesc('match')->filter(function ($var) {
return $var['match'] > 40;
})
->keys()
->map(function ($suggestion) use ($variableName, $viewFile) {
return new SuggestCorrectVariableNameSolution($variableName, $viewFile, $suggestion);
})
->map(function ($solution) {
return $solution->isRunnable()
? $solution
: BaseSolution::create($solution->getSolutionTitle())
->setSolutionDescription($solution->getSolutionDescription());
})
->toArray();
}

protected function findOptionalVariableSolution(string $variableName, string $viewFile)
Expand Down

0 comments on commit d4b3146

Please sign in to comment.