Skip to content

Commit 50d5344

Browse files
authored
Feature/upgrade psalm (#29)
Adding psalm v5 for php versions which support it
1 parent 0e2e4d9 commit 50d5344

15 files changed

+53
-21
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"squizlabs/php_codesniffer": "^3.5",
2929
"symfony/css-selector": "^4.4|^5.0",
3030
"symfony/dom-crawler": "^4.4|^5.0",
31-
"vimeo/psalm": "^3.12|^4.0"
31+
"vimeo/psalm": "^4.30|^5.22"
3232
},
3333
"autoload": {
3434
"psr-4": {

psalm.xml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
findUnusedBaselineEntry="true"
9+
findUnusedCode="false"
810
>
911
<projectFiles>
1012
<directory name="src/" />

src/analyzer/Model/TombstoneIndex.php

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Scheb\Tombstone\Core\Model\FilePathInterface;
88
use Scheb\Tombstone\Core\Model\Tombstone;
99

10+
/**
11+
* @template-implements \IteratorAggregate<array-key, Tombstone>
12+
*/
1013
class TombstoneIndex implements \Countable, \IteratorAggregate
1114
{
1215
/**

src/analyzer/Model/VampireIndex.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Scheb\Tombstone\Core\Model\Vampire;
88

9+
/**
10+
* @template-implements \IteratorAggregate<array-key, Vampire>
11+
*/
912
class VampireIndex implements \Countable, \IteratorAggregate
1013
{
1114
/**

src/analyzer/Report/Checkstyle/CheckstyleReportGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private function getCalledBy(Tombstone $tombstone): string
8282
}
8383

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

8787
$numAdditionalVampires = $numVampires - 1;
8888
if ($numAdditionalVampires > 0) {

src/analyzer/Report/Console/ConsoleReportGenerator.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ private function displayTombstones(array $result): void
9494
$this->newLine();
9595
$this->printTombstone($tombstone, 'RIP');
9696
$date = $tombstone->getTombstoneDate();
97-
if ($date) {
98-
if ($age = TimePeriodFormatter::formatAge($date)) {
97+
if (null !== $date) {
98+
$age = TimePeriodFormatter::formatAge($date);
99+
if (null !== $age) {
99100
$this->output->writeln(sprintf(' was not called for %s', $age));
100101
} else {
101102
$this->output->writeln(sprintf(' was not called since %s', $date));
@@ -109,10 +110,10 @@ private function printTombstone(Tombstone $tombstone, string $prefix): void
109110
$this->output->writeln(sprintf(' [%s] <info>%s</info>', $prefix, (string) $tombstone));
110111
$this->output->writeln(sprintf(' in <comment>line %s</comment>', $tombstone->getLine()));
111112
$method = $tombstone->getMethod();
112-
if ($method) {
113+
if (null !== $method) {
113114
$this->output->writeln(sprintf(' in method <comment>%s</comment>', $method));
114115
} else {
115-
$this->output->writeln(sprintf(' in global scope'));
116+
$this->output->writeln(' in global scope');
116117
}
117118
}
118119

src/analyzer/Report/Html/Renderer/DashboardRenderer.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ private function getDeadSince(Tombstone $tombstone): string
131131
return 'since unknown';
132132
}
133133

134-
if ($age = TimePeriodFormatter::formatAge($date)) {
134+
$age = TimePeriodFormatter::formatAge($date);
135+
if (null !== $age) {
135136
return 'for '.$age;
136137
}
137138

@@ -167,7 +168,7 @@ private function renderInvokers(Tombstone $tombstone): string
167168
$invokersString = '';
168169
foreach ($invokers as $invoker) {
169170
$this->invokerTemplate->setVar([
170-
'invoker' => $invoker ? htmlspecialchars($invoker) : 'global scope',
171+
'invoker' => null !== $invoker ? htmlspecialchars($invoker) : 'global scope',
171172
]);
172173
$invokersString .= $this->invokerTemplate->render();
173174
}
@@ -218,7 +219,8 @@ private function renderDeletedTombstones(AnalyzerFileResult $fileResult): string
218219
private function getLastCalled(Vampire $vampire): string
219220
{
220221
$invocationDate = $vampire->getInvocationDate();
221-
if ($age = TimePeriodFormatter::formatAge($invocationDate)) {
222+
$age = TimePeriodFormatter::formatAge($invocationDate);
223+
if (null !== $age) {
222224
return $age;
223225
}
224226

@@ -228,7 +230,7 @@ private function getLastCalled(Vampire $vampire): string
228230
private function getTombstoneScope(Tombstone $tombstone): string
229231
{
230232
$method = $tombstone->getMethod();
231-
if ($method) {
233+
if (null !== $method) {
232234
return sprintf('method <samp>%s</samp>', htmlspecialchars($method));
233235
}
234236

src/analyzer/Report/Html/Renderer/PhpFileFormatter.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ private function formatTokens(array $tokens): \Traversable
4949
$stringFlag = false;
5050
$result = '';
5151
foreach ($tokens as $j => $token) {
52+
$previousToken = $j > 0 ? $tokens[$j - 1] : null;
5253
if (\is_string($token)) {
53-
if ('"' === $token && '\\' !== $tokens[$j - 1]) {
54+
if ('"' === $token && '\\' !== $previousToken) {
5455
$result .= $this->highlighter->formatString($token);
5556
$stringFlag = !$stringFlag;
5657
} else {

src/analyzer/Report/TimePeriodFormatter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TimePeriodFormatter
1111
public static function formatAge(string $date): ?string
1212
{
1313
$tombstoneDate = strtotime($date);
14-
if (!$tombstoneDate) {
14+
if (false === $tombstoneDate) {
1515
return null;
1616
}
1717

src/analyzer/Stock/TombstoneNodeVisitor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(TombstoneExtractor $tombstoneCallback, array $tombst
4242
$this->tombstoneFunctionNames = $tombstoneFunctionNames;
4343
}
4444

45-
public function enterNode(Node $node)
45+
public function enterNode(Node $node): void
4646
{
4747
parent::enterNode($node);
4848
if ($node instanceof Class_) {
@@ -114,7 +114,7 @@ private function visitStaticCallNode(StaticCall $node): void
114114
}
115115
}
116116

117-
public function leaveNode(Node $node)
117+
public function leaveNode(Node $node): void
118118
{
119119
parent::leaveNode($node);
120120
if ($node instanceof ClassMethod || $node instanceof Function_) {

src/core/Model/RootPath.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ private function createRelativePath(string $path): RelativeFilePath
6969
{
7070
if ('' !== $path && '.' === $path[0]) {
7171
if ('.' === $path) {
72-
$path = ''; // Path is equal root path
73-
} elseif ('.' === $path[0]) {
74-
// Remove leading "./"
75-
$path = preg_replace('#^(\\./)+#', '', $path);
72+
// Path is equal root path
73+
return new RelativeFilePath('', $this);
7674
}
75+
// Remove leading "./"
76+
$path = preg_replace('#^(\\./)+#', '', $path);
7777
}
7878

7979
return new RelativeFilePath($path, $this);

src/core/Model/StackTrace.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Scheb\Tombstone\Core\Model;
66

7-
class StackTrace implements \Countable, \IteratorAggregate, \ArrayAccess
7+
class StackTrace implements \Countable, StackTraceInterface
88
{
99
/**
1010
* @var StackTraceFrame[]
@@ -32,7 +32,7 @@ public function count(): int
3232
}
3333

3434
/**
35-
* @return \Traversable<int, StackTraceFrame>
35+
* @return \Traversable<array-key, StackTraceFrame>
3636
*/
3737
public function getIterator(): \Traversable
3838
{
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Scheb\Tombstone\Core\Model;
6+
7+
/**
8+
* @extends \IteratorAggregate<array-key, StackTraceFrame>
9+
* @extends \ArrayAccess<array-key, StackTraceFrame>
10+
*/
11+
interface StackTraceInterface extends \IteratorAggregate, \ArrayAccess
12+
{
13+
public function getHash(): int;
14+
}

src/logger/Handler/PsrLoggerHandler.php

+6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ class PsrLoggerHandler extends AbstractHandler
1414
*/
1515
private $logger;
1616

17+
/**
18+
* @var string|int|mixed
19+
*/
1720
private $level;
1821

22+
/**
23+
* @param string|int|mixed $level
24+
*/
1925
public function __construct(LoggerInterface $logger, $level)
2026
{
2127
$this->logger = $logger;

src/logger/Handler/StreamHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct($stream, ?int $filePermission = null, $useLocking =
7171

7272
public function close(): void
7373
{
74-
if ($this->url && \is_resource($this->stream)) {
74+
if (null !== $this->url && \is_resource($this->stream)) {
7575
fclose($this->stream);
7676
}
7777
$this->stream = null;

0 commit comments

Comments
 (0)