From 7b5ae90b3a631f3a9772f15cf16fc2fecdcf7f2b Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Tue, 12 Dec 2023 16:16:47 +0200 Subject: [PATCH 1/5] Fix compile script --- bin/compile | 2 -- src/Object/get.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/compile b/bin/compile index 2422749..1018030 100755 --- a/bin/compile +++ b/bin/compile @@ -5,8 +5,6 @@ declare(strict_types=1); -require_once dirname(__DIR__).'/vendor/autoload.php'; - function getCode(SplFileInfo $file): string { $code = php_strip_whitespace($file->getRealPath()); diff --git a/src/Object/get.php b/src/Object/get.php index 84e8268..3a0c66d 100644 --- a/src/Object/get.php +++ b/src/Object/get.php @@ -1,6 +1,6 @@ Date: Sun, 17 Dec 2023 18:11:51 +0200 Subject: [PATCH 2/5] Bump minimum PHP requirement to 7.2 --- .github/workflows/tests.yml | 3 +-- .php-version | 2 +- README.md | 4 ++++ composer.json | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 40b87c2..1e78057 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,6 @@ jobs: fail-fast: false matrix: include: - - php: 7.1 - php: 7.2 - php: 7.3 - php: 7.4 @@ -60,7 +59,7 @@ jobs: fail-fast: false matrix: include: - - php: 7.1 + - php: 7.2 steps: - name: Checkout diff --git a/.php-version b/.php-version index 37722eb..5904f7a 100644 --- a/.php-version +++ b/.php-version @@ -1 +1 @@ -7.4 +7.2 diff --git a/README.md b/README.md index 5c45a00..3d9cc8a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ Lodash-PHP is a port of the [Lodash JS library](https://lodash.com/) to PHP. It Lodash-PHP tries to mimick lodash.js as close as possible +# Requirements + +Lodash-PHP requires minimum PHP 7.2+, but the latest version of PHP is always recommended. + # Installation Install Lodash-PHP through composer: diff --git a/composer.json b/composer.json index 3fb0d3a..97b84ee 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ ] }, "require": { - "php": ">=7.1", + "php": "^7.2 || ^8.0", "sebastian/comparator": "^1.2 | ^2.0 | ^2.1 | ^3.0 | ^4.0", "symfony/property-access": "^2.7 | ^3.0 | ^4.0 | ^5.0" }, From 3e48ec2829cb1142eda17e36cb4d404187ff2435 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Sun, 17 Dec 2023 09:08:27 +0200 Subject: [PATCH 3/5] Update PHPStan to 1.10 --- composer.json | 2 +- phpstan-baseline.neon | 54 ++------------------------------- phpstan.neon | 6 ++-- src/String/split.php | 2 +- src/String/template.php | 12 ++++++-- src/String/truncate.php | 2 +- src/internal/isIterateeCall.php | 2 +- 7 files changed, 19 insertions(+), 61 deletions(-) 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; } From 799bec715e36626e3d2f62dfa08a179f9190e558 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Mon, 29 Jan 2024 09:49:41 -0500 Subject: [PATCH 4/5] Add 6.x to property access because it blocks install in updated projects --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bc7d4ed..8696e2a 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require": { "php": "^7.2 || ^8.0", "sebastian/comparator": "^1.2 | ^2.0 | ^2.1 | ^3.0 | ^4.0", - "symfony/property-access": "^2.7 | ^3.0 | ^4.0 | ^5.0" + "symfony/property-access": "^2.7 | ^3.0 | ^4.0 | ^5.0 | ^6.0" }, "require-dev": { "phpdocumentor/reflection-docblock": "*", From e3e02ac496f049e37159b99b266d77ae7f829880 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Tue, 30 Jan 2024 10:44:40 -0500 Subject: [PATCH 5/5] Add 5.x to sebastian comparator because it blocks install in updated projects --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8696e2a..539cfd9 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require": { "php": "^7.2 || ^8.0", - "sebastian/comparator": "^1.2 | ^2.0 | ^2.1 | ^3.0 | ^4.0", + "sebastian/comparator": "^1.2 | ^2.0 | ^2.1 | ^3.0 | ^4.0 | ^5.0", "symfony/property-access": "^2.7 | ^3.0 | ^4.0 | ^5.0 | ^6.0" }, "require-dev": {