diff --git a/composer.json b/composer.json index 97b84ee..bc7d4ed 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "phpdocumentor/reflection-docblock": "*", "phpstan/phpdoc-parser": "*", "phpunit/phpunit": "^7.3 || ^8.4", - "phpstan/phpstan": "^0.12", + "phpstan/phpstan": "^1.10", "friendsofphp/php-cs-fixer": "^2.12" } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 233035a..b806197 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,40 +1,5 @@ parameters: ignoreErrors: - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$iteratee$#" - count: 1 - path: src/Array/differenceBy.php - - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$comparator$#" - count: 1 - path: src/Array/differenceWith.php - - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$iteratee$#" - count: 1 - path: src/Array/intersectionBy.php - - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$comparator$#" - count: 1 - path: src/Array/intersectionWith.php - - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$iteratee$#" - count: 1 - path: src/Array/unionBy.php - - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$comparator$#" - count: 1 - path: src/Array/unionWith.php - - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$iteratee$#" - count: 1 - path: src/Array/zipWith.php - - message: "#^Unreachable statement \\- code above always terminates\\.$#" count: 1 @@ -56,27 +21,12 @@ parameters: path: src/String/startsWith.php - - message: "#^Comparison operation \"\\>\" between int\\<0, max\\> and \\-1 is always true\\.$#" - count: 1 - path: src/String/truncate.php - - - - message: "#^Call to function is_array\\(\\) with object will always evaluate to false\\.$#" + message: "#^Offset mixed on \\*NEVER\\* in isset\\(\\) always exists and is not nullable\\.$#" count: 1 - path: src/internal/isIterateeCall.php - - - - message: "#^Result of \\|\\| is always true\\.$#" - count: 1 - path: src/internal/isIterateeCall.php + path: src/internal/baseIntersection.php - message: "#^Unreachable statement \\- code above always terminates\\.$#" count: 1 path: src/internal/isIterateeCall.php - - - message: "#^Regex pattern is invalid\\: Delimiter must not be alphanumeric or backslash in pattern\\: \\\\x\\{e83c\\}\\[\\\\x\\{effb\\}\\-\\\\x\\{efff\\}\\]\\(\\?\\=\\\\x\\{e83c\\}\\[\\\\x\\{effb\\}\\-\\\\x\\{efff\\}\\]\\)\\|\\(\\?\\:\\[\\^\\\\x\\{e800\\}\\-\\\\x\\{efff\\}\\]\\[\\\\x\\{0300\\}\\-\\\\x\\{036f\\}\\\\x\\{fe20\\}\\-\\\\x\\{fe2f\\}\\\\x\\{20d0\\}\\-\\\\x\\{20ff\\}\\]\\?\\|\\[\\\\x\\{0300\\}\\-\\\\x\\{036f\\}\\\\x\\{fe20\\}\\-\\\\x\\{fe2f\\}\\\\x\\{20d0\\}\\-\\\\x\\{20ff\\}\\]\\|\\(\\?\\:\\\\x\\{e83c\\}\\[\\\\x\\{ede6\\}\\-\\\\x\\{edff\\}\\]\\)\\{2\\}\\|\\[\\\\x\\{e800\\}\\-\\\\x\\{ebff\\}\\]\\[\\\\x\\{ec00\\}\\-\\\\x\\{efff\\}\\]\\|\\[\\\\x\\{e800\\}\\-\\\\x\\{efff\\}\\]\\)\\[\\\\x\\{fe0e\\}\\\\x\\{fe0f\\}\\]\\?\\(\\?\\:\\[\\\\x\\{0300\\}\\-\\\\x\\{036f\\}\\\\x\\{fe20\\}\\-\\\\x\\{fe2f\\}\\\\x\\{20d0\\}\\-\\\\x\\{20ff\\}\\]\\|\\\\x\\{e83c\\}\\[\\\\x\\{effb\\}\\-\\\\x\\{efff\\}\\]\\)\\?\\(\\?\\:\\\\x\\{200d\\}\\(\\?\\:\\[\\^\\\\x\\{e800\\}\\-\\\\x\\{efff\\}\\]\\|\\(\\?\\:\\\\x\\{e83c\\}\\[\\\\x\\{ede6\\}\\-\\\\x\\{edff\\}\\]\\)\\{2\\}\\|\\[\\\\x\\{e800\\}\\-\\\\x\\{ebff\\}\\]\\[\\\\x\\{ec00\\}\\-\\\\x\\{efff\\}\\]\\)\\[\\\\x\\{fe0e\\}\\\\x\\{fe0f\\}\\]\\?\\(\\?\\:\\[\\\\x\\{0300\\}\\-\\\\x\\{036f\\}\\\\x\\{fe20\\}\\-\\\\x\\{fe2f\\}\\\\x\\{20d0\\}\\-\\\\x\\{20ff\\}\\]\\|\\\\x\\{e83c\\}\\[\\\\x\\{effb\\}\\-\\\\x\\{efff\\}\\]\\)\\?\\)\\*$#" - count: 1 - path: src/internal/unicodeSize.php - diff --git a/phpstan.neon b/phpstan.neon index ae2cc00..f537171 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,11 +4,13 @@ includes: parameters: paths: - src - bootstrap: %rootDir%/../../../src/bootstrap.php + bootstrapFiles: + - src/bootstrap.php level: 5 - excludes_analyse: + excludePaths: - src/compiled.php - src/Lodash.php - src/internal/memoizeCapped.php # Exclude internal function due to dynamic class usage ignoreErrors: - "#Callable '.*internal.*' invoked with \\d+ parameters, [\\d-]+ required.#" + - "#^PHPDoc tag \\@param references unknown parameter\\: \\$[a-zA-Z]+$#" diff --git a/src/String/split.php b/src/String/split.php index 2ec929f..73916c3 100644 --- a/src/String/split.php +++ b/src/String/split.php @@ -33,7 +33,7 @@ function split(string $string, string $separator, int $limit = 0): array { if (\preg_match(reRegExpChar, $separator)) { - return \preg_split($separator, $string, $limit ?? -1, PREG_SPLIT_DELIM_CAPTURE) ?: []; + return \preg_split($separator, $string, $limit ?: -1, PREG_SPLIT_DELIM_CAPTURE) ?: []; } /** @var array $result */ diff --git a/src/String/template.php b/src/String/template.php index 559e2b4..8b76ef0 100644 --- a/src/String/template.php +++ b/src/String/template.php @@ -107,12 +107,12 @@ function template(string $string, array $options = []): callable ]); $string = \preg_replace_callback('#'.$reDelimiters.'#u', function ($matches) { - list(, + [, $escapeValue, $interpolateValue, $esTemplateValue, $evaluateValue, - ) = \array_merge($matches, \array_fill(\count($matches), 5 - \count($matches), null)); + ] = \array_merge($matches, \array_fill(\count($matches), 5 - \count($matches), null)); $interpolateValue = $interpolateValue ?: $esTemplateValue; @@ -128,7 +128,7 @@ function template(string $string, array $options = []): callable } if ($interpolateValue) { - $interpolateValue = \trim($interpolateValue ?? $esTemplateValue); + $interpolateValue = \trim($interpolateValue); $interpolateValue = \preg_replace('#^([\p{L}\p{N}_]+)$#u', '$$1', $interpolateValue); $source .= ""; } @@ -145,8 +145,14 @@ function template(string $string, array $options = []): callable return new class($string, $imports) { public $source; + /** + * @var array + */ private $imports; + /** + * @param array $imports + */ public function __construct(string $source, array $imports) { $this->source = $source; diff --git a/src/String/truncate.php b/src/String/truncate.php index 7fc4601..381c0df 100644 --- a/src/String/truncate.php +++ b/src/String/truncate.php @@ -105,7 +105,7 @@ function truncate($string, array $options = []) } } elseif (\strpos($string, $separator) !== $end) { $index = \strrpos($result, $separator); - if (false !== $index && $index > -1) { + if (false !== $index) { $result = \substr($result, 0, $index); } } diff --git a/src/internal/isIterateeCall.php b/src/internal/isIterateeCall.php index 08b13b2..b9c3169 100644 --- a/src/internal/isIterateeCall.php +++ b/src/internal/isIterateeCall.php @@ -24,7 +24,7 @@ */ function isIterateeCall($value, $index = null, $object = null) { - if (!\is_object($object) || !\is_array($object)) { + if (!\is_object($object) && !\is_array($object)) { return false; }