Improve static analysis

This commit is contained in:
Andrea Marco Sartori 2023-01-14 10:31:18 +10:00
parent fbafffaa3c
commit 3bc9eab5b0
4 changed files with 8 additions and 21 deletions

View File

@ -1,16 +0,0 @@
parameters:
ignoreErrors:
-
message: "#^Generator expects key type int\\|string, mixed given\\.$#"
count: 1
path: src/Parser.php
-
message: "#^Parameter \\#1 \\$json of method Cerbero\\\\JsonParser\\\\Decoders\\\\ConfigurableDecoder\\:\\:decode\\(\\) expects string, int\\|string given\\.$#"
count: 1
path: src/Parser.php
-
message: "#^Binary operation \"\\+\" between int\\|string and 1 results in an error\\.$#"
count: 1
path: src/Tree.php

View File

@ -20,14 +20,14 @@ final class ConfigurableDecoder
}
/**
* Decode the given JSON.
* Decode the given value.
*
* @param string $json
* @param string|int $value
* @return mixed
*/
public function decode(string $json): mixed
public function decode(string|int $value): mixed
{
$decoded = $this->config->decoder->decode($json);
$decoded = $this->config->decoder->decode((string) $value);
if (!$decoded->succeeded) {
call_user_func($this->config->onError, $decoded);

View File

@ -68,6 +68,7 @@ final class Parser implements IteratorAggregate
}
if ($this->state->hasBuffer()) {
/** @var string|int $key */
$key = $this->decoder->decode($this->state->key());
$value = $this->decoder->decode($this->state->value());

View File

@ -115,7 +115,9 @@ final class Tree
public function traverseArray(array $referenceTokens): void
{
$referenceToken = $referenceTokens[$this->depth] ?? null;
$this->original[$this->depth] = isset($this->original[$this->depth]) ? $this->original[$this->depth] + 1 : 0;
$index = $this->original[$this->depth] ?? null;
$this->original[$this->depth] = is_int($index) ? $index + 1 : 0;
$this->wildcarded[$this->depth] = $referenceToken == '-' ? '-' : $this->original[$this->depth];
$this->trim();