Skip to content

Commit 8b9dfa5

Browse files
committed
Update to psalm 6
1 parent b42c3ee commit 8b9dfa5

8 files changed

Lines changed: 60 additions & 16 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"phpunit/phpunit": "^9",
4242
"amphp/phpunit-util": "^3",
4343
"amphp/php-cs-fixer-config": "^2",
44-
"psalm/phar": "^5.18"
44+
"psalm/phar": "6.16.1"
4545
},
4646
"autoload": {
4747
"psr-4": {

examples/shared-memory-parcel.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
// Create a parcel that then can be accessed in any number of child processes or threads.
1515
$parcel = SharedMemoryParcel::create($mutex, 1);
1616

17-
printf("Parent %d created semaphore %s and parcel: %s\n", getmypid(), $semaphore->getKey(), $parcel->getKey());
17+
$pid = getmypid();
18+
if ($pid === false) {
19+
print "Unable to determine PID";
20+
exit(1);
21+
}
22+
23+
printf("Parent %d created semaphore %s and parcel: %s\n", $pid, $semaphore->getKey(), $parcel->getKey());
1824

1925
// Send semaphore and parcel key to child process as command argument.
2026
$context = contextFactory()->start([

examples/worker/FetchTask.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public function __construct(string $url)
2020

2121
public function run(Channel $channel, Cancellation $cancellation): mixed
2222
{
23-
return \file_get_contents($this->url);
23+
$contents = \file_get_contents($this->url);
24+
if ($contents === false) {
25+
throw new \RuntimeException("Unable to read from {$this->url}");
26+
}
27+
28+
return $contents;
2429
}
2530
}

examples/worker/parent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
print strlen($bodies[1]) . PHP_EOL;
2323

2424
print PHP_EOL;
25-
print 'Took ' . (microtime(true) - $start) . ' seconds' . PHP_EOL;
25+
print 'Took ' . number_format(microtime(true) - $start, 2) . ' seconds' . PHP_EOL;

psalm.xml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,51 @@
2323
</errorLevel>
2424
</StringIncrement>
2525

26-
<MissingClosureReturnType>
26+
<ClassMustBeFinal>
2727
<errorLevel type="suppress">
28-
<directory name="src"/>
28+
<file name="src/Worker/WorkerException.php"/>
29+
<file name="src/Context/ContextException.php"/>
30+
<file name="src/Context/StatusError.php"/>
2931
</errorLevel>
30-
</MissingClosureReturnType>
32+
</ClassMustBeFinal>
3133

3234
<DocblockTypeContradiction>
3335
<errorLevel type="suppress">
3436
<directory name="src"/>
3537
</errorLevel>
3638
</DocblockTypeContradiction>
3739

38-
<UndefinedClass>
40+
<MissingOverrideAttribute>
3941
<errorLevel type="suppress">
42+
<directory name="examples"/>
4043
<directory name="src"/>
4144
</errorLevel>
42-
</UndefinedClass>
45+
</MissingOverrideAttribute>
46+
47+
<UnusedClass>
48+
<errorLevel type="suppress">
49+
<directory name="src"/>
50+
</errorLevel>
51+
</UnusedClass>
52+
53+
<PossiblyUnusedMethod>
54+
<errorLevel type="suppress">
55+
<directory name="src"/>
56+
</errorLevel>
57+
</PossiblyUnusedMethod>
58+
59+
<UnusedVariable>
60+
<errorLevel type="suppress">
61+
<directory name="examples"/>
62+
<directory name="src"/>
63+
</errorLevel>
64+
</UnusedVariable>
4365

44-
<UndefinedFunction>
66+
<UndefinedClass>
4567
<errorLevel type="suppress">
46-
<referencedFunction name="str_increment"/>
68+
<directory name="src"/>
4769
</errorLevel>
48-
</UndefinedFunction>
70+
</UndefinedClass>
4971

5072
<UnsupportedPropertyReferenceUsage>
5173
<errorLevel type="suppress">

src/Context/ProcessContext.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public static function start(
112112
}
113113

114114
$contents = \file_get_contents(self::SCRIPT_PATH);
115+
if ($contents === false) {
116+
throw new ContextException("Unable to read script '" . self::SCRIPT_PATH . "'");
117+
}
118+
115119
$contents = \str_replace("__DIR__", \var_export($path, true), $contents);
116120
$suffix = \bin2hex(\random_bytes(10));
117121
self::$pharScriptPath = $scriptPath = \sys_get_temp_dir() . "/amp-process-runner-" . $suffix . ".php";

src/Context/ThreadContext.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ public static function start(
136136

137137
private bool $exited = false;
138138

139+
/**
140+
* @throws ContextException
141+
*/
139142
private function __construct(
140143
private readonly int $id,
141144
private readonly Runtime $runtime,
@@ -151,7 +154,12 @@ private function __construct(
151154
$exited = true;
152155
});
153156

154-
$this->oid = \getmypid();
157+
$pid = \getmypid();
158+
if ($pid === false) {
159+
throw new ContextException("Failed to determine PID");
160+
}
161+
162+
$this->oid = $pid;
155163
}
156164

157165
public function receive(?Cancellation $cancellation = null): mixed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Amp\Parallel\Test\Context;
44

55
use PHPUnit\Framework\TestCase;
66
use function Amp\Parallel\Context\flattenArgument;
7-
use function sqrt;
87

98
class FlattenArgumentTest extends TestCase
109
{
1110
public function testNan()
1211
{
1312
self::assertSame('NAN', flattenArgument(\sqrt(-1)));
1413
}
15-
}
14+
}

0 commit comments

Comments
 (0)