Improve typehints

This commit is contained in:
Matias Griese 2021-12-09 14:06:58 +02:00
parent 3f3503e0f3
commit 236c068d70
8 changed files with 77 additions and 9 deletions

View File

@ -101,6 +101,11 @@
"system/src/DOMWordsIterator.php"
]
},
"autoload-dev": {
"psr-4": {
"PHPStan\\": "tests/phpstan/classes"
}
},
"archive": {
"exclude": [
"VERSION"

12
composer.lock generated
View File

@ -4562,16 +4562,16 @@
},
{
"name": "phpspec/prophecy",
"version": "1.14.0",
"version": "v1.15.0",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e"
"reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
"reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13",
"reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13",
"shasum": ""
},
"require": {
@ -4623,9 +4623,9 @@
],
"support": {
"issues": "https://github.com/phpspec/prophecy/issues",
"source": "https://github.com/phpspec/prophecy/tree/1.14.0"
"source": "https://github.com/phpspec/prophecy/tree/v1.15.0"
},
"time": "2021-09-10T09:02:12+00:00"
"time": "2021-12-08T12:19:24+00:00"
},
{
"name": "phpstan/phpstan",

View File

@ -22,7 +22,12 @@ use Grav\Common\Media\Traits\MediaObjectTrait;
* Class Medium
* @package Grav\Common\Page\Medium
*
* @property string $filepath
* @property string $mime
* @property int $size
* @property int $modified
* @property array $metadata
* @property int|string $timestamp
*/
class Medium extends Data implements RenderableInterface, MediaFileInterface
{

View File

@ -337,9 +337,9 @@ class Uri
/**
* Get URI parameter.
*
* @param string|null $id
* @param string|bool|null $default
* @return bool|string
* @param string $id
* @param string|false|null $default
* @return string|false|null
*/
public function param($id, $default = false)
{

View File

@ -0,0 +1,51 @@
<?php
namespace PHPStan\Toolbox;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
/**
* Extension to handle UniformResourceLocator return types.
*/
class UniformResourceLocatorExtension implements DynamicMethodReturnTypeExtension
{
/**
* @return string
*/
public function getClass(): string
{
return UniformResourceLocator::class;
}
/**
* @param MethodReflection $methodReflection
* @return bool
*/
public function isMethodSupported(MethodReflection $methodReflection): bool
{
return $methodReflection->getName() === 'findResource';
}
/**
* @param MethodReflection $methodReflection
* @param MethodCall $methodCall
* @param Scope $scope
* @return Type
*/
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
{
$first = $methodCall->getArgs()[2] ?? false;
if ($first) {
return new StringType();
}
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
}
}

View File

@ -0,0 +1,5 @@
services:
-
class: PHPStan\Toolbox\UniformResourceLocatorExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

View File

@ -2,6 +2,7 @@
includes:
#- '../../vendor/phpstan/phpstan-strict-rules/rules.neon'
- '../../vendor/phpstan/phpstan-deprecation-rules/rules.neon'
- 'extension.neon'
parameters:
fileExtensions:
- php

View File

@ -1,6 +1,7 @@
includes:
#- '../../vendor/phpstan/phpstan-strict-rules/rules.neon'
- '../../vendor/phpstan/phpstan-deprecation-rules/rules.neon'
- 'extension.neon'
parameters:
fileExtensions:
- php