diff --git a/composer.json b/composer.json index 1a6728a..cb21095 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,13 @@ ], "require": { "php": "^8.1", - "phpstan/phpstan": "^1.12" + "phpstan/phpstan": "^2.0" }, "require-dev": { "phpoption/phpoption": "^1.9", "phpstan/extension-installer": "^1.4", - "phpstan/phpstan-deprecation-rules": "^1.2", - "phpstan/phpstan-strict-rules": "^1.6", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^10.5 || ^11.3", "slevomat/coding-standard": "^8.15" }, diff --git a/src/Type/PhpOption/FilterReturnTypeExtension.php b/src/Type/PhpOption/FilterReturnTypeExtension.php index 98b9fa7..ed128c9 100644 --- a/src/Type/PhpOption/FilterReturnTypeExtension.php +++ b/src/Type/PhpOption/FilterReturnTypeExtension.php @@ -90,7 +90,7 @@ public function getTypeFromMethodCall( } $valueType = $scope->getType(new MethodCall($methodCall->var, 'get')); - $scope = $scope->assignExpression($var, $valueType); + $scope = $scope->assignExpression($var, $valueType, $valueType); if ($methodReflection->getName() === 'filter') { $scope = $scope->filterByTruthyValue($expr); diff --git a/tests/Type/PhpOption/data/option-fold-left.php b/tests/Type/PhpOption/data/option-fold-left.php index 4d3a20b..6995e44 100644 --- a/tests/Type/PhpOption/data/option-fold-left.php +++ b/tests/Type/PhpOption/data/option-fold-left.php @@ -6,9 +6,10 @@ /** * @var \PhpOption\Option $option + * @var int $initialValue */ -assertType('int|string', $option->foldLeft(123, static function ($initial, $value) { - assertType('int', $initial); +assertType('int|string', $option->foldLeft($initialValue, static function ($initialValue, $value) { + assertType('int', $initialValue); assertType('string', $value); return $value; diff --git a/tests/Type/PhpOption/data/option-fold-right.php b/tests/Type/PhpOption/data/option-fold-right.php index 84b18c5..ab98828 100644 --- a/tests/Type/PhpOption/data/option-fold-right.php +++ b/tests/Type/PhpOption/data/option-fold-right.php @@ -6,9 +6,10 @@ /** * @var \PhpOption\Option $option + * @var int $initialValue */ -assertType('int|string', $option->foldRight(123, static function ($value, $initial) { - assertType('int', $initial); +assertType('int|string', $option->foldRight($initialValue, static function ($value, $initialValue) { + assertType('int', $initialValue); assertType('string', $value); return $value; diff --git a/tests/Type/PhpOption/data/option-get-or-call.php b/tests/Type/PhpOption/data/option-get-or-call.php index 7163797..8ab7db6 100644 --- a/tests/Type/PhpOption/data/option-get-or-call.php +++ b/tests/Type/PhpOption/data/option-get-or-call.php @@ -6,5 +6,6 @@ /** * @var \PhpOption\Option $option + * @var \Closure(): int $callable */ -assertType('int|string', $option->getOrCall(static fn () => 123)); +assertType('int|string', $option->getOrCall($callable)); diff --git a/tests/Type/PhpOption/data/option-get-or-else.php b/tests/Type/PhpOption/data/option-get-or-else.php index ef08a3e..4263086 100644 --- a/tests/Type/PhpOption/data/option-get-or-else.php +++ b/tests/Type/PhpOption/data/option-get-or-else.php @@ -6,5 +6,6 @@ /** * @var \PhpOption\Option $option + * @var int $default */ -assertType('int|string', $option->getOrElse(123)); +assertType('int|string', $option->getOrElse($default));