Skip to content

Commit

Permalink
Fix build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jul 11, 2024
1 parent 222b561 commit 35d620f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.github export-ignore
.gitignore export-ignore
phpstan.neon.dist export-ignore
phpstan-baseline.neon export-ignore
phpunit.xml.dist export-ignore
/tests export-ignore
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0 || ^8.5.13",
"phpstan/phpstan": "^1.5"
"phpstan/phpstan": "^1.11"
},
"autoload": {
"psr-4": { "Seld\\JsonLint\\": "src/Seld/JsonLint/" }
Expand Down
16 changes: 16 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters:
ignoreErrors:
-
message: "#^Cannot access offset 1 on array\\|bool\\|float\\|int\\|stdClass\\|string\\|null\\.$#"
count: 1
path: src/Seld/JsonLint/JsonParser.php

-
message: "#^Property Seld\\\\JsonLint\\\\JsonParser\\:\\:\\$vstack \\(list\\<array\\|bool\\|float\\|int\\|stdClass\\|string\\|null\\>\\) does not accept non\\-empty\\-array\\<int\\<\\-3, max\\>, array\\|bool\\|float\\|int\\|stdClass\\|string\\|null\\>\\.$#"
count: 4
path: src/Seld/JsonLint/JsonParser.php

-
message: "#^Property Seld\\\\JsonLint\\\\JsonParser\\:\\:\\$vstack \\(list\\<array\\|bool\\|float\\|int\\|stdClass\\|string\\|null\\>\\) does not accept non\\-empty\\-array\\<int\\<\\-3, max\\>, mixed\\>\\.$#"
count: 1
path: src/Seld/JsonLint/JsonParser.php
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
level: 8

treatPhpDocTypesAsCertain: false

paths:
- src/
- tests/
Expand Down
8 changes: 4 additions & 4 deletions src/Seld/JsonLint/JsonParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public function parse($input, $flags = 0)
}

// this shouldn't happen, unless resolve defaults are off
if (\is_array($action[0]) && \count($action) > 1) { // @phpstan-ignore-line
if (\is_array($action[0]) && \count($action) > 1) {
throw new ParsingException('Parse Error: multiple actions possible at state: ' . $state . ', token: ' . $symbol);
}

Expand Down Expand Up @@ -508,19 +508,19 @@ private function performAction($currentToken, $yytext, $yyleng, $yylineno, $yyst
} else {
$key = $this->vstack[$len][0];
}
if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($this->vstack[$len-2]->{$key})) {
if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($this->vstack[$len-2]->$key)) {
$errStr = 'Parse error on line ' . ($yylineno+1) . ":\n";
$errStr .= $this->lexer->showPosition() . "\n";
$errStr .= "Duplicate key: ".$this->vstack[$len][0];
throw new DuplicateKeyException($errStr, $this->vstack[$len][0], array('line' => $yylineno+1));
}
if (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($this->vstack[$len-2]->{$key})) {
if (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($this->vstack[$len-2]->$key)) {
$duplicateCount = 1;
do {
$duplicateKey = $key . '.' . $duplicateCount++;
} while (isset($this->vstack[$len-2]->$duplicateKey));
$this->vstack[$len-2]->$duplicateKey = $this->vstack[$len][1];
} elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS_TO_ARRAY) && isset($this->vstack[$len-2]->{$key})) {
} elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS_TO_ARRAY) && isset($this->vstack[$len-2]->$key)) {
if (!isset($this->vstack[$len-2]->$key->__duplicates__)) {
$this->vstack[$len-2]->$key = (object) ['__duplicates__' => [ $this->vstack[$len-2]->$key ]];
}
Expand Down
7 changes: 3 additions & 4 deletions tests/JsonParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function testDuplicateKeys()
);

$result = $parser->parse($str, JsonParser::ALLOW_DUPLICATE_KEYS | JsonParser::PARSE_TO_ASSOC);
self::assertSame(['a' => 'b', 'a.1' => 'c', 'a.2' => 'd'], $result);
self::assertSame(array('a' => 'b', 'a.1' => 'c', 'a.2' => 'd'), $result);
}

public function testDuplicateKeysToArray()
Expand All @@ -253,13 +253,12 @@ public function testDuplicateKeysToArray()
$str = '{"a":"b", "a":"c", "a":"d"}';

$result = $parser->parse($str, JsonParser::ALLOW_DUPLICATE_KEYS_TO_ARRAY);
$this->assertTrue(isset($result->a->__duplicates__[2]));
$this->assertThat($result, $this->objectHasAttribute('a'));
$this->assertThat($result->a, $this->objectHasAttribute('__duplicates__'));
self::assertSame(['b', 'c', 'd'], $result->a->__duplicates__);
self::assertSame(array('b', 'c', 'd'), $result->a->__duplicates__);

$result = $parser->parse($str, JsonParser::ALLOW_DUPLICATE_KEYS_TO_ARRAY | JsonParser::PARSE_TO_ASSOC);
self::assertSame(['a' => ['__duplicates__' => ['b', 'c', 'd']]], $result);
self::assertSame(array('a' => array('__duplicates__' => array('b', 'c', 'd'))), $result);
}

public function testDuplicateKeysWithEmpty()
Expand Down

0 comments on commit 35d620f

Please sign in to comment.