Skip to content

Commit 457738c

Browse files
authored
Merge pull request #410 from TysonAndre/fix-notices
Fix php 8.4 notices about implicitly nullable parameters
2 parents 4fd2db9 + 45291ee commit 457738c

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

src/Node.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function getRoot() : Node {
151151
* @param callable|null $shouldDescendIntoChildrenFn
152152
* @return \Generator|Node[]|Token[]
153153
*/
154-
public function getDescendantNodesAndTokens(callable $shouldDescendIntoChildrenFn = null) {
154+
public function getDescendantNodesAndTokens(?callable $shouldDescendIntoChildrenFn = null) {
155155
// TODO - write unit tests to prove invariants
156156
// (concatenating all descendant Tokens should produce document, concatenating all Nodes should produce document)
157157
foreach ($this->getChildNodesAndTokens() as $child) {
@@ -176,7 +176,7 @@ public function getDescendantNodesAndTokens(callable $shouldDescendIntoChildrenF
176176
* @param callable|null $shouldDescendIntoChildrenFn
177177
* @return void
178178
*/
179-
public function walkDescendantNodesAndTokens(callable $callback, callable $shouldDescendIntoChildrenFn = null) {
179+
public function walkDescendantNodesAndTokens(callable $callback, ?callable $shouldDescendIntoChildrenFn = null) {
180180
// TODO - write unit tests to prove invariants
181181
// (concatenating all descendant Tokens should produce document, concatenating all Nodes should produce document)
182182
foreach (static::CHILD_NAMES as $name) {
@@ -209,7 +209,7 @@ public function walkDescendantNodesAndTokens(callable $callback, callable $shoul
209209
* @param callable|null $shouldDescendIntoChildrenFn
210210
* @return \Generator|Node[]
211211
*/
212-
public function getDescendantNodes(callable $shouldDescendIntoChildrenFn = null) {
212+
public function getDescendantNodes(?callable $shouldDescendIntoChildrenFn = null) {
213213
foreach ($this->getChildNodes() as $child) {
214214
yield $child;
215215
if ($shouldDescendIntoChildrenFn === null || $shouldDescendIntoChildrenFn($child)) {
@@ -223,7 +223,7 @@ public function getDescendantNodes(callable $shouldDescendIntoChildrenFn = null)
223223
* @param callable|null $shouldDescendIntoChildrenFn
224224
* @return \Generator|Token[]
225225
*/
226-
public function getDescendantTokens(callable $shouldDescendIntoChildrenFn = null) {
226+
public function getDescendantTokens(?callable $shouldDescendIntoChildrenFn = null) {
227227
foreach ($this->getChildNodesAndTokens() as $child) {
228228
if ($child instanceof Node) {
229229
if ($shouldDescendIntoChildrenFn == null || $shouldDescendIntoChildrenFn($child)) {

src/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected function makeLexer(string $fileContents): TokenStreamProviderInterface
175175
* @param string $fileContents
176176
* @return SourceFileNode
177177
*/
178-
public function parseSourceFile(string $fileContents, string $uri = null) : SourceFileNode {
178+
public function parseSourceFile(string $fileContents, ?string $uri = null) : SourceFileNode {
179179
$this->lexer = $this->makeLexer($fileContents);
180180

181181
$this->reset();
@@ -1417,7 +1417,7 @@ private function parseStringLiteralExpression2($parentNode): StringLiteral {
14171417
case TokenKind::DollarOpenBraceToken:
14181418
case TokenKind::OpenBraceDollarToken:
14191419
$expression->children[] = $this->eat(TokenKind::DollarOpenBraceToken, TokenKind::OpenBraceDollarToken);
1420-
/**
1420+
/**
14211421
* @phpstan-ignore-next-line "Strict comparison using
14221422
* === between 403|404 and 408 will always evaluate to
14231423
* false" is wrong because those tokens were eaten above

src/Token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getLeadingCommentsAndWhitespaceText(string $document) : string {
4242
* @param string|null $document
4343
* @return bool|null|string
4444
*/
45-
public function getText(string $document = null) {
45+
public function getText(?string $document = null) {
4646
if ($document === null) {
4747
return null;
4848
}

tests/LexicalGrammarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LexicalGrammarTest extends TestCase {
1717
private $expectedTokensFile;
1818
private $tokens;
1919
const FILE_PATTERN = __DIR__ . "/cases/lexical/*";
20-
public function run(TestResult $result = null) : TestResult {
20+
public function run(?TestResult $result = null) : TestResult {
2121
if (!isset($GLOBALS["GIT_CHECKOUT_LEXER"])) {
2222
$GLOBALS["GIT_CHECKOUT_LEXER"] = true;
2323
exec("git -C " . dirname(self::FILE_PATTERN) . " checkout *.php.tokens");

tests/ParserGrammarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ParserGrammarTest extends TestCase {
1919
private $expectedDiagnosticsFile;
2020
private $tokens;
2121
private $diagnostics;
22-
public function run(TestResult $result = null) : TestResult {
22+
public function run(?TestResult $result = null) : TestResult {
2323
if (!isset($GLOBALS["GIT_CHECKOUT_PARSER"])) {
2424
$GLOBALS["GIT_CHECKOUT_PARSER"] = true;
2525
exec("git -C " . dirname(self::FILE_PATTERN) . " checkout *.php.tree *.php.diag");

tests/generate_spec_tests.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
//$testCases = array('C:\src\php-investigations\tolerant-php-parser\tests\..\php-langspec\tests\traits\traits.phpt');
99
$sep = DIRECTORY_SEPARATOR;
10-
$testCases = glob(__DIR__ . "${sep}..${sep}php-langspec${sep}tests${sep}**${sep}*.phpt");
11-
$outTestCaseDir = __DIR__ . "${sep}cases${sep}php-langspec${sep}";
10+
$testCases = glob(__DIR__ . "{$sep}..{$sep}php-langspec{$sep}tests{$sep}**{$sep}*.phpt");
11+
$outTestCaseDir = __DIR__ . "{$sep}cases{$sep}php-langspec{$sep}";
1212
mkdir($outTestCaseDir);
1313
file_put_contents($outTestCaseDir . "README.md", "Auto-generated from php/php-langspec tests");
1414

0 commit comments

Comments
 (0)