Skip to content

Commit

Permalink
Fixing Psalm errors
Browse files Browse the repository at this point in the history
Fixing erros as with v5 Psalm has gottern more strict
  • Loading branch information
JimTools committed Feb 22, 2024
1 parent 4aae5aa commit df55c55
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/analyzer/Model/TombstoneIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Scheb\Tombstone\Core\Model\FilePathInterface;
use Scheb\Tombstone\Core\Model\Tombstone;

/**
* @template-implements \IteratorAggregate<array-key, Tombstone>
*/
class TombstoneIndex implements \Countable, \IteratorAggregate
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/analyzer/Model/VampireIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Scheb\Tombstone\Core\Model\Vampire;

/**
* @template-implements \IteratorAggregate<array-key, Vampire>
*/
class VampireIndex implements \Countable, \IteratorAggregate
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function getCalledBy(Tombstone $tombstone): string
}

$invoker = array_shift($vampires)->getInvoker();
$calledBy = sprintf(' by "%s"', $invoker ?: 'global scope');
$calledBy = sprintf(' by "%s"', null !== $invoker ? $invoker : 'global scope');

$numAdditionalVampires = $numVampires - 1;
if ($numAdditionalVampires > 0) {
Expand Down
9 changes: 5 additions & 4 deletions src/analyzer/Report/Console/ConsoleReportGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ private function displayTombstones(array $result): void
$this->newLine();
$this->printTombstone($tombstone, 'RIP');
$date = $tombstone->getTombstoneDate();
if ($date) {
if ($age = TimePeriodFormatter::formatAge($date)) {
if (null !== $date) {
$age = TimePeriodFormatter::formatAge($date);
if (null !== $age) {
$this->output->writeln(sprintf(' was not called for %s', $age));
} else {
$this->output->writeln(sprintf(' was not called since %s', $date));
Expand All @@ -109,10 +110,10 @@ private function printTombstone(Tombstone $tombstone, string $prefix): void
$this->output->writeln(sprintf(' [%s] <info>%s</info>', $prefix, (string) $tombstone));
$this->output->writeln(sprintf(' in <comment>line %s</comment>', $tombstone->getLine()));
$method = $tombstone->getMethod();
if ($method) {
if (null !== $method) {
$this->output->writeln(sprintf(' in method <comment>%s</comment>', $method));
} else {
$this->output->writeln(sprintf(' in global scope'));
$this->output->writeln(' in global scope');
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/analyzer/Report/Html/Renderer/DashboardRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ private function getDeadSince(Tombstone $tombstone): string
return 'since unknown';
}

if ($age = TimePeriodFormatter::formatAge($date)) {
$age = TimePeriodFormatter::formatAge($date);
if (null !== $age) {
return 'for '.$age;
}

Expand Down Expand Up @@ -167,7 +168,7 @@ private function renderInvokers(Tombstone $tombstone): string
$invokersString = '';
foreach ($invokers as $invoker) {
$this->invokerTemplate->setVar([
'invoker' => $invoker ? htmlspecialchars($invoker) : 'global scope',
'invoker' => null !== $invoker ? htmlspecialchars($invoker) : 'global scope',
]);
$invokersString .= $this->invokerTemplate->render();
}
Expand Down Expand Up @@ -218,7 +219,8 @@ private function renderDeletedTombstones(AnalyzerFileResult $fileResult): string
private function getLastCalled(Vampire $vampire): string
{
$invocationDate = $vampire->getInvocationDate();
if ($age = TimePeriodFormatter::formatAge($invocationDate)) {
$age = TimePeriodFormatter::formatAge($invocationDate);
if (null !== $age) {
return $age;
}

Expand All @@ -228,7 +230,7 @@ private function getLastCalled(Vampire $vampire): string
private function getTombstoneScope(Tombstone $tombstone): string
{
$method = $tombstone->getMethod();
if ($method) {
if (null !== $method) {
return sprintf('method <samp>%s</samp>', htmlspecialchars($method));
}

Expand Down
3 changes: 2 additions & 1 deletion src/analyzer/Report/Html/Renderer/PhpFileFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ private function formatTokens(array $tokens): \Traversable
$stringFlag = false;
$result = '';
foreach ($tokens as $j => $token) {
$previousToken = $j > 0 ? $tokens[$j - 1] : null;
if (\is_string($token)) {
if ('"' === $token && '\\' !== $tokens[$j - 1]) {
if ('"' === $token && '\\' !== $previousToken) {
$result .= $this->highlighter->formatString($token);
$stringFlag = !$stringFlag;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/Report/TimePeriodFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TimePeriodFormatter
public static function formatAge(string $date): ?string
{
$tombstoneDate = strtotime($date);
if (!$tombstoneDate) {
if (false === $tombstoneDate) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/Stock/TombstoneNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(TombstoneExtractor $tombstoneCallback, array $tombst
$this->tombstoneFunctionNames = $tombstoneFunctionNames;
}

public function enterNode(Node $node)
public function enterNode(Node $node): void
{
parent::enterNode($node);
if ($node instanceof Class_) {
Expand Down Expand Up @@ -114,7 +114,7 @@ private function visitStaticCallNode(StaticCall $node): void
}
}

public function leaveNode(Node $node)
public function leaveNode(Node $node): void
{
parent::leaveNode($node);
if ($node instanceof ClassMethod || $node instanceof Function_) {
Expand Down
8 changes: 4 additions & 4 deletions src/core/Model/RootPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ private function createRelativePath(string $path): RelativeFilePath
{
if ('' !== $path && '.' === $path[0]) {
if ('.' === $path) {
$path = ''; // Path is equal root path
} elseif ('.' === $path[0]) {
// Remove leading "./"
$path = preg_replace('#^(\\./)+#', '', $path);
// Path is equal root path
return new RelativeFilePath('', $this);
}
// Remove leading "./"
$path = preg_replace('#^(\\./)+#', '', $path);
}
return new RelativeFilePath($path, $this);
Expand Down
4 changes: 2 additions & 2 deletions src/core/Model/StackTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Scheb\Tombstone\Core\Model;

class StackTrace implements \Countable, \IteratorAggregate, \ArrayAccess
class StackTrace implements \Countable, StackTraceInterface
{
/**
* @var StackTraceFrame[]
Expand Down Expand Up @@ -32,7 +32,7 @@ public function count(): int
}

/**
* @return \Traversable<int, StackTraceFrame>
* @return \Traversable<array-key, StackTraceFrame>
*/
public function getIterator(): \Traversable
{
Expand Down
14 changes: 14 additions & 0 deletions src/core/Model/StackTraceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Scheb\Tombstone\Core\Model;

/**
* @extends \IteratorAggregate<array-key, StackTraceFrame>
* @extends \ArrayAccess<array-key, StackTraceFrame>
*/
interface StackTraceInterface extends \IteratorAggregate, \ArrayAccess
{
public function getHash(): int;
}
2 changes: 1 addition & 1 deletion src/logger/Handler/StreamHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct($stream, ?int $filePermission = null, $useLocking =

public function close(): void
{
if ($this->url && \is_resource($this->stream)) {
if (null !== $this->url && \is_resource($this->stream)) {
fclose($this->stream);
}
$this->stream = null;
Expand Down

0 comments on commit df55c55

Please sign in to comment.