mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
Updated Rector to commit 84faf2905518aad5fb97caf613517f8a50827867
84faf29055
Update generate-changelog command to use objects, add simple filtering (#3232)
This commit is contained in:
parent
fd9f761fe2
commit
efb1e95fb5
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit126c226e12fa4e9c2e4353c2d4188542::getLoader();
|
||||
return ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921::getLoader();
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit126c226e12fa4e9c2e4353c2d4188542
|
||||
class ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit126c226e12fa4e9c2e4353c2d4188542
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit126c226e12fa4e9c2e4353c2d4188542', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit126c226e12fa4e9c2e4353c2d4188542', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitb0438dc6c264d9c98b8c8dbdc7504921', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit126c226e12fa4e9c2e4353c2d4188542::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit126c226e12fa4e9c2e4353c2d4188542::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::$files;
|
||||
$requireFile = static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit126c226e12fa4e9c2e4353c2d4188542
|
||||
class ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3061,9 +3061,9 @@ class ComposerStaticInit126c226e12fa4e9c2e4353c2d4188542
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit126c226e12fa4e9c2e4353c2d4188542::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit126c226e12fa4e9c2e4353c2d4188542::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit126c226e12fa4e9c2e4353c2d4188542::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitb0438dc6c264d9c98b8c8dbdc7504921::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
22
vendor/composer/installed.json
vendored
22
vendor/composer/installed.json
vendored
|
@ -859,17 +859,17 @@
|
|||
},
|
||||
{
|
||||
"name": "phpstan\/phpstan-phpunit",
|
||||
"version": "1.3.2",
|
||||
"version_normalized": "1.3.2.0",
|
||||
"version": "1.3.3",
|
||||
"version_normalized": "1.3.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/phpstan\/phpstan-phpunit.git",
|
||||
"reference": "cd9c6938f8bbfcb6da3ed5a3c7ea60873825d088"
|
||||
"reference": "54a24bd23e9e80ee918cdc24f909d376c2e273f7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan-phpunit\/zipball\/cd9c6938f8bbfcb6da3ed5a3c7ea60873825d088",
|
||||
"reference": "cd9c6938f8bbfcb6da3ed5a3c7ea60873825d088",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan-phpunit\/zipball\/54a24bd23e9e80ee918cdc24f909d376c2e273f7",
|
||||
"reference": "54a24bd23e9e80ee918cdc24f909d376c2e273f7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -885,7 +885,7 @@
|
|||
"phpstan\/phpstan-strict-rules": "^1.0",
|
||||
"phpunit\/phpunit": "^9.5"
|
||||
},
|
||||
"time": "2022-12-13T15:08:22+00:00",
|
||||
"time": "2022-12-21T15:25:00+00:00",
|
||||
"type": "phpstan-extension",
|
||||
"extra": {
|
||||
"phpstan": {
|
||||
|
@ -908,7 +908,7 @@
|
|||
"description": "PHPUnit extensions and rules for PHPStan",
|
||||
"support": {
|
||||
"issues": "https:\/\/github.com\/phpstan\/phpstan-phpunit\/issues",
|
||||
"source": "https:\/\/github.com\/phpstan\/phpstan-phpunit\/tree\/1.3.2"
|
||||
"source": "https:\/\/github.com\/phpstan\/phpstan-phpunit\/tree\/1.3.3"
|
||||
},
|
||||
"install-path": "..\/phpstan\/phpstan-phpunit"
|
||||
},
|
||||
|
@ -2122,12 +2122,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "4aa76596024629f6f8ef676fd7cc3ae53f5086ac"
|
||||
"reference": "c5289ee54e37ac071e93fe3b0ac454619ed78ec8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/4aa76596024629f6f8ef676fd7cc3ae53f5086ac",
|
||||
"reference": "4aa76596024629f6f8ef676fd7cc3ae53f5086ac",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/c5289ee54e37ac071e93fe3b0ac454619ed78ec8",
|
||||
"reference": "c5289ee54e37ac071e93fe3b0ac454619ed78ec8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2157,7 +2157,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
},
|
||||
"time": "2022-12-21T15:12:14+00:00",
|
||||
"time": "2022-12-21T16:38:42+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
|
@ -6,7 +6,6 @@ namespace PHPStan\Rules\PHPUnit;
|
|||
use PhpParser\Node;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Rules\Rule;
|
||||
use PHPStan\Type\FileTypeMapper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function array_merge;
|
||||
/**
|
||||
|
@ -20,12 +19,6 @@ class DataProviderDeclarationRule implements Rule
|
|||
* @var DataProviderHelper
|
||||
*/
|
||||
private $dataProviderHelper;
|
||||
/**
|
||||
* The file type mapper.
|
||||
*
|
||||
* @var FileTypeMapper
|
||||
*/
|
||||
private $fileTypeMapper;
|
||||
/**
|
||||
* When set to true, it reports data provider method with incorrect name case.
|
||||
*
|
||||
|
@ -38,10 +31,9 @@ class DataProviderDeclarationRule implements Rule
|
|||
* @var bool
|
||||
*/
|
||||
private $deprecationRulesInstalled;
|
||||
public function __construct(\PHPStan\Rules\PHPUnit\DataProviderHelper $dataProviderHelper, FileTypeMapper $fileTypeMapper, bool $checkFunctionNameCase, bool $deprecationRulesInstalled)
|
||||
public function __construct(\PHPStan\Rules\PHPUnit\DataProviderHelper $dataProviderHelper, bool $checkFunctionNameCase, bool $deprecationRulesInstalled)
|
||||
{
|
||||
$this->dataProviderHelper = $dataProviderHelper;
|
||||
$this->fileTypeMapper = $fileTypeMapper;
|
||||
$this->checkFunctionNameCase = $checkFunctionNameCase;
|
||||
$this->deprecationRulesInstalled = $deprecationRulesInstalled;
|
||||
}
|
||||
|
@ -55,15 +47,9 @@ class DataProviderDeclarationRule implements Rule
|
|||
if ($classReflection === null || !$classReflection->isSubclassOf(TestCase::class)) {
|
||||
return [];
|
||||
}
|
||||
$docComment = $node->getDocComment();
|
||||
if ($docComment === null) {
|
||||
return [];
|
||||
}
|
||||
$methodPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc($scope->getFile(), $classReflection->getName(), $scope->isInTrait() ? $scope->getTraitReflection()->getName() : null, $node->name->toString(), $docComment->getText());
|
||||
$annotations = $this->dataProviderHelper->getDataProviderAnnotations($methodPhpDoc);
|
||||
$errors = [];
|
||||
foreach ($annotations as $annotation) {
|
||||
$errors = array_merge($errors, $this->dataProviderHelper->processDataProvider($scope, $annotation, $this->checkFunctionNameCase, $this->deprecationRulesInstalled));
|
||||
foreach ($this->dataProviderHelper->getDataProviderMethods($scope, $node, $classReflection) as $dataProviderValue => [$dataProviderClassReflection, $dataProviderMethodName, $lineNumber]) {
|
||||
$errors = array_merge($errors, $this->dataProviderHelper->processDataProvider($dataProviderValue, $dataProviderClassReflection, $dataProviderMethodName, $lineNumber, $this->checkFunctionNameCase, $this->deprecationRulesInstalled));
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
declare (strict_types=1);
|
||||
namespace PHPStan\Rules\PHPUnit;
|
||||
|
||||
use PhpParser\Node\Attribute;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
|
@ -11,6 +16,7 @@ use PHPStan\Reflection\MissingMethodFromReflectionException;
|
|||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Rules\RuleError;
|
||||
use PHPStan\Rules\RuleErrorBuilder;
|
||||
use PHPStan\Type\FileTypeMapper;
|
||||
use function array_merge;
|
||||
use function count;
|
||||
use function explode;
|
||||
|
@ -24,17 +30,61 @@ class DataProviderHelper
|
|||
* @var ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
/**
|
||||
* The file type mapper.
|
||||
*
|
||||
* @var FileTypeMapper
|
||||
*/
|
||||
private $fileTypeMapper;
|
||||
/** @var bool */
|
||||
private $phpunit10OrNewer;
|
||||
public function __construct(ReflectionProvider $reflectionProvider, bool $phpunit10OrNewer)
|
||||
public function __construct(ReflectionProvider $reflectionProvider, FileTypeMapper $fileTypeMapper, bool $phpunit10OrNewer)
|
||||
{
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->fileTypeMapper = $fileTypeMapper;
|
||||
$this->phpunit10OrNewer = $phpunit10OrNewer;
|
||||
}
|
||||
/**
|
||||
* @return iterable<array{ClassReflection|null, string, int}>
|
||||
*/
|
||||
public function getDataProviderMethods(Scope $scope, ClassMethod $node, ClassReflection $classReflection) : iterable
|
||||
{
|
||||
$docComment = $node->getDocComment();
|
||||
if ($docComment !== null) {
|
||||
$methodPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc($scope->getFile(), $classReflection->getName(), $scope->isInTrait() ? $scope->getTraitReflection()->getName() : null, $node->name->toString(), $docComment->getText());
|
||||
foreach ($this->getDataProviderAnnotations($methodPhpDoc) as $annotation) {
|
||||
$dataProviderValue = $this->getDataProviderAnnotationValue($annotation);
|
||||
if ($dataProviderValue === null) {
|
||||
// Missing value is already handled in NoMissingSpaceInMethodAnnotationRule
|
||||
continue;
|
||||
}
|
||||
$dataProviderMethod = $this->parseDataProviderAnnotationValue($scope, $dataProviderValue);
|
||||
$dataProviderMethod[] = $node->getLine();
|
||||
(yield $dataProviderValue => $dataProviderMethod);
|
||||
}
|
||||
}
|
||||
if (!$this->phpunit10OrNewer) {
|
||||
return;
|
||||
}
|
||||
foreach ($node->attrGroups as $attrGroup) {
|
||||
foreach ($attrGroup->attrs as $attr) {
|
||||
$dataProviderMethod = null;
|
||||
if ($attr->name->toLowerString() === 'phpunit\\framework\\attributes\\dataprovider') {
|
||||
$dataProviderMethod = $this->parseDataProviderAttribute($attr, $classReflection);
|
||||
} elseif ($attr->name->toLowerString() === 'phpunit\\framework\\attributes\\dataproviderexternal') {
|
||||
$dataProviderMethod = $this->parseDataProviderExternalAttribute($attr);
|
||||
}
|
||||
if ($dataProviderMethod === null) {
|
||||
continue;
|
||||
}
|
||||
yield from $dataProviderMethod;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return array<PhpDocTagNode>
|
||||
*/
|
||||
public function getDataProviderAnnotations(?ResolvedPhpDocBlock $phpDoc) : array
|
||||
private function getDataProviderAnnotations(?ResolvedPhpDocBlock $phpDoc) : array
|
||||
{
|
||||
if ($phpDoc === null) {
|
||||
return [];
|
||||
|
@ -49,37 +99,31 @@ class DataProviderHelper
|
|||
/**
|
||||
* @return RuleError[] errors
|
||||
*/
|
||||
public function processDataProvider(Scope $scope, PhpDocTagNode $phpDocTag, bool $checkFunctionNameCase, bool $deprecationRulesInstalled) : array
|
||||
public function processDataProvider(string $dataProviderValue, ?ClassReflection $classReflection, string $methodName, int $lineNumber, bool $checkFunctionNameCase, bool $deprecationRulesInstalled) : array
|
||||
{
|
||||
$dataProviderValue = $this->getDataProviderValue($phpDocTag);
|
||||
if ($dataProviderValue === null) {
|
||||
// Missing value is already handled in NoMissingSpaceInMethodAnnotationRule
|
||||
return [];
|
||||
}
|
||||
[$classReflection, $method] = $this->parseDataProviderValue($scope, $dataProviderValue);
|
||||
if ($classReflection === null) {
|
||||
$error = RuleErrorBuilder::message(sprintf('@dataProvider %s related class not found.', $dataProviderValue))->build();
|
||||
$error = RuleErrorBuilder::message(sprintf('@dataProvider %s related class not found.', $dataProviderValue))->line($lineNumber)->build();
|
||||
return [$error];
|
||||
}
|
||||
try {
|
||||
$dataProviderMethodReflection = $classReflection->getNativeMethod($method);
|
||||
$dataProviderMethodReflection = $classReflection->getNativeMethod($methodName);
|
||||
} catch (MissingMethodFromReflectionException $missingMethodFromReflectionException) {
|
||||
$error = RuleErrorBuilder::message(sprintf('@dataProvider %s related method not found.', $dataProviderValue))->build();
|
||||
$error = RuleErrorBuilder::message(sprintf('@dataProvider %s related method not found.', $dataProviderValue))->line($lineNumber)->build();
|
||||
return [$error];
|
||||
}
|
||||
$errors = [];
|
||||
if ($checkFunctionNameCase && $method !== $dataProviderMethodReflection->getName()) {
|
||||
$errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method is used with incorrect case: %s.', $dataProviderValue, $dataProviderMethodReflection->getName()))->build();
|
||||
if ($checkFunctionNameCase && $methodName !== $dataProviderMethodReflection->getName()) {
|
||||
$errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method is used with incorrect case: %s.', $dataProviderValue, $dataProviderMethodReflection->getName()))->line($lineNumber)->build();
|
||||
}
|
||||
if (!$dataProviderMethodReflection->isPublic()) {
|
||||
$errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method must be public.', $dataProviderValue))->build();
|
||||
$errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method must be public.', $dataProviderValue))->line($lineNumber)->build();
|
||||
}
|
||||
if ($deprecationRulesInstalled && $this->phpunit10OrNewer && !$dataProviderMethodReflection->isStatic()) {
|
||||
$errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method must be static in PHPUnit 10 and newer.', $dataProviderValue))->build();
|
||||
$errors[] = RuleErrorBuilder::message(sprintf('@dataProvider %s related method must be static in PHPUnit 10 and newer.', $dataProviderValue))->line($lineNumber)->build();
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
private function getDataProviderValue(PhpDocTagNode $phpDocTag) : ?string
|
||||
private function getDataProviderAnnotationValue(PhpDocTagNode $phpDocTag) : ?string
|
||||
{
|
||||
if (preg_match('/^[^ \\t]+/', (string) $phpDocTag->value, $matches) !== 1) {
|
||||
return null;
|
||||
|
@ -89,7 +133,7 @@ class DataProviderHelper
|
|||
/**
|
||||
* @return array{ClassReflection|null, string}
|
||||
*/
|
||||
private function parseDataProviderValue(Scope $scope, string $dataProviderValue) : array
|
||||
private function parseDataProviderAnnotationValue(Scope $scope, string $dataProviderValue) : array
|
||||
{
|
||||
$parts = explode('::', $dataProviderValue, 2);
|
||||
if (count($parts) <= 1) {
|
||||
|
@ -100,4 +144,45 @@ class DataProviderHelper
|
|||
}
|
||||
return [null, $dataProviderValue];
|
||||
}
|
||||
/**
|
||||
* @return array<string, array{(ClassReflection|null), string, int}>|null
|
||||
*/
|
||||
private function parseDataProviderExternalAttribute(Attribute $attribute) : ?array
|
||||
{
|
||||
if (count($attribute->args) !== 2) {
|
||||
return null;
|
||||
}
|
||||
$methodNameArg = $attribute->args[1]->value;
|
||||
if (!$methodNameArg instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
$classNameArg = $attribute->args[0]->value;
|
||||
if ($classNameArg instanceof ClassConstFetch && $classNameArg->class instanceof Name) {
|
||||
$className = $classNameArg->class->toString();
|
||||
} elseif ($classNameArg instanceof String_) {
|
||||
$className = $classNameArg->value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
$dataProviderClassReflection = null;
|
||||
if ($this->reflectionProvider->hasClass($className)) {
|
||||
$dataProviderClassReflection = $this->reflectionProvider->getClass($className);
|
||||
$className = $dataProviderClassReflection->getName();
|
||||
}
|
||||
return [sprintf('%s::%s', $className, $methodNameArg->value) => [$dataProviderClassReflection, $methodNameArg->value, $attribute->getLine()]];
|
||||
}
|
||||
/**
|
||||
* @return array<string, array{(ClassReflection|null), string, int}>|null
|
||||
*/
|
||||
private function parseDataProviderAttribute(Attribute $attribute, ClassReflection $classReflection) : ?array
|
||||
{
|
||||
if (count($attribute->args) !== 1) {
|
||||
return null;
|
||||
}
|
||||
$methodNameArg = $attribute->args[0]->value;
|
||||
if (!$methodNameArg instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
return [$methodNameArg->value => [$classReflection, $methodNameArg->value, $attribute->getLine()]];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ declare (strict_types=1);
|
|||
namespace PHPStan\Rules\PHPUnit;
|
||||
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\FileTypeMapper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function dirname;
|
||||
use function explode;
|
||||
|
@ -14,9 +15,12 @@ class DataProviderHelperFactory
|
|||
{
|
||||
/** @var ReflectionProvider */
|
||||
private $reflectionProvider;
|
||||
public function __construct(ReflectionProvider $reflectionProvider)
|
||||
/** @var FileTypeMapper */
|
||||
private $fileTypeMapper;
|
||||
public function __construct(ReflectionProvider $reflectionProvider, FileTypeMapper $fileTypeMapper)
|
||||
{
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->fileTypeMapper = $fileTypeMapper;
|
||||
}
|
||||
public function create() : \PHPStan\Rules\PHPUnit\DataProviderHelper
|
||||
{
|
||||
|
@ -42,6 +46,6 @@ class DataProviderHelperFactory
|
|||
}
|
||||
}
|
||||
}
|
||||
return new \PHPStan\Rules\PHPUnit\DataProviderHelper($this->reflectionProvider, $phpUnit10OrNewer);
|
||||
return new \PHPStan\Rules\PHPUnit\DataProviderHelper($this->reflectionProvider, $this->fileTypeMapper, $phpUnit10OrNewer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d5c39ae'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b1ca6d7'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a236bc6'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 4aa7659'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d5c39ae'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b1ca6d7'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a236bc6'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c5289ee'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -68,25 +68,22 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->isName($node, 'execute')) {
|
||||
if (!$this->isObjectType($node, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
|
||||
return null;
|
||||
}
|
||||
$class = $this->betterNodeFinder->findParentType($node, Class_::class);
|
||||
if (!$class instanceof Class_) {
|
||||
$executeClassMethod = $node->getMethod('execute');
|
||||
if (!$executeClassMethod instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isObjectType($class, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
|
||||
return null;
|
||||
}
|
||||
$this->refactorReturnTypeDeclaration($node);
|
||||
$this->addReturn0ToMethod($node);
|
||||
$this->refactorReturnTypeDeclaration($executeClassMethod);
|
||||
$this->addReturn0ToMethod($executeClassMethod);
|
||||
if ($this->hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
|
@ -106,7 +103,11 @@ CODE_SAMPLE
|
|||
$hasReturn = \false;
|
||||
$this->traverseNodesWithCallable((array) $classMethod->getStmts(), function (Node $node) use($classMethod, &$hasReturn) : ?int {
|
||||
if ($node instanceof FunctionLike) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
// skip anonymous class
|
||||
if ($node instanceof Class_) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof Node && $this->isReturnWithExprIntEquals($parentNode, $node)) {
|
||||
|
@ -116,8 +117,11 @@ CODE_SAMPLE
|
|||
if (!$node instanceof Return_) {
|
||||
return null;
|
||||
}
|
||||
if ($node->expr instanceof Int_) {
|
||||
return null;
|
||||
if ($node->expr instanceof Expr) {
|
||||
$returnedType = $this->getType($node->expr);
|
||||
if ($returnedType instanceof IntegerType) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($node->expr instanceof Ternary && $this->isIntegerTernaryIfElse($node->expr)) {
|
||||
$hasReturn = \true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user