[TypeDeclaration] Switch from stringy types to PHPStan types (#4510)

* nette-30 config cleanup

* [TypeDeclaratoin] Move AddReturnTypeDeclarationRector from generic

* add Type support to AddReturnTypeDeclaration

* make AddParamTypeDeclarationRector use PHPStan type objects over strings

* [SymfonyPhpConfig] Add support for nested types

* drop StringTypeToPhpParserNodeMapper

* [ci-review] Rector Rectify

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Tomas Votruba 2020-10-30 12:58:35 +01:00 committed by GitHub
parent 63037fe924
commit dc2047f70a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 1459 additions and 796 deletions

View File

@ -31,7 +31,7 @@ PRs and issues are linked, so you can find more about it. Thanks to [ChangelogLi
### Changed
-
-
### Fixed
- [#4422] [DeadCode] Fix binary different nesting in RemoveOverriddenValuesRector
@ -372,7 +372,7 @@ PRs and issues are linked, so you can find more about it. Thanks to [ChangelogLi
### Fixed
- [#4111] show command - display loaded sets + fix set provider
-
-
## [v0.8.3] - 2020-09-02
### Added
@ -2746,7 +2746,7 @@ PRs and issues are linked, so you can find more about it. Thanks to [ChangelogLi
### Changed
- [#1769] [Restoration] Return removed class annotations
- [#1788] infer from [@return] doc type in PropertyTypeDeclaratoin
- [#1788] infer from [@return] doc type in PropertyTypeDeclaration
### Fixed

View File

@ -31,7 +31,7 @@
"doctrine/annotations": "^1.11",
"doctrine/inflector": "^1.4|^2.0",
"jean85/pretty-package-versions": "^1.5.1",
"migrify/php-config-printer": "^0.3.45",
"migrify/php-config-printer": "^0.3.52",
"nette/robot-loader": "^3.2",
"nette/utils": "^3.1",
"nikic/php-parser": "4.10.2",

View File

@ -2,12 +2,17 @@
declare(strict_types=1);
use PHPStan\Type\BooleanType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Rector\CakePHP\Rector\MethodCall\ModalToGetSetRector;
use Rector\CakePHP\Rector\MethodCall\RenameMethodCallBasedOnParameterRector;
use Rector\CakePHP\ValueObject\ModalToGetSet;
use Rector\CakePHP\ValueObject\RenameMethodCallBasedOnParameter;
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
@ -19,7 +24,9 @@ use Rector\Renaming\ValueObject\RenameProperty;
use Rector\Renaming\ValueObject\RenameStaticMethod;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# source: https://book.cakephp.org/4/en/appendices/4-0-migration-guide.html
@ -79,89 +86,102 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration('Cake\Http\BaseApplication', 'bootstrap', 'void'),
new AddReturnTypeDeclaration('Cake\Http\BaseApplication', 'bootstrapCli', 'void'),
new AddReturnTypeDeclaration('Cake\Http\BaseApplication', 'middleware', 'Cake\Http\MiddlewareQueue'),
new AddReturnTypeDeclaration('Cake\Console\Shell', 'initialize', 'void'),
new AddReturnTypeDeclaration('Cake\Controller\Component', 'initialize', 'void'),
new AddReturnTypeDeclaration('Cake\Controller\Controller', 'initialize', 'void'),
new AddReturnTypeDeclaration('Cake\Controller\Controller', 'render', 'Cake\Http\Response'),
new AddReturnTypeDeclaration('Cake\Form\Form', 'validate', 'bool'),
new AddReturnTypeDeclaration('Cake\Form\Form', '_buildSchema', 'Cake\Form\Schema'),
new AddReturnTypeDeclaration('Cake\ORM\Behavior', 'initialize', 'void'),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'initialize', 'void'),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'updateAll', 'int'),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'deleteAll', 'int'),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'validationDefault', 'Cake\Validation\Validator'),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'buildRules', 'Cake\ORM\RulesChecker'),
new AddReturnTypeDeclaration('Cake\View\Helper', 'initialize', 'void'), ]),
new AddReturnTypeDeclaration('Cake\Http\BaseApplication', 'bootstrap', new VoidType()),
new AddReturnTypeDeclaration('Cake\Http\BaseApplication', 'bootstrapCli', new VoidType()),
new AddReturnTypeDeclaration('Cake\Http\BaseApplication', 'middleware', new ObjectType(
'Cake\Http\MiddlewareQueue'
)),
new AddReturnTypeDeclaration('Cake\Console\Shell', 'initialize', new VoidType()),
new AddReturnTypeDeclaration('Cake\Controller\Component', 'initialize', new VoidType()),
new AddReturnTypeDeclaration('Cake\Controller\Controller', 'initialize', new VoidType()),
new AddReturnTypeDeclaration('Cake\Controller\Controller', 'render', new ObjectType(
'Cake\Http\Response'
)),
new AddReturnTypeDeclaration('Cake\Form\Form', 'validate', new BooleanType()),
new AddReturnTypeDeclaration('Cake\Form\Form', '_buildSchema', new ObjectType('Cake\Form\Schema')),
new AddReturnTypeDeclaration('Cake\ORM\Behavior', 'initialize', new VoidType()),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'initialize', new VoidType()),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'updateAll', new IntegerType()),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'deleteAll', new IntegerType()),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'validationDefault', new ObjectType(
'Cake\Validation\Validator'
)),
new AddReturnTypeDeclaration('Cake\ORM\Table', 'buildRules', new ObjectType('Cake\ORM\RulesChecker')),
new AddReturnTypeDeclaration('Cake\View\Helper', 'initialize', new VoidType()), ]),
]]);
$eventInterfaceObjectType = new ObjectType('Cake\Event\EventInterface');
$services->set(AddParamTypeDeclarationRector::class)
->call('configure', [[
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => inline_value_objects([
new AddParamTypeDeclaration('Cake\Form\Form', 'getData', 0, '?string'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'beforeFind', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'buildValidator', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'buildRules', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'beforeRules', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'afterRules', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'beforeSave', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'afterSave', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'beforeDelete', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'afterDelete', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'beforeFind', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'buildValidator', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'buildRules', 0, 'Cake\ORM\RulesChecker'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'beforeRules', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'afterRules', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'beforeSave', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'afterSave', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'beforeDelete', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\ORM\Table', 'afterDelete', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration(
'Cake\Form\Form',
'getData',
0,
new UnionType([new StringType(), new NullType()])
),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'beforeFind', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'buildValidator', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'buildRules', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'beforeRules', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'afterRules', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'beforeSave', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'afterSave', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'beforeDelete', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Behavior', 'afterDelete', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Table', 'beforeFind', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Table', 'buildValidator', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Table', 'buildRules', 0, new ObjectType('Cake\ORM\RulesChecker')),
new AddParamTypeDeclaration('Cake\ORM\Table', 'beforeRules', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Table', 'afterRules', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Table', 'beforeSave', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Table', 'afterSave', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Table', 'beforeDelete', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\ORM\Table', 'afterDelete', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration(
'Cake\Controller\Controller',
'beforeFilter',
0,
'Cake\Event\EventInterface'
$eventInterfaceObjectType
),
new AddParamTypeDeclaration(
'Cake\Controller\Controller',
'afterFilter',
0,
'Cake\Event\EventInterface'
$eventInterfaceObjectType
),
new AddParamTypeDeclaration(
'Cake\Controller\Controller',
'beforeRender',
0,
'Cake\Event\EventInterface'
$eventInterfaceObjectType
),
new AddParamTypeDeclaration(
'Cake\Controller\Controller',
'beforeRedirect',
0,
'Cake\Event\EventInterface'
$eventInterfaceObjectType
),
new AddParamTypeDeclaration('Cake\Controller\Component', 'shutdown', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\Controller\Component', 'startup', 0, 'Cake\Event\EventInterface'),
new AddParamTypeDeclaration('Cake\Controller\Component', 'shutdown', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration('Cake\Controller\Component', 'startup', 0, $eventInterfaceObjectType),
new AddParamTypeDeclaration(
'Cake\Controller\Component',
'beforeFilter',
0,
'Cake\Event\EventInterface'
$eventInterfaceObjectType
),
new AddParamTypeDeclaration(
'Cake\Controller\Component',
'beforeRender',
0,
'Cake\Event\EventInterface'
$eventInterfaceObjectType
),
new AddParamTypeDeclaration(
'Cake\Controller\Component',
'beforeRedirect',
0,
'Cake\Event\EventInterface'
$eventInterfaceObjectType
),
]),
]]);

View File

@ -127,33 +127,36 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(UnusedForeachValueToArrayKeysRector::class);
$services->set(ArrayThisCallToThisMethodCallRector::class);
$services->set(CommonNotEqualRector::class);
$services->set(RenameFunctionRector::class)->call('configure', [[
RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [
'split' => 'explode',
'join' => 'implode',
'sizeof' => 'count',
# https://www.php.net/manual/en/aliases.php
'chop' => 'rtrim',
'doubleval' => 'floatval',
'gzputs' => 'gzwrites',
'fputs' => 'fwrite',
'ini_alter' => 'ini_set',
'is_double' => 'is_float',
'is_integer' => 'is_int',
'is_long' => 'is_int',
'is_real' => 'is_float',
'is_writeable' => 'is_writable',
'key_exists' => 'array_key_exists',
'pos' => 'current',
'strchr' => 'strstr',
# mb
'mbstrcut' => 'mb_strcut',
'mbstrlen' => 'mb_strlen',
'mbstrpos' => 'mb_strpos',
'mbstrrpos' => 'mb_strrpos',
'mbsubstr' => 'mb_substr',
$services->set(RenameFunctionRector::class)
->call('configure', [[
RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [
'split' => 'explode',
'join' => 'implode',
'sizeof' => 'count',
# https://www.php.net/manual/en/aliases.php
'chop' => 'rtrim',
'doubleval' => 'floatval',
'gzputs' => 'gzwrites',
'fputs' => 'fwrite',
'ini_alter' => 'ini_set',
'is_double' => 'is_float',
'is_integer' => 'is_int',
'is_long' => 'is_int',
'is_real' => 'is_float',
'is_writeable' => 'is_writable',
'key_exists' => 'array_key_exists',
'pos' => 'current',
'strchr' => 'strstr',
# mb
'mbstrcut' => 'mb_strcut',
'mbstrlen' => 'mb_strlen',
'mbstrpos' => 'mb_strpos',
'mbstrrpos' => 'mb_strrpos',
'mbsubstr' => 'mb_substr',
],
],
]]);
]);
$services->set(SetTypeToCastRector::class);
$services->set(LogicalToBooleanRector::class);
$services->set(VarToPublicPropertyRector::class);

View File

@ -2,11 +2,12 @@
declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use PHPStan\Type\VoidType;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://github.com/doctrine/dbal/blob/master/UPGRADE.md#bc-break-changes-in-handling-string-and-binary-columns
@ -28,7 +29,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration('Doctrine\DBAL\Connection', 'ping', 'void'),
new AddReturnTypeDeclaration('Doctrine\DBAL\Connection', 'ping', new VoidType()),
]),
]]);
};

View File

@ -2,6 +2,7 @@
declare(strict_types=1);
use PHPStan\Type\ObjectType;
use Rector\Generic\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Generic\ValueObject\ArgumentRemover;
use function Rector\SymfonyPhpConfig\inline_value_objects;
@ -19,13 +20,13 @@ return static function (ContainerConfigurator $containerConfigurator): void {
'Doctrine\ORM\Mapping\ClassMetadataFactory',
'setEntityManager',
0,
'Doctrine\ORM\EntityManagerInterface'
new ObjectType('Doctrine\ORM\EntityManagerInterface')
),
new AddParamTypeDeclaration(
'Doctrine\ORM\Tools\DebugUnitOfWorkListener',
'dumpIdentityMap',
0,
'Doctrine\ORM\EntityManagerInterface'
new ObjectType('Doctrine\ORM\EntityManagerInterface')
),
]),
]]);

View File

@ -2,12 +2,13 @@
declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use PHPStan\Type\BooleanType;
use Rector\Laravel\Rector\StaticCall\MinutesToSecondsInCacheRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\RenameProperty;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://laravel-news.com/laravel-5-8-deprecates-string-and-array-helpers
@ -23,11 +24,11 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Repository', 'put', 'bool'),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Repository', 'forever', 'bool'),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'put', 'bool'),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'putMany', 'bool'),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'forever', 'bool'), ]
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Repository', 'put', new BooleanType()),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Repository', 'forever', new BooleanType()),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'put', new BooleanType()),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'putMany', new BooleanType()),
new AddReturnTypeDeclaration('Illuminate\Contracts\Cache\Store', 'forever', new BooleanType()), ]
),
]]);

View File

@ -2,6 +2,15 @@
declare(strict_types=1);
use PHPStan\Type\BooleanType;
use PHPStan\Type\CallableType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
@ -12,76 +21,89 @@ return static function (ContainerConfigurator $containerConfigurator): void {
# scalar type hints, see https://github.com/nette/component-model/commit/f69df2ca224cad7b07f1c8835679393263ea6771
# scalar param types https://github.com/nette/security/commit/84024f612fb3f55f5d6e3e3e28eef1ad0388fa56
$iterableType = new IterableType(new MixedType(), new MixedType());
$services->set(AddParamTypeDeclarationRector::class)
->call('configure', [[
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => inline_value_objects([
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'lookup', 0, '?string'),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'lookup', 1, 'bool'),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'lookupPath', 0, 'string'),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'lookupPath', 1, 'bool'),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'monitor', 0, 'string'),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'unmonitor', 0, 'string'),
new AddParamTypeDeclaration(
'Nette\ComponentModel\Component',
'lookup',
0,
new UnionType([new StringType(), new NullType()])
),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'lookup', 1, new BooleanType()),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'lookupPath', 0, new StringType()),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'lookupPath', 1, new BooleanType()),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'monitor', 0, new StringType()),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'unmonitor', 0, new StringType()),
new AddParamTypeDeclaration(
'Nette\ComponentModel\Component',
'attached',
0,
'Nette\ComponentModel\IComponent'
new ObjectType('Nette\ComponentModel\IComponent')
),
new AddParamTypeDeclaration(
'Nette\ComponentModel\Component',
'detached',
0,
'Nette\ComponentModel\IComponent'
new ObjectType('Nette\ComponentModel\IComponent')
),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'link', 0, 'string'),
new AddParamTypeDeclaration('Nette\ComponentModel\Container', 'getComponent', 1, 'bool'),
new AddParamTypeDeclaration('Nette\ComponentModel\Container', 'createComponent', 0, 'string'),
new AddParamTypeDeclaration('Nette\ComponentModel\Component', 'link', 0, new StringType()),
new AddParamTypeDeclaration('Nette\ComponentModel\Container', 'getComponent', 1, new BooleanType()),
new AddParamTypeDeclaration('Nette\ComponentModel\Container', 'createComponent', 0, new StringType()),
new AddParamTypeDeclaration(
'Nette\ComponentModel\IComponent',
'setParent',
0,
'?Nette\ComponentModel\IContainer'
new UnionType([new ObjectType('Nette\ComponentModel\IContainer'), new NullType()])
),
new AddParamTypeDeclaration('Nette\ComponentModel\IComponent', 'setParent', 1, 'string'),
new AddParamTypeDeclaration('Nette\ComponentModel\IContainer', 'getComponents', 0, 'bool'),
new AddParamTypeDeclaration('Nette\Bridges\SecurityDI\SecurityExtension', '__construct', 0, 'bool'),
new AddParamTypeDeclaration('Nette\Security\IUserStorage', 'setAuthenticated', 0, 'bool'),
new AddParamTypeDeclaration('Nette\ComponentModel\IComponent', 'setParent', 1, new StringType()),
new AddParamTypeDeclaration('Nette\ComponentModel\IContainer', 'getComponents', 0, new BooleanType()),
new AddParamTypeDeclaration(
'Nette\Bridges\SecurityDI\SecurityExtension',
'__construct',
0,
new BooleanType()
),
new AddParamTypeDeclaration('Nette\Security\IUserStorage', 'setAuthenticated', 0, new BooleanType()),
new AddParamTypeDeclaration(
'Nette\Security\IUserStorage',
'setIdentity',
0,
'?Nette\Security\IIdentity'
new UnionType([new ObjectType('Nette\Security\IIdentity'), new NullType()])
),
new AddParamTypeDeclaration('Nette\Security\IUserStorage', 'setExpiration', 1, 'int'),
new AddParamTypeDeclaration('Nette\Security\Identity', '__construct', 2, 'iterable'),
new AddParamTypeDeclaration('Nette\Security\Identity', '__set', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Identity', '&__get', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Identity', '__isset', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Passwords', 'hash', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Passwords', 'verify', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Passwords', 'verify', 1, 'string'),
new AddParamTypeDeclaration('Nette\Security\Passwords', 'needsRehash', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'addRole', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'hasRole', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'getRoleParents', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'removeRole', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'addResource', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'addResource', 1, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'hasResource', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'resourceInheritsFrom', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'resourceInheritsFrom', 1, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'resourceInheritsFrom', 2, 'bool'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'removeResource', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'allow', 3, 'callable'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'deny', 3, 'callable'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'setRule', 0, 'bool'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'setRule', 1, 'bool'),
new AddParamTypeDeclaration('Nette\Security\Permission', 'setRule', 5, 'callable'),
new AddParamTypeDeclaration('Nette\Security\User', 'logout', 0, 'bool'),
new AddParamTypeDeclaration('Nette\Security\User', 'getAuthenticator', 0, 'bool'),
new AddParamTypeDeclaration('Nette\Security\User', 'isInRole', 0, 'string'),
new AddParamTypeDeclaration('Nette\Security\User', 'getAuthorizator', 0, 'bool'),
new AddParamTypeDeclaration('Nette\Security\User', 'getAuthorizator', 1, 'string'),
new AddParamTypeDeclaration('Nette\Security\IUserStorage', 'setExpiration', 1, new IntegerType()),
new AddParamTypeDeclaration('Nette\Security\Identity', '__construct', 2, $iterableType),
new AddParamTypeDeclaration('Nette\Security\Identity', '__set', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Identity', '&__get', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Identity', '__isset', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Passwords', 'hash', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Passwords', 'verify', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Passwords', 'verify', 1, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Passwords', 'needsRehash', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'addRole', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'hasRole', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'getRoleParents', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'removeRole', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'addResource', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'addResource', 1, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'hasResource', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'resourceInheritsFrom', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'resourceInheritsFrom', 1, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'resourceInheritsFrom', 2, new BooleanType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'removeResource', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'allow', 3, new CallableType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'deny', 3, new CallableType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'setRule', 0, new BooleanType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'setRule', 1, new BooleanType()),
new AddParamTypeDeclaration('Nette\Security\Permission', 'setRule', 5, new CallableType()),
new AddParamTypeDeclaration('Nette\Security\User', 'logout', 0, new BooleanType()),
new AddParamTypeDeclaration('Nette\Security\User', 'getAuthenticator', 0, new BooleanType()),
new AddParamTypeDeclaration('Nette\Security\User', 'isInRole', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\User', 'getAuthorizator', 0, new BooleanType()),
new AddParamTypeDeclaration('Nette\Security\User', 'getAuthorizator', 1, new StringType()),
]),
]]);
};

View File

@ -2,368 +2,552 @@
declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
# scalar type hints, see https://github.com/nette/security/commit/84024f612fb3f55f5d6e3e3e28eef1ad0388fa56
$arrayType = new ArrayType(new MixedType(), new MixedType());
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration('Nette\Mail\Mailer', 'send', 'void'),
new AddReturnTypeDeclaration('Nette\Mail\Mailer', 'send', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Forms\Rendering\DefaultFormRenderer',
'renderControl',
'Nette\Utils\Html'
new ObjectType('Nette\Utils\Html')
),
new AddReturnTypeDeclaration('Nette\Caching\Cache', 'generateKey', 'string'),
new AddReturnTypeDeclaration('Nette\Security\IResource', 'getResourceId', 'string'),
new AddReturnTypeDeclaration('Nette\Caching\Cache', 'generateKey', new StringType()),
new AddReturnTypeDeclaration('Nette\Security\IResource', 'getResourceId', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Security\IAuthenticator',
'authenticate',
'Nette\Security\IIdentity'
new ObjectType('Nette\Security\IIdentity')
),
new AddReturnTypeDeclaration('Nette\Security\IAuthorizator', 'isAllowed', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Security\Identity', 'getData', $arrayType),
new AddReturnTypeDeclaration('Nette\Security\IIdentity', 'getRoles', $arrayType),
new AddReturnTypeDeclaration(
'Nette\Security\User',
'getStorage',
new ObjectType('Nette\Security\IUserStorage')
),
new AddReturnTypeDeclaration('Nette\Security\User', 'login', new VoidType()),
new AddReturnTypeDeclaration('Nette\Security\User', 'logout', new VoidType()),
new AddReturnTypeDeclaration('Nette\Security\User', 'isLoggedIn', new BooleanType()),
new AddReturnTypeDeclaration(
'Nette\Security\User',
'getIdentity',
new UnionType([new ObjectType('Nette\Security\IIdentity'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Security\IAuthorizator', 'isAllowed', 'bool'),
new AddReturnTypeDeclaration('Nette\Security\Identity', 'getData', 'array'),
new AddReturnTypeDeclaration('Nette\Security\IIdentity', 'getRoles', 'array'),
new AddReturnTypeDeclaration('Nette\Security\User', 'getStorage', 'Nette\Security\IUserStorage'),
new AddReturnTypeDeclaration('Nette\Security\User', 'login', 'void'),
new AddReturnTypeDeclaration('Nette\Security\User', 'logout', 'void'),
new AddReturnTypeDeclaration('Nette\Security\User', 'isLoggedIn', 'bool'),
new AddReturnTypeDeclaration('Nette\Security\User', 'getIdentity', '?Nette\Security\IIdentity'),
new AddReturnTypeDeclaration(
'Nette\Security\User',
'getAuthenticator',
'?Nette\Security\IAuthenticator'
new UnionType([new ObjectType('Nette\Security\IAuthenticator'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Security\User', 'getAuthorizator', '?Nette\Security\IAuthorizator'),
new AddReturnTypeDeclaration('Nette\Security\User', 'getLogoutReason', '?int'),
new AddReturnTypeDeclaration('Nette\Security\User', 'getRoles', 'array'),
new AddReturnTypeDeclaration('Nette\Security\User', 'isInRole', 'bool'),
new AddReturnTypeDeclaration('Nette\Security\User', 'isAllowed', 'bool'),
new AddReturnTypeDeclaration('Nette\Security\IUserStorage', 'isAuthenticated', 'bool'),
new AddReturnTypeDeclaration('Nette\Security\IUserStorage', 'getIdentity', '?Nette\Security\IIdentity'),
new AddReturnTypeDeclaration('Nette\Security\IUserStorage', 'getLogoutReason', '?int'),
new AddReturnTypeDeclaration(
'Nette\Security\User',
'getAuthorizator',
new UnionType([new ObjectType('Nette\Security\IAuthorizator'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Security\User', 'getLogoutReason',
new UnionType([new IntegerType(), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Security\User', 'getRoles', $arrayType),
new AddReturnTypeDeclaration('Nette\Security\User', 'isInRole', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Security\User', 'isAllowed', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Security\IUserStorage', 'isAuthenticated', new BooleanType()),
new AddReturnTypeDeclaration(
'Nette\Security\IUserStorage',
'getIdentity',
new UnionType([new ObjectType('Nette\Security\IIdentity'), new NullType()])
),
new AddReturnTypeDeclaration(
'Nette\Security\IUserStorage',
'getLogoutReason',
new UnionType([new IntegerType(), new NullType()])),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\Component',
'lookup',
'Nette\ComponentModel\IComponent'
new ObjectType('Nette\ComponentModel\IComponent')
),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'lookupPath', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'monitor', new VoidType()),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'unmonitor', new VoidType()),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'attached', new VoidType()),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'detached', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\Component',
'getName',
new UnionType([new StringType(), new NullType()])
),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\IComponent',
'getName',
new UnionType([new StringType(), new NullType()])
),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'lookupPath', '?string'),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'monitor', 'void'),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'unmonitor', 'void'),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'attached', 'void'),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'detached', 'void'),
new AddReturnTypeDeclaration('Nette\ComponentModel\Component', 'getName', '?string'),
new AddReturnTypeDeclaration('Nette\ComponentModel\IComponent', 'getName', '?string'),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\IComponent',
'getParent',
'?Nette\ComponentModel\IContainer'
new UnionType([new ObjectType('Nette\ComponentModel\IContainer'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\ComponentModel\Container', 'removeComponent', 'void'),
new AddReturnTypeDeclaration('Nette\ComponentModel\Container', 'removeComponent', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\Container',
'getComponent',
'?Nette\ComponentModel\IComponent'
new UnionType([new ObjectType('Nette\ComponentModel\IComponent'), new NullType()])
),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\Container',
'createComponent',
'?Nette\ComponentModel\IComponent'
new UnionType([new ObjectType('Nette\ComponentModel\IComponent'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\ComponentModel\Container', 'getComponents',
new ObjectType('Iterator')
),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\Container',
'validateChildComponent',
new VoidType()
),
new AddReturnTypeDeclaration('Nette\ComponentModel\Container', 'getComponents', 'Iterator'),
new AddReturnTypeDeclaration('Nette\ComponentModel\Container', 'validateChildComponent', 'void'),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\Container',
'_isCloning',
'?Nette\ComponentModel\IComponent'
new UnionType([new ObjectType('Nette\ComponentModel\IComponent'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\ComponentModel\IContainer', 'removeComponent', 'void'),
new AddReturnTypeDeclaration('Nette\ComponentModel\IContainer', 'removeComponent', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\ComponentModel\IContainer',
'getComponent',
'?Nette\ComponentModel\IContainer'
new UnionType([new ObjectType('Nette\ComponentModel\IContainer'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\ComponentModel\IContainer', 'getComponents', 'Iterator'),
new AddReturnTypeDeclaration('Nette\Application\Application', 'run', 'void'),
new AddReturnTypeDeclaration('Nette\ComponentModel\IContainer', 'getComponents', new ObjectType(
'Iterator'
)),
new AddReturnTypeDeclaration('Nette\Application\Application', 'run', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\Application',
'createInitialRequest',
'Nette\Application\Request'
new ObjectType('Nette\Application\Request')
),
new AddReturnTypeDeclaration('Nette\Application\Application', 'processRequest', 'void'),
new AddReturnTypeDeclaration('Nette\Application\Application', 'processException', 'void'),
new AddReturnTypeDeclaration('Nette\Application\Application', 'getRequests', 'array'),
new AddReturnTypeDeclaration('Nette\Application\Application', 'processRequest', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\Application', 'processException', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\Application', 'getRequests', $arrayType),
new AddReturnTypeDeclaration(
'Nette\Application\Application',
'getPresenter',
'?Nette\Application\IPresenter'
new UnionType([new ObjectType('Nette\Application\IPresenter'), new NullType()])
),
new AddReturnTypeDeclaration(
'Nette\Application\Application',
'getRouter',
'?Nette\Application\IRouter'
new UnionType([new ObjectType('Nette\Application\IRouter'), new NullType()])
),
new AddReturnTypeDeclaration(
'Nette\Application\Application',
'getPresenterFactory',
'?Nette\Application\IPresenterFactory'
new UnionType([new ObjectType('Nette\Application\IPresenterFactory'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Application\Helpers', 'splitName', $arrayType),
new AddReturnTypeDeclaration(
'Nette\Application\IPresenter',
'run',
new ObjectType('Nette\Application\IResponse')
),
new AddReturnTypeDeclaration(
'Nette\Application\IPresenterFactory',
'getPresenterClass',
new StringType()
),
new AddReturnTypeDeclaration('Nette\Application\Helpers', 'splitName', 'array'),
new AddReturnTypeDeclaration('Nette\Application\IPresenter', 'run', 'Nette\Application\IResponse'),
new AddReturnTypeDeclaration('Nette\Application\IPresenterFactory', 'getPresenterClass', 'string'),
new AddReturnTypeDeclaration(
'Nette\Application\IPresenterFactory',
'createPresenter',
'Nette\Application\IPresenter'
new ObjectType('Nette\Application\IPresenter')
),
new AddReturnTypeDeclaration(
'Nette\Application\PresenterFactory',
'formatPresenterClass',
new StringType()
),
new AddReturnTypeDeclaration(
'Nette\Application\PresenterFactory',
'unformatPresenterClass',
new UnionType([new StringType(), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Application\IResponse', 'send', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\Responses\FileResponse', 'getFile', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\Responses\FileResponse', 'getName', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Application\Responses\FileResponse',
'getContentType',
new StringType()
),
new AddReturnTypeDeclaration('Nette\Application\PresenterFactory', 'formatPresenterClass', 'string'),
new AddReturnTypeDeclaration('Nette\Application\PresenterFactory', 'unformatPresenterClass', '?string'),
new AddReturnTypeDeclaration('Nette\Application\IResponse', 'send', 'void'),
new AddReturnTypeDeclaration('Nette\Application\Responses\FileResponse', 'getFile', 'string'),
new AddReturnTypeDeclaration('Nette\Application\Responses\FileResponse', 'getName', 'string'),
new AddReturnTypeDeclaration('Nette\Application\Responses\FileResponse', 'getContentType', 'string'),
new AddReturnTypeDeclaration(
'Nette\Application\Responses\ForwardResponse',
'getRequest',
'Nette\Application\Request'
new ObjectType('Nette\Application\Request')
),
new AddReturnTypeDeclaration('Nette\Application\Request', 'getPresenterName', 'string'),
new AddReturnTypeDeclaration('Nette\Application\Request', 'getParameters', 'array'),
new AddReturnTypeDeclaration('Nette\Application\Request', 'getFiles', 'array'),
new AddReturnTypeDeclaration('Nette\Application\Request', 'getMethod', '?string'),
new AddReturnTypeDeclaration('Nette\Application\Request', 'isMethod', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\Request', 'hasFlag', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\RedirectResponse', 'getUrl', 'string'),
new AddReturnTypeDeclaration('Nette\Application\RedirectResponse', 'getCode', 'int'),
new AddReturnTypeDeclaration('Nette\Application\JsonResponse', 'getContentType', 'string'),
new AddReturnTypeDeclaration('Nette\Application\IRouter', 'match', '?Nette\Application\Request'),
new AddReturnTypeDeclaration('Nette\Application\IRouter', 'constructUrl', '?string'),
new AddReturnTypeDeclaration('Nette\Application\Routers\Route', 'getMask', 'string'),
new AddReturnTypeDeclaration('Nette\Application\Routers\Route', 'getDefaults', 'array'),
new AddReturnTypeDeclaration('Nette\Application\Routers\Route', 'getFlags', 'int'),
new AddReturnTypeDeclaration('Nette\Application\Routers\Route', 'getTargetPresenters', '?array'),
new AddReturnTypeDeclaration('Nette\Application\Routers\RouteList', 'warmupCache', 'void'),
new AddReturnTypeDeclaration('Nette\Application\Routers\RouteList', 'offsetSet', 'void'),
new AddReturnTypeDeclaration('Nette\Application\Routers\RouteList', 'getModule', '?string'),
new AddReturnTypeDeclaration('Nette\Application\Routers\CliRouter', 'getDefaults', 'array'),
new AddReturnTypeDeclaration('Nette\Application\Request', 'getPresenterName', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\Request', 'getParameters', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\Request', 'getFiles', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\Request', 'getMethod', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration('Nette\Application\Request', 'isMethod', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Application\Request', 'hasFlag', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Application\RedirectResponse', 'getUrl', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\RedirectResponse', 'getCode', new IntegerType()),
new AddReturnTypeDeclaration('Nette\Application\JsonResponse', 'getContentType', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Application\IRouter',
'match',
new UnionType([new ObjectType('Nette\Application\Request'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Application\IRouter', 'constructUrl', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration('Nette\Application\Routers\Route', 'getMask', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\Routers\Route', 'getDefaults', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\Routers\Route', 'getFlags', new IntegerType()),
new AddReturnTypeDeclaration(
'Nette\Application\Routers\Route',
'getTargetPresenters',
new UnionType([$arrayType, new NullType()])
),
new AddReturnTypeDeclaration('Nette\Application\Routers\RouteList', 'warmupCache', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\Routers\RouteList', 'offsetSet', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\Routers\RouteList', 'getModule', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration('Nette\Application\Routers\CliRouter', 'getDefaults', $arrayType),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Component',
'getPresenter',
'?Nette\Application\UI\Presenter'
new UnionType([new ObjectType('Nette\Application\UI\Presenter'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'getUniqueId', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'tryCall', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'checkRequirements', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'getUniqueId', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'tryCall', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'checkRequirements', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Component',
'getReflection',
'Nette\Application\UI\ComponentReflection'
new ObjectType('Nette\Application\UI\ComponentReflection')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'loadState', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'saveState', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'getParameters', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'getParameterId', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'getPersistentParams', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'signalReceived', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'formatSignalMethod', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'link', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'lazyLink', 'Nette\Application\UI\Link'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'isLinkCurrent', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'redirect', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'redirectPermanent', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'offsetSet', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'loadState', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'saveState', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'getParameters', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'getParameterId', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'getPersistentParams', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'signalReceived', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'formatSignalMethod', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'link', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Component',
'lazyLink',
new ObjectType('Nette\Application\UI\Link')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'isLinkCurrent', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'redirect', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'redirectPermanent', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'offsetSet', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Component',
'offsetGet',
'Nette\ComponentModel\IComponent'
new ObjectType('Nette\ComponentModel\IComponent')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'offsetExists', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'offsetUnset', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'offsetExists', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Component', 'offsetUnset', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getRequest',
'Nette\Application\Request'
new ObjectType('Nette\Application\Request')
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getPresenter',
'Nette\Application\UI\Presenter'
new ObjectType('Nette\Application\UI\Presenter')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getUniqueId', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'checkRequirements', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'processSignal', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getSignal', '?array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'isSignalReceiver', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getAction', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'changeAction', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getView', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'sendTemplate', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'findLayoutTemplateFile', '?string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'formatLayoutTemplateFiles', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'formatTemplateFiles', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'formatActionMethod', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'formatRenderMethod', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getUniqueId', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'checkRequirements', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'processSignal', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getSignal',
new UnionType([$arrayType, new NullType()])
),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'isSignalReceiver', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getAction', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'changeAction', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getView', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'sendTemplate', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'findLayoutTemplateFile', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'formatLayoutTemplateFiles', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'formatTemplateFiles', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'formatActionMethod', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'formatRenderMethod', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'createTemplate',
'Nette\Application\UI\ITemplate'
new ObjectType('Nette\Application\UI\ITemplate')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getPayload', 'stdClass'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'isAjax', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'sendPayload', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'sendJson', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'sendResponse', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'terminate', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'forward', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'redirectUrl', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'error', 'void'),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getPayload',
new ObjectType('stdClass')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'isAjax', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'sendPayload', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'sendJson', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'sendResponse', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'terminate', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'forward', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'redirectUrl', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'error', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getLastCreatedRequest',
'?Nette\Application\Request'
new UnionType([new ObjectType('Nette\Application\Request'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getLastCreatedRequestFlag', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'canonicalize', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'lastModified', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'createRequest', '?string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'argsToParams', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'handleInvalidLink', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'storeRequest', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'restoreRequest', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getPersistentComponents', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getGlobalState', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'saveGlobalState', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'initGlobalParameters', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'popGlobalParameters', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getFlashKey', '?string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'hasFlashSession', 'bool'),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getLastCreatedRequestFlag',
new BooleanType()
),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'canonicalize', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'lastModified', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'createRequest', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'argsToParams', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'handleInvalidLink', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'storeRequest', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'restoreRequest', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getPersistentComponents', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getGlobalState', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'saveGlobalState', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'initGlobalParameters', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'popGlobalParameters', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getFlashKey', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'hasFlashSession', new BooleanType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getFlashSession',
'Nette\Http\SessionSection'
new ObjectType('Nette\Http\SessionSection')
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getContext',
new ObjectType('Nette\DI\Container')
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getHttpRequest',
new ObjectType('Nette\Http\IRequest')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getContext', 'Nette\DI\Container'),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getHttpRequest', 'Nette\Http\IRequest'),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getHttpResponse',
'Nette\Http\IResponse'
new ObjectType('Nette\Http\IResponse')
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getUser',
new ObjectType('Nette\Security\User')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Presenter', 'getUser', 'Nette\Security\User'),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Presenter',
'getTemplateFactory',
'Nette\Application\UI\ITemplateFactory'
new ObjectType('Nette\Application\UI\ITemplateFactory')
),
new AddReturnTypeDeclaration('Nette\Application\Exception\BadRequestException', 'getHttpCode', 'int'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationDI\LatteExtension', 'addMacro', 'void'),
new AddReturnTypeDeclaration(
'Nette\Application\Exception\BadRequestException',
'getHttpCode',
new IntegerType()
),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationDI\LatteExtension', 'addMacro', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Bridges\ApplicationDI\PresenterFactoryCallback',
'__invoke',
'Nette\Application\IPresenter'
new ObjectType('Nette\Application\IPresenter')
),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\ILatteFactory', 'create', 'Latte\Engine'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', 'getLatte', 'Latte\Engine'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', 'render', 'void'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', '__toString', 'string'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', 'getFile', '?string'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', 'getParameters', 'array'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', '__set', 'void'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', '__unset', 'void'),
new AddReturnTypeDeclaration(
'Nette\Bridges\ApplicationLatte\ILatteFactory',
'create',
new ObjectType('Latte\Engine')
),
new AddReturnTypeDeclaration(
'Nette\Bridges\ApplicationLatte\Template',
'getLatte',
new ObjectType('Latte\Engine')
),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', 'render', new VoidType()),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', '__toString', new StringType()),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', 'getFile', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', 'getParameters', $arrayType),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', '__set', new VoidType()),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\Template', '__unset', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Bridges\ApplicationLatte\TemplateFactory',
'createTemplate',
'Nette\Application\UI\ITemplate'
new ObjectType('Nette\Application\UI\ITemplate')
),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\UIMacros', 'initialize', 'void'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationTracy\RoutingPanel', 'initializePanel', 'void'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationTracy\RoutingPanel', 'getTab', 'string'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationTracy\RoutingPanel', 'getPanel', 'string'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\UIRuntime', 'initialize', 'void'),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\UIMacros', 'initialize', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Bridges\ApplicationTracy\RoutingPanel',
'initializePanel',
new VoidType()
),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationTracy\RoutingPanel', 'getTab', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Bridges\ApplicationTracy\RoutingPanel',
'getPanel',
new StringType()
),
new AddReturnTypeDeclaration('Nette\Bridges\ApplicationLatte\UIRuntime', 'initialize', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\ComponentReflection',
'getPersistentParams',
'array'
$arrayType
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\ComponentReflection',
'getPersistentComponents',
'array'
$arrayType
),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'hasCallableMethod', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'combineArgs', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'convertType', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'parseAnnotation', '?array'),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'getParameterType', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'hasAnnotation', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'getMethods', 'array'),
new AddReturnTypeDeclaration(
'Nette\Application\UI\ComponentReflection',
'hasCallableMethod',
new BooleanType()
),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'combineArgs', $arrayType),
new AddReturnTypeDeclaration(
'Nette\Application\UI\ComponentReflection',
'convertType',
new BooleanType()
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\ComponentReflection',
'parseAnnotation',
new UnionType([$arrayType, new NullType()])
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\ComponentReflection',
'getParameterType',
$arrayType
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\ComponentReflection',
'hasAnnotation',
new BooleanType()
),
new AddReturnTypeDeclaration('Nette\Application\UI\ComponentReflection', 'getMethods', $arrayType),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Control',
'getTemplate',
'Nette\Application\UI\ITemplate'
new ObjectType('Nette\Application\UI\ITemplate')
),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Control',
'createTemplate',
'Nette\Application\UI\ITemplate'
new ObjectType('Nette\Application\UI\ITemplate')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'templatePrepareFilters', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'flashMessage', 'stdClass'),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'redrawControl', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'isControlInvalid', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'getSnippetId', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'templatePrepareFilters', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Control',
'flashMessage',
new ObjectType('stdClass')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'redrawControl', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'isControlInvalid', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Control', 'getSnippetId', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\Form',
'getPresenter',
'?Nette\Application\UI\Presenter'
new UnionType([new ObjectType('Nette\Application\UI\Presenter'), new NullType()]),
),
new AddReturnTypeDeclaration('Nette\Application\UI\Form', 'signalReceived', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\IRenderable', 'redrawControl', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\IRenderable', 'isControlInvalid', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\ITemplate', 'render', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\ITemplate', 'getFile', '?string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Form', 'signalReceived', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\IRenderable', 'redrawControl', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\IRenderable', 'isControlInvalid', new BooleanType()),
new AddReturnTypeDeclaration('Nette\Application\UI\ITemplate', 'render', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\ITemplate', 'getFile', new UnionType([
new StringType(),
new NullType(),
])),
new AddReturnTypeDeclaration(
'Nette\Application\UI\ITemplateFactory',
'createTemplate',
'Nette\Application\UI\ITemplate'
new ObjectType('Nette\Application\UI\ITemplate')
),
new AddReturnTypeDeclaration('Nette\Application\UI\Link', 'getDestination', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\Link', 'getParameters', 'array'),
new AddReturnTypeDeclaration('Nette\Application\UI\Link', '__toString', 'string'),
new AddReturnTypeDeclaration('Nette\Application\UI\MethodReflection', 'hasAnnotation', 'bool'),
new AddReturnTypeDeclaration('Nette\Application\UI\IStatePersistent', 'loadState', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\IStatePersistent', 'saveState', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\ISignalReceiver', 'signalReceived', 'void'),
new AddReturnTypeDeclaration('Nette\Application\UI\Link', 'getDestination', new StringType()),
new AddReturnTypeDeclaration('Nette\Application\UI\Link', 'getParameters', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\UI\Link', '__toString', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Application\UI\MethodReflection',
'hasAnnotation',
new BooleanType()
),
new AddReturnTypeDeclaration('Nette\Application\UI\IStatePersistent', 'loadState', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\IStatePersistent', 'saveState', new VoidType()),
new AddReturnTypeDeclaration('Nette\Application\UI\ISignalReceiver', 'signalReceived', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\Routers\SimpleRouter',
'match',
'?Nette\Application\Request'
new UnionType([new ObjectType('Nette\Application\Request'), new NullType()]),
),
new AddReturnTypeDeclaration('Nette\Application\Routers\SimpleRouter', 'getDefaults', $arrayType),
new AddReturnTypeDeclaration('Nette\Application\Routers\SimpleRouter', 'getFlags', new IntegerType()),
new AddReturnTypeDeclaration('Nette\Application\LinkGenerator', 'link', new StringType()),
new AddReturnTypeDeclaration(
'Nette\Application\MicroPresenter',
'getContext',
new UnionType([new ObjectType('Nette\DI\Container'), new NullType()])
),
new AddReturnTypeDeclaration('Nette\Application\Routers\SimpleRouter', 'getDefaults', 'array'),
new AddReturnTypeDeclaration('Nette\Application\Routers\SimpleRouter', 'getFlags', 'int'),
new AddReturnTypeDeclaration('Nette\Application\LinkGenerator', 'link', 'string'),
new AddReturnTypeDeclaration('Nette\Application\MicroPresenter', 'getContext', '?Nette\DI\Container'),
new AddReturnTypeDeclaration(
'Nette\Application\MicroPresenter',
'createTemplate',
'Nette\Application\UI\ITemplate'
new ObjectType('Nette\Application\UI\ITemplate')
),
new AddReturnTypeDeclaration(
'Nette\Application\MicroPresenter',
'redirectUrl',
'Nette\Application\Responses\RedirectResponse'
new ObjectType('Nette\Application\Responses\RedirectResponse')
),
new AddReturnTypeDeclaration('Nette\Application\MicroPresenter', 'error', 'void'),
new AddReturnTypeDeclaration('Nette\Application\MicroPresenter', 'error', new VoidType()),
new AddReturnTypeDeclaration(
'Nette\Application\MicroPresenter',
'getRequest',
'?Nette\Application\Request'
new UnionType([new ObjectType('Nette\Application\Request'), new NullType()])
),
]),
]]);

View File

@ -30,87 +30,79 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(AddDatePickerToDateControlRector::class);
$services->set(ChangeFormArrayAccessToAnnotatedControlVariableRector::class);
$services->set(GetConfigWithDefaultsArgumentToArrayMergeInCompilerExtensionRector::class);
// Control class has remove __construct(), e.g. https://github.com/Pixidos/GPWebPay/pull/16/files#diff-fdc8251950f85c5467c63c249df05786
$services->set(RemoveParentCallWithoutParentRector::class);
// https://github.com/nette/utils/commit/d0041ba59f5d8bf1f5b3795fd76d43fb13ea2e15
$services->set(FormerNullableArgumentToScalarTypedRector::class);
$services->set(StaticCallToMethodCallRector::class)->call('configure', [[
StaticCallToMethodCallRector::STATIC_CALLS_TO_METHOD_CALLS => inline_value_objects(
[new StaticCallToMethodCall(
'Nette\Security\Passwords',
'hash',
'Nette\Security\Passwords',
'hash'
), new StaticCallToMethodCall(
'Nette\Security\Passwords',
'verify',
'Nette\Security\Passwords',
'verify'
), new StaticCallToMethodCall(
$services->set(StaticCallToMethodCallRector::class)
->call('configure', [[
StaticCallToMethodCallRector::STATIC_CALLS_TO_METHOD_CALLS => inline_value_objects([
new StaticCallToMethodCall('Nette\Security\Passwords', 'hash', 'Nette\Security\Passwords', 'hash'),
new StaticCallToMethodCall('Nette\Security\Passwords', 'verify', 'Nette\Security\Passwords', 'verify'),
new StaticCallToMethodCall(
'Nette\Security\Passwords',
'needsRehash',
'Nette\Security\Passwords',
'needsRehash'
)]
),
]]);
), ]
),
]]);
// https://github.com/contributte/event-dispatcher-extra/tree/v0.4.3 and higher
$services->set(RenameClassConstantRector::class)->call('configure', [[
RenameClassConstantRector::CLASS_CONSTANT_RENAME => inline_value_objects(
[new RenameClassConstant(
'Contributte\Events\Extra\Event\Security\LoggedInEvent',
'NAME',
'class'
), new RenameClassConstant(
'Contributte\Events\Extra\Event\Security\LoggedOutEvent',
'NAME',
'class'
), new RenameClassConstant('Contributte\Events\Extra\Event\Application\ShutdownEvent', 'NAME', 'class')]
),
]]);
$services->set(RenameClassRector::class)->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
# nextras/forms was split into 2 packages
'Nextras\FormComponents\Controls\DatePicker' => 'Nextras\FormComponents\Controls\DateControl',
# @see https://github.com/nette/di/commit/a0d361192f8ac35f1d9f82aab7eb351e4be395ea
'Nette\DI\ServiceDefinition' => 'Nette\DI\Definitions\ServiceDefinition',
'Nette\DI\Statement' => 'Nette\DI\Definitions\Statement',
],
]]);
$services->set(ArgumentDefaultValueReplacerRector::class)->call('configure', [[
ArgumentDefaultValueReplacerRector::REPLACED_ARGUMENTS => inline_value_objects([
// json 2nd argument is now int typed
new ArgumentDefaultValueReplacer('Nette\Utils\Json', 'decode', 1, true, 'Nette\Utils\Json::FORCE_ARRAY'),
// @see https://github.com/nette/forms/commit/574b97f9d5e7a902a224e57d7d584e7afc9fefec
new ArgumentDefaultValueReplacer('Nette\Forms\Form', 'decode', 0, true, 'array'),
]),
]]);
$services->set(RenameMethodRector::class)->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => inline_value_objects(
[new MethodCallRename('Nette\Forms\Controls\BaseControl', 'setAttribute', 'setHtmlAttribute')]
),
]]);
$services->set(RenameMethodRector::class)->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => inline_value_objects([new MethodCallRename(
'Nette\Forms\Controls\BaseControl',
# see https://github.com/nette/forms/commit/b99385aa9d24d729a18f6397a414ea88eab6895a
'setType',
'setHtmlType'
), new MethodCallRename(
'Nette\Forms\Controls\BaseControl',
'setAttribute',
'setHtmlAttribute'
), new MethodCallRename(
'Nette\DI\Definitions\ServiceDefinition',
# see https://github.com/nette/di/commit/1705a5db431423fc610a6f339f88dead1b5dc4fb
'setClass',
'setType'
), new MethodCallRename(
'Nette\DI\Definitions\ServiceDefinition',
'getClass',
'getType'
), new MethodCallRename('Nette\DI\Definitions\Definition', 'isAutowired', 'getAutowired')]),
]]);
$services->set(RenameClassConstantRector::class)
->call('configure', [[
RenameClassConstantRector::CLASS_CONSTANT_RENAME => inline_value_objects([
new RenameClassConstant('Contributte\Events\Extra\Event\Security\LoggedInEvent', 'NAME', 'class'),
new RenameClassConstant('Contributte\Events\Extra\Event\Security\LoggedOutEvent', 'NAME', 'class'),
new RenameClassConstant('Contributte\Events\Extra\Event\Application\ShutdownEvent', 'NAME', 'class'), ]
),
]]);
$services->set(RenameClassRector::class)
->call('configure', [[
RenameClassRector::OLD_TO_NEW_CLASSES => [
# nextras/forms was split into 2 packages
'Nextras\FormComponents\Controls\DatePicker' => 'Nextras\FormComponents\Controls\DateControl',
# @see https://github.com/nette/di/commit/a0d361192f8ac35f1d9f82aab7eb351e4be395ea
'Nette\DI\ServiceDefinition' => 'Nette\DI\Definitions\ServiceDefinition',
'Nette\DI\Statement' => 'Nette\DI\Definitions\Statement',
],
]]);
$services->set(ArgumentDefaultValueReplacerRector::class)
->call('configure', [[
ArgumentDefaultValueReplacerRector::REPLACED_ARGUMENTS => inline_value_objects([
// json 2nd argument is now `int` typed
new ArgumentDefaultValueReplacer(
'Nette\Utils\Json',
'decode',
1,
true,
'Nette\Utils\Json::FORCE_ARRAY'
),
// @see https://github.com/nette/forms/commit/574b97f9d5e7a902a224e57d7d584e7afc9fefec
new ArgumentDefaultValueReplacer('Nette\Forms\Form', 'decode', 0, true, 'array'),
]),
]]);
$services->set(RenameMethodRector::class)
->call('configure', [[
RenameMethodRector::METHOD_CALL_RENAMES => inline_value_objects([
new MethodCallRename('Nette\Forms\Controls\BaseControl', 'setAttribute', 'setHtmlAttribute'),
// see https://github.com/nette/forms/commit/b99385aa9d24d729a18f6397a414ea88eab6895a
new MethodCallRename('Nette\Forms\Controls\BaseControl', 'setType', 'setHtmlType'),
new MethodCallRename('Nette\Forms\Controls\BaseControl', 'setAttribute', 'setHtmlAttribute'),
new MethodCallRename(
'Nette\DI\Definitions\ServiceDefinition',
# see https://github.com/nette/di/commit/1705a5db431423fc610a6f339f88dead1b5dc4fb
'setClass',
'setType'
),
new MethodCallRename('Nette\DI\Definitions\ServiceDefinition', 'getClass', 'getType'),
new MethodCallRename('Nette\DI\Definitions\Definition', 'isAutowired', 'getAutowired'), ]),
]]);
$services->set(MagicHtmlCallToAppendAttributeRector::class);
$services->set(RequestGetCookieDefaultArgumentToCoalesceRector::class);
};

View File

@ -2,10 +2,9 @@
declare(strict_types=1);
use PHPStan\Type\ObjectType;
use Rector\Generic\Rector\Class_\RemoveInterfacesRector;
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use Rector\NetteToSymfony\Rector\Class_\FormControlToControllerAndFormTypeRector;
use Rector\NetteToSymfony\Rector\ClassMethod\RouterListToControllerAnnotationsRector;
use Rector\NetteToSymfony\Rector\Interface_\DeleteFactoryInterfaceRector;
@ -17,6 +16,8 @@ use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameClassConstant;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -38,7 +39,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
new AddReturnTypeDeclaration(
'Nette\Application\IPresenter',
'run',
'Symfony\Component\HttpFoundation\Response'
new ObjectType('Symfony\Component\HttpFoundation\Response')
),
]),
]]);

View File

@ -2,18 +2,22 @@
declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$arrayType = new ArrayType(new MixedType(), new MixedType());
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration('PhpSpec\ObjectBehavior', 'getMatchers', 'array'),
new AddReturnTypeDeclaration('PhpSpec\ObjectBehavior', 'getMatchers', $arrayType),
]),
]]);
};

View File

@ -2,8 +2,8 @@
declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use PHPStan\Type\MixedType;
use PHPStan\Type\VoidType;
use Rector\PHPUnit\Rector\MethodCall\AssertEqualsParameterToSpecificMethodsTypeRector;
use Rector\PHPUnit\Rector\MethodCall\ReplaceAssertArraySubsetRector;
use Rector\PHPUnit\Rector\MethodCall\SpecificAssertContainsRector;
@ -11,7 +11,9 @@ use Rector\PHPUnit\Rector\MethodCall\SpecificAssertInternalTypeRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -23,7 +25,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
->call('configure', [[
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => inline_value_objects([
// https://github.com/rectorphp/rector/issues/1024 - no type, $dataName
new AddParamTypeDeclaration('PHPUnit\Framework\TestCase', '__construct', 2, ''),
new AddParamTypeDeclaration('PHPUnit\Framework\TestCase', '__construct', 2, new MixedType()),
]),
]]);
@ -43,16 +45,15 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects(
[
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'setUpBeforeClass', 'void'),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'setUp', 'void'),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'assertPreConditions', 'void'),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'assertPostConditions', 'void'),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'tearDown', 'void'),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'tearDownAfterClass', 'void'),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'onNotSuccessfulTest', 'void'), ]
),
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'setUpBeforeClass', new VoidType()),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'setUp', new VoidType()),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'assertPreConditions', new VoidType()),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'assertPostConditions', new VoidType()),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'tearDown', new VoidType()),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'tearDownAfterClass', new VoidType()),
new AddReturnTypeDeclaration('PHPUnit\Framework\TestCase', 'onNotSuccessfulTest', new VoidType()),
]),
]]);
$services->set(ReplaceAssertArraySubsetRector::class);

View File

@ -2,14 +2,14 @@
declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Generic\Rector\ClassMethod\ArgumentDefaultValueReplacerRector;
use Rector\Generic\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\Rector\ClassMethod\WrapReturnRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use Rector\Generic\ValueObject\ArgumentAdder;
use Rector\Generic\ValueObject\ArgumentDefaultValueReplacer;
use Rector\Generic\ValueObject\ArgumentRemover;
@ -24,6 +24,8 @@ use Rector\Symfony\Rector\New_\StringToArrayArgumentProcessRector;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\Transform\Rector\New_\NewToStaticCallRector;
use Rector\Transform\ValueObject\NewToStaticCall;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# https://github.com/symfony/symfony/pull/28447
@ -161,13 +163,15 @@ return static function (ContainerConfigurator $containerConfigurator): void {
]),
]]);
$iterableType = new IterableType(new MixedType(), new MixedType());
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration(
'Symfony\Component\Form\AbstractTypeExtension',
'getExtendedTypes',
'iterable'
$iterableType
),
]),
]]);

View File

@ -2,6 +2,16 @@
declare(strict_types=1);
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
@ -12,6 +22,9 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$arrayType = new ArrayType(new MixedType(), new MixedType());
$iterableType = new IterableType(new MixedType(), new MixedType());
$services->set(AddParamTypeDeclarationRector::class)
->call('configure', [[
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => inline_value_objects([
@ -20,222 +33,412 @@ return static function (ContainerConfigurator $containerConfigurator): void {
'Symfony\Component\EventDispatcher\EventDispatcherInterface',
'addListener',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\EventDispatcher\EventDispatcherInterface',
'addListener',
2,
'int'
new IntegerType()
),
new AddParamTypeDeclaration(
'Symfony\Component\EventDispatcher\EventDispatcherInterface',
'removeListener',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\EventDispatcher\EventDispatcherInterface',
'getListeners',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\EventDispatcher\EventDispatcherInterface',
'getListenerPriority',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\EventDispatcher\EventDispatcherInterface',
'hasListeners',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Application',
'setCatchExceptions',
0,
new BooleanType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Application',
'setAutoExit',
0,
new BooleanType()
),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'setName', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'setVersion', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'register', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'get', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'has', 0, new StringType()),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Application',
'findNamespace',
0,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'find', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'all', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'getAbbreviations', 0, $arrayType),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Application',
'extractNamespace',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Application',
'extractNamespace',
1,
new IntegerType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Application',
'setDefaultCommand',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Application',
'setDefaultCommand',
1,
new BooleanType()
),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'setCatchExceptions', 0, 'bool'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'setAutoExit', 0, 'bool'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'setName', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'setVersion', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'register', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'get', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'has', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'findNamespace', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'find', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'all', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'getAbbreviations', 0, 'array'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'extractNamespace', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'extractNamespace', 1, 'int'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'setDefaultCommand', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Application', 'setDefaultCommand', 1, 'bool'),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'mergeApplicationDefinition',
0,
'bool'
new BooleanType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'addArgument',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'addArgument',
1,
new IntegerType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'addArgument',
2,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'addOption',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'addOption',
2,
new IntegerType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'addOption',
3,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'setName',
0,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'addArgument', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'addArgument', 1, 'int'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'addArgument', 2, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'addOption', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'addOption', 2, 'int'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'addOption', 3, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'setName', 0, 'string'),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'setProcessTitle',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'setHidden',
0,
new BooleanType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'setDescription',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'setHelp',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'setAliases',
0,
$iterableType
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'getSynopsis',
0,
new BooleanType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'addUsage',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Command\Command',
'getHelper',
0,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'setHidden', 0, 'bool'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'setDescription', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'setHelp', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'setAliases', 0, 'iterable'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'getSynopsis', 0, 'bool'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'addUsage', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Command\Command', 'getHelper', 0, 'string'),
new AddParamTypeDeclaration(
'Symfony\Component\Console\CommandLoader\CommandLoaderInterface',
'get',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\CommandLoader\CommandLoaderInterface',
'has',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Input\InputInterface',
'getArgument',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Input\InputInterface',
'setArgument',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Input\InputInterface',
'getOption',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Input\InputInterface',
'setOption',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Input\InputInterface',
'hasOption',
0,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Console\Input\InputInterface', 'getOption', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Input\InputInterface', 'setOption', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Console\Input\InputInterface', 'hasOption', 0, 'string'),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Input\InputInterface',
'setInteractive',
0,
'bool'
new BooleanType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Output\OutputInterface',
'write',
1,
new BooleanType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Output\OutputInterface',
'write',
2,
new IntegerType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Output\OutputInterface',
'writeln',
1,
new IntegerType()
),
new AddParamTypeDeclaration('Symfony\Component\Console\Output\OutputInterface', 'write', 1, 'bool'),
new AddParamTypeDeclaration('Symfony\Component\Console\Output\OutputInterface', 'write', 2, 'int'),
new AddParamTypeDeclaration('Symfony\Component\Console\Output\OutputInterface', 'writeln', 1, 'int'),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Output\OutputInterface',
'setVerbosity',
0,
'int'
new IntegerType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Console\Output\OutputInterface',
'setDecorated',
0,
'bool'
new BooleanType()
),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'signal', 0, new IntegerType()),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'stop', 0, new FloatType()),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'stop', 1, new IntegerType()),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'setTty', 0, new BooleanType()),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'setPty', 0, new BooleanType()),
new AddParamTypeDeclaration(
'Symfony\Component\Process\Process',
'setWorkingDirectory',
0,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'signal', 0, 'int'),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'stop', 0, 'float'),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'stop', 1, 'int'),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'setTty', 0, 'bool'),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'setPty', 0, 'bool'),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'setWorkingDirectory', 0, 'string'),
new AddParamTypeDeclaration(
'Symfony\Component\Process\Process',
'inheritEnvironmentVariables',
0,
'bool'
new BooleanType()
),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'updateStatus', 0, 'bool'),
new AddParamTypeDeclaration('Symfony\Component\Process\Process', 'updateStatus', 0, new BooleanType()),
new AddParamTypeDeclaration(
'Symfony\Component\EventDispatcher\EventDispatcher',
'dispatch',
0,
'object'
new ObjectWithoutClassType()
),
new AddParamTypeDeclaration(
'Symfony\Contracts\Translation\TranslatorInterface',
'setLocale',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration('Symfony\Contracts\Translation\TranslatorInterface', 'trans', 0, '?string'),
new AddParamTypeDeclaration('Symfony\Contracts\Translation\TranslatorInterface', 'trans', 2, 'string'),
new AddParamTypeDeclaration('Symfony\Contracts\Translation\TranslatorInterface', 'trans', 3, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\AbstractExtension', 'getType', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\AbstractExtension', 'hasType', 0, 'string'),
new AddParamTypeDeclaration(
'Symfony\Contracts\Translation\TranslatorInterface',
'trans',
0,
new UnionType([new StringType(), new NullType()])
),
new AddParamTypeDeclaration(
'Symfony\Contracts\Translation\TranslatorInterface',
'trans',
2,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Contracts\Translation\TranslatorInterface',
'trans',
3,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Form\AbstractExtension', 'getType', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Form\AbstractExtension', 'hasType', 0, new StringType()),
new AddParamTypeDeclaration(
'Symfony\Component\Form\AbstractExtension',
'getTypeExtensions',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Form\AbstractExtension',
'hasTypeExtensions',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Form\DataMapperInterface',
'mapFormsToData',
0,
'iterable'
$iterableType
),
new AddParamTypeDeclaration(
'Symfony\Component\Form\DataMapperInterface',
'mapDataToForms',
1,
'iterable'
$iterableType
),
new AddParamTypeDeclaration('Symfony\Component\Form\Form', 'add', 1, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\Form', 'remove', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\Form', 'has', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\Form', 'get', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'add', 1, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'create', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'create', 1, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'get', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'remove', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'has', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\Form', 'add', 1, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Form\Form', 'remove', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Form\Form', 'has', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Form\Form', 'get', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'add', 1, new StringType()),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormBuilderInterface',
'create',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormBuilderInterface',
'create',
1,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'get', 0, new StringType()),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormBuilderInterface',
'remove',
0,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Form\FormBuilderInterface', 'has', 0, new StringType()),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormExtensionInterface',
'getTypeExtensions',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormExtensionInterface',
'hasTypeExtensions',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'create', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createNamed', 0, new StringType()),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createNamed', 1, new StringType()),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormFactory',
'createForProperty',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormFactory',
'createForProperty',
1,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createBuilder', 0, new StringType()),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormFactory',
'createNamedBuilder',
0,
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormFactory',
'createNamedBuilder',
1,
new StringType()
),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'create', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createNamed', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createNamed', 1, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createForProperty', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createForProperty', 1, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createBuilder', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createNamedBuilder', 0, 'string'),
new AddParamTypeDeclaration('Symfony\Component\Form\FormFactory', 'createNamedBuilder', 1, 'string'),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormFactory',
'createBuilderForProperty',
0,
'string'
new StringType()
),
new AddParamTypeDeclaration(
'Symfony\Component\Form\FormFactory',
'createBuilderForProperty',
1,
'string'
new StringType()
), ]
),
]]);

View File

@ -22,7 +22,7 @@
- [DowngradePhp74](#downgradephp74) (7)
- [DowngradePhp80](#downgradephp80) (6)
- [FileSystemRector](#filesystemrector) (1)
- [Generic](#generic) (35)
- [Generic](#generic) (34)
- [JMS](#jms) (2)
- [Laravel](#laravel) (3)
- [Legacy](#legacy) (4)
@ -73,7 +73,7 @@
- [SymfonyPhpConfig](#symfonyphpconfig) (3)
- [Transform](#transform) (12)
- [Twig](#twig) (1)
- [TypeDeclaration](#typedeclaration) (9)
- [TypeDeclaration](#typedeclaration) (10)
## Architecture
@ -310,10 +310,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(ArrayToFluentCallRector::class)
->call('configure', [[
ArrayToFluentCallRector::ARRAYS_TO_FLUENT_CALLS => inline_value_objects([new ArrayToFluentCall('ArticlesTable', [
'foreignKey' => 'setForeignKey',
'propertyName' => 'setProperty',
])]),
ArrayToFluentCallRector::ARRAYS_TO_FLUENT_CALLS => inline_value_objects([
new ArrayToFluentCall('ArticlesTable', ['setForeignKey', 'setProperty']), ]
),
]]);
};
```
@ -5784,49 +5783,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
<br><br>
### `AddReturnTypeDeclarationRector`
- class: [`Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector`](/rules/generic/src/Rector/ClassMethod/AddReturnTypeDeclarationRector.php)
- [test fixtures](/rules/generic/tests/Rector/ClassMethod/AddReturnTypeDeclarationRector/Fixture)
Changes defined return typehint of method and class.
```php
<?php
declare(strict_types=1);
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration('SomeClass', 'getData', 'array'),
]),
]]);
};
```
```diff
class SomeClass
{
- public getData()
+ public getData(): array
{
}
}
```
<br><br>
### `AnnotatedPropertyInjectToConstructorInjectionRector`
- class: [`Rector\Generic\Rector\Property\AnnotatedPropertyInjectToConstructorInjectionRector`](/rules/generic/src/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector.php)
@ -16280,6 +16236,7 @@ Add param types where needed
declare(strict_types=1);
use PHPStan\Type\StringType;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
@ -16291,7 +16248,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(AddParamTypeDeclarationRector::class)
->call('configure', [[
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => inline_value_objects([
new AddParamTypeDeclaration('SomeClass', 'process', 0, 'string'),
new AddParamTypeDeclaration('SomeClass', 'process', 0, new StringType()),
]),
]]);
};
@ -16311,6 +16268,54 @@ return static function (ContainerConfigurator $containerConfigurator): void {
<br><br>
### `AddReturnTypeDeclarationRector`
- class: [`Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector`](/rules/type-declaration/src/Rector/ClassMethod/AddReturnTypeDeclarationRector.php)
- [test fixtures](/rules/type-declaration/tests/Rector/ClassMethod/AddReturnTypeDeclarationRector/Fixture)
Changes defined return typehint of method and class.
```php
<?php
declare(strict_types=1);
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(AddReturnTypeDeclarationRector::class)
->call('configure', [[
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => inline_value_objects([
new AddReturnTypeDeclaration('SomeClass', 'getData', new ArrayType(new MixedType(false, null), new MixedType(
false,
null
))),
]),
]]);
};
```
```diff
class SomeClass
{
- public getData()
+ public getData(): array
{
}
}
```
<br><br>
### `CompleteVarDocTypePropertyRector`
- class: [`Rector\TypeDeclaration\Rector\Property\CompleteVarDocTypePropertyRector`](/rules/type-declaration/src/Rector/Property/CompleteVarDocTypePropertyRector.php)

View File

@ -1,50 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\StaticTypeMapper\Mapper;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\NullableType;
use Rector\Core\Exception\NotImplementedException;
final class StringTypeToPhpParserNodeMapper
{
/**
* @var string[]
*/
private const SAME_NAMED_IDENTIFIERS = ['string', 'int', 'float', 'array', 'void', 'bool'];
/**
* @return Identifier|Name|NullableType
*/
public function map(string $type): Node
{
foreach (self::SAME_NAMED_IDENTIFIERS as $sameNamedIdentifier) {
if ($type !== $sameNamedIdentifier) {
continue;
}
return new Identifier($sameNamedIdentifier);
}
if (Strings::contains($type, '\\') || ctype_upper($type[0])) {
return new FullyQualified($type);
}
if (Strings::startsWith($type, '?')) {
$nullableType = ltrim($type, '?');
/** @var Identifier|Name $nameNode */
$nameNode = $this->map($nullableType);
return new NullableType($nameNode);
}
throw new NotImplementedException(sprintf('%s for "%s"', __METHOD__, $type));
}
}

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\StaticTypeMapper;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\UnionType as PhpParserUnionType;
@ -19,7 +18,6 @@ use PHPStan\Type\Type;
use Rector\Core\Exception\NotImplementedException;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper;
use Rector\StaticTypeMapper\Mapper\StringTypeToPhpParserNodeMapper;
use Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper;
use Rector\StaticTypeMapper\PHPStan\NameScopeFactory;
@ -44,11 +42,6 @@ final class StaticTypeMapper
*/
private $phpDocTypeMapper;
/**
* @var StringTypeToPhpParserNodeMapper
*/
private $stringTypeToPhpParserNodeMapper;
/**
* @var NameScopeFactory
*/
@ -58,13 +51,11 @@ final class StaticTypeMapper
NameScopeFactory $nameScopeFactory,
PHPStanStaticTypeMapper $phpStanStaticTypeMapper,
PhpDocTypeMapper $phpDocTypeMapper,
PhpParserNodeMapper $phpParserNodeMapper,
StringTypeToPhpParserNodeMapper $stringTypeToPhpParserNodeMapper
PhpParserNodeMapper $phpParserNodeMapper
) {
$this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper;
$this->phpParserNodeMapper = $phpParserNodeMapper;
$this->phpDocTypeMapper = $phpDocTypeMapper;
$this->stringTypeToPhpParserNodeMapper = $stringTypeToPhpParserNodeMapper;
$this->nameScopeFactory = $nameScopeFactory;
}
@ -104,14 +95,6 @@ final class StaticTypeMapper
throw new NotImplementedException(__METHOD__ . ' for ' . get_class($phpDocTagValueNode));
}
/**
* @return Identifier|Name|NullableType
*/
public function mapStringToPhpParserNode(string $type): Node
{
return $this->stringTypeToPhpParserNodeMapper->map($type);
}
public function mapPHPStanPhpDocTypeNodeToPhpDocString(TypeNode $typeNode, Node $node): string
{
$phpStanType = $this->mapPHPStanPhpDocTypeNodeToPHPStanType($typeNode, $node);

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Rector\SymfonyPhpConfig;
use Rector\SymfonyPhpConfig\Exception\ValueObjectException;
use Rector\SymfonyPhpConfig\Reflection\ArgumentAndParameterFactory;
use ReflectionClass;
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline;
@ -15,7 +14,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigura
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
function inline_single_object(object $object, ServicesConfigurator $servicesConfigurator): ReferenceConfigurator
function inline_argument_object(object $object, ServicesConfigurator $servicesConfigurator): ReferenceConfigurator
{
$reflectionClass = new ReflectionClass($object);
@ -41,15 +40,19 @@ function inline_value_object(object $object): InlineServiceConfigurator
$className = $reflectionClass->getName();
$argumentValues = resolve_argument_values($reflectionClass, $object);
// Symfony 5.1+
if (function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\inline_service')) {
return inline_service($className)
->args($argumentValues);
// Symfony 5.1+
$inlineServiceConfigurator = inline_service($className);
} else {
// Symfony 5.0-
$inlineServiceConfigurator = inline($className);
}
// Symfony 5.0-
return inline($className)
->args($argumentValues);
if ($argumentValues !== []) {
$inlineServiceConfigurator->args($argumentValues);
}
return $inlineServiceConfigurator;
}
/**
@ -75,11 +78,8 @@ function resolve_argument_values(ReflectionClass $reflectionClass, object $objec
$constructorMethodReflection = $reflectionClass->getConstructor();
if ($constructorMethodReflection === null) {
$message = sprintf(
'Constructor for "%s" was not found. Be sure to use only value objects',
$reflectionClass->getName()
);
throw new ValueObjectException($message);
// value object without constructor
return [];
}
foreach ($constructorMethodReflection->getParameters() as $reflectionParameter) {
@ -87,7 +87,17 @@ function resolve_argument_values(ReflectionClass $reflectionClass, object $objec
$propertyReflection = $reflectionClass->getProperty($parameterName);
$propertyReflection->setAccessible(true);
$argumentValues[] = $propertyReflection->getValue($object);
$resolvedValue = $propertyReflection->getValue($object);
if (is_array($resolvedValue)) {
foreach ($resolvedValue as $key => $value) {
if (is_object($value)) {
$resolvedValue[$key] = inline_value_object($value);
}
}
}
$argumentValues[] = is_object($resolvedValue) ? inline_value_object($resolvedValue) : $resolvedValue;
}
return $argumentValues;

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Tests\Functions;
use PHPStan\Type\UnionType;
use Rector\Core\HttpKernel\RectorKernel;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\ServiceWithValueObject;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\WithType;
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
final class ConfigFactoryNestedTest extends AbstractKernelTestCase
{
protected function setUp(): void
{
self::bootKernelWithConfigs(RectorKernel::class, [
__DIR__ . '/config/config_with_nested_union_type_value_objects.php',
]);
}
public function testInlineValueObjectFunction(): void
{
/** @var ServiceWithValueObject $serviceWithValueObject */
$serviceWithValueObject = self::$container->get(ServiceWithValueObject::class);
$withType = $serviceWithValueObject->getWithType();
$this->assertInstanceOf(WithType::class, $withType);
$this->assertInstanceOf(UnionType::class, $withType->getType());
}
}

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Tests\Functions;
use PHPStan\Type\IntegerType;
use PHPStan\Type\StringType;
use Rector\Core\HttpKernel\RectorKernel;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\ServiceWithValueObject;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\WithType;
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
final class ConfigFactoryTest extends AbstractKernelTestCase
{
protected function setUp(): void
{
self::bootKernelWithConfigs(RectorKernel::class, [
__DIR__ . '/config/config_with_nested_value_objects.php',
]);
}
public function testInlineValueObjectFunction(): void
{
/** @var ServiceWithValueObject $serviceWithValueObject */
$serviceWithValueObject = self::$container->get(ServiceWithValueObject::class);
$withType = $serviceWithValueObject->getWithType();
$this->assertInstanceOf(WithType::class, $withType);
$this->assertInstanceOf(IntegerType::class, $withType->getType());
}
public function testInlineValueObjectsFunction(): void
{
/** @var ServiceWithValueObject $serviceWithValueObject */
$serviceWithValueObject = self::$container->get(ServiceWithValueObject::class);
$withTypes = $serviceWithValueObject->getWithTypes();
$this->assertCount(1, $withTypes);
$singleWithType = $withTypes[0];
$this->assertInstanceOf(WithType::class, $singleWithType);
$this->assertInstanceOf(StringType::class, $singleWithType->getType());
}
}

View File

@ -4,8 +4,9 @@ declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Tests\Functions;
use Iterator;
use PHPUnit\Framework\TestCase;
use function Rector\SymfonyPhpConfig\inline_single_object;
use function Rector\SymfonyPhpConfig\inline_argument_object;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\SomeValueObject;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -13,19 +14,27 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigura
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
final class InlineValueObjectTest extends TestCase
final class InlineSingleObjectTest extends TestCase
{
public function test(): void
/**
* @dataProvider provideData()
*/
public function test(object $valueObject, string $expectedType): void
{
$servicesConfigurator = $this->createServiceConfigurator();
$someValueObject = new SomeValueObject('Rector');
$referenceConfigurator = inline_single_object($someValueObject, $servicesConfigurator);
$referenceConfigurator = inline_argument_object($valueObject, $servicesConfigurator);
$this->assertInstanceOf(ReferenceConfigurator::class, $referenceConfigurator);
$id = (string) $referenceConfigurator;
$this->assertSame(SomeValueObject::class, $id);
$this->assertSame($expectedType, $id);
}
public function provideData(): Iterator
{
yield [new SomeValueObject('Rector'), SomeValueObject::class];
// yield [new WithType(new StringType()), WithType::class];
}
private function createServiceConfigurator(): ServicesConfigurator

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Tests\Functions\Source;
final class ServiceWithValueObject
{
/**
* @var WithType
*/
private $withType;
/**
* @var WithType[]
*/
private $withTypes = [];
public function setWithType(WithType $withType): void
{
$this->withType = $withType;
}
public function getWithType(): WithType
{
return $this->withType;
}
/**
* @param WithType[] $withTypes
*/
public function setWithTypes(array $withTypes): void
{
$this->withTypes = $withTypes;
}
/**
* @return WithType[]
*/
public function getWithTypes(): array
{
return $this->withTypes;
}
}

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Tests\Functions\Source;
use PHPStan\Type\Type;
final class WithType
{
/**
* @var Type
*/
private $type;
public function __construct(Type $type)
{
$this->type = $type;
}
public function getType(): Type
{
return $this->type;
}
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Tests\Functions\config;
use PHPStan\Type\NullType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
use function Rector\SymfonyPhpConfig\inline_value_object;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\ServiceWithValueObject;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\WithType;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->defaults()
->public()
->autowire()
->autoconfigure();
$unionType = new UnionType([new StringType(), new NullType()]);
$services->set(ServiceWithValueObject::class)
->call('setWithType', [inline_value_object(new WithType($unionType))]);
};

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Rector\SymfonyPhpConfig\Tests\Functions\config;
use PHPStan\Type\IntegerType;
use PHPStan\Type\StringType;
use function Rector\SymfonyPhpConfig\inline_value_object;
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\ServiceWithValueObject;
use Rector\SymfonyPhpConfig\Tests\Functions\Source\WithType;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->defaults()
->public()
->autowire()
->autoconfigure();
$withType = new WithType(new IntegerType());
$services->set(ServiceWithValueObject::class)
->call('setWithType', [inline_value_object($withType)])
->call('setWithTypes', [inline_value_objects([new WithType(new StringType())])]);
};

View File

@ -680,3 +680,7 @@ parameters:
- packages/better-php-doc-parser/src/PartPhpDocTagPrinter/Behavior/ArrayPartPhpDocTagPrinterTrait.php # 70
- packages/better-php-doc-parser/src/PhpDocNode/PrintTagValueNodeTrait.php # 54
# allow in new <types> config
-
message: '#new <class\> is limited to 3 "new <class\>\(new <class\>\)\)" nesting to each other\. You have \d+ nesting#'
path: config/set/*

View File

@ -6,7 +6,7 @@ use PhpParser\Node\Expr\MethodCall;
use Rector\RectorGenerator\Provider\RectorRecipeProvider;
use Rector\RectorGenerator\ValueObject\RectorRecipe;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Rector\SymfonyPhpConfig\inline_single_object;
use function Rector\SymfonyPhpConfig\inline_argument_object;
// run "bin/rector generate" to a new Rector basic schema + tests from this config
return static function (ContainerConfigurator $containerConfigurator): void {
@ -78,5 +78,5 @@ CODE_SAMPLE
$services = $containerConfigurator->services();
$services->set(RectorRecipeProvider::class)
->arg('$rectorRecipe', inline_single_object($rectorRecipe, $services));
->arg('$rectorRecipe', inline_argument_object($rectorRecipe, $services));
};

View File

@ -1,62 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Generic\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\Generic\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use Symplify\SmartFileSystem\SmartFileInfo;
final class AddReturnTypeDeclarationRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
/**
* @return array<string, mixed[]>
*/
protected function getRectorsWithConfiguration(): array
{
return [
AddReturnTypeDeclarationRector::class => [
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => [
new AddReturnTypeDeclaration(
'Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture\SomeClass',
'parse',
'array'
),
new AddReturnTypeDeclaration(
'Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture\SomeClass',
'resolve',
'SomeType'
),
new AddReturnTypeDeclaration(
'Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture\SomeClass',
'nullable',
'?SomeType'
),
new AddReturnTypeDeclaration(
'Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture\RemoveReturnType',
'clear',
''
),
new AddReturnTypeDeclaration(PHPUnitTestCase::class, 'tearDown', 'void'),
],
],
];
}
}

View File

@ -1,25 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture;
class RemoveReturnType
{
public function clear(): array
{
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture;
class RemoveReturnType
{
public function clear()
{
}
}
?>

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source;
abstract class PHPUnitTestCase
{
}

View File

@ -11,11 +11,14 @@ use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Trait_;
use PHPStan\Type\MixedType;
use PHPStan\Type\StringType;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\TypeComparator;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Webmozart\Assert\Assert;
@ -34,6 +37,16 @@ final class AddParamTypeDeclarationRector extends AbstractRector implements Conf
*/
private $parameterTypehints = [];
/**
* @var TypeComparator
*/
private $typeComparator;
public function __construct(TypeComparator $typeComparator)
{
$this->typeComparator = $typeComparator;
}
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Add param types where needed', [
@ -56,7 +69,7 @@ class SomeClass
}
CODE_SAMPLE
, [
self::PARAMETER_TYPEHINTS => [new AddParamTypeDeclaration('SomeClass', 'process', 0, 'string')],
self::PARAMETER_TYPEHINTS => [new AddParamTypeDeclaration('SomeClass', 'process', 0, new StringType())],
]),
]);
}
@ -96,6 +109,9 @@ CODE_SAMPLE
return $node;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$parameterTypehints = $configuration[self::PARAMETER_TYPEHINTS] ?? [];
@ -154,17 +170,23 @@ CODE_SAMPLE
private function refactorParameter(Param $param, AddParamTypeDeclaration $addParamTypeDeclaration): void
{
// already set → no change
if ($param->type && $this->isName($param->type, $addParamTypeDeclaration->getTypehint())) {
return;
if ($param->type !== null) {
$currentParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
if ($this->typeComparator->areTypesEquals($currentParamType, $addParamTypeDeclaration->getParamType())) {
return;
}
}
// remove it
if ($addParamTypeDeclaration->getTypehint() === '') {
if ($addParamTypeDeclaration->getParamType() instanceof MixedType) {
$param->type = null;
return;
}
$returnTypeNode = $this->staticTypeMapper->mapStringToPhpParserNode($addParamTypeDeclaration->getTypehint());
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode(
$addParamTypeDeclaration->getParamType()
);
$param->type = $returnTypeNode;
}
}

View File

@ -2,19 +2,23 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\ClassMethod;
namespace Rector\TypeDeclaration\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\ConfiguredCodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\Generic\ValueObject\AddReturnTypeDeclaration;
use Rector\NodeTypeResolver\PHPStan\TypeComparator;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\AddReturnTypeDeclarationRectorTest
* @see \Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\AddReturnTypeDeclarationRectorTest
*/
final class AddReturnTypeDeclarationRector extends AbstractRector implements ConfigurableRectorInterface
{
@ -28,6 +32,16 @@ final class AddReturnTypeDeclarationRector extends AbstractRector implements Con
*/
private $methodReturnTypes = [];
/**
* @var TypeComparator
*/
private $typeComparator;
public function __construct(TypeComparator $typeComparator)
{
$this->typeComparator = $typeComparator;
}
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Changes defined return typehint of method and class.', [
@ -51,7 +65,12 @@ class SomeClass
CODE_SAMPLE
,
[
self::METHOD_RETURN_TYPES => [new AddReturnTypeDeclaration('SomeClass', 'getData', 'array')],
self::METHOD_RETURN_TYPES => [
new AddReturnTypeDeclaration('SomeClass', 'getData', new ArrayType(
new MixedType(),
new MixedType()
)),
],
]
),
]);
@ -95,20 +114,23 @@ CODE_SAMPLE
$this->methodReturnTypes = $methodReturnTypes;
}
private function processClassMethodNodeWithTypehints(ClassMethod $classMethod, string $newType): void
private function processClassMethodNodeWithTypehints(ClassMethod $classMethod, Type $newType): void
{
// remove it
if ($newType === '') {
if ($newType instanceof MixedType) {
$classMethod->returnType = null;
return;
}
// already set → no change
if ($classMethod->returnType && $this->isName($classMethod->returnType, $newType)) {
return;
if ($classMethod->returnType !== null) {
$currentReturnType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($classMethod->returnType);
if ($this->typeComparator->areTypesEquals($currentReturnType, $newType)) {
return;
}
}
$returnTypeNode = $this->staticTypeMapper->mapStringToPhpParserNode($newType);
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($newType);
$classMethod->returnType = $returnTypeNode;
}
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Rector\TypeDeclaration\ValueObject;
use PHPStan\Type\Type;
final class AddParamTypeDeclaration
{
/**
@ -22,16 +24,16 @@ final class AddParamTypeDeclaration
private $position;
/**
* @var string
* @var Type
*/
private $typehint;
private $paramType;
public function __construct(string $className, string $methodName, int $position, string $typehint)
public function __construct(string $className, string $methodName, int $position, Type $paramType)
{
$this->className = $className;
$this->methodName = $methodName;
$this->position = $position;
$this->typehint = $typehint;
$this->paramType = $paramType;
}
public function getClassName(): string
@ -49,8 +51,8 @@ final class AddParamTypeDeclaration
return $this->position;
}
public function getTypehint(): string
public function getParamType(): Type
{
return $this->typehint;
return $this->paramType;
}
}

View File

@ -2,7 +2,9 @@
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
namespace Rector\TypeDeclaration\ValueObject;
use PHPStan\Type\Type;
final class AddReturnTypeDeclaration
{
@ -17,11 +19,11 @@ final class AddReturnTypeDeclaration
private $method;
/**
* @var string
* @var Type
*/
private $returnType;
public function __construct(string $class, string $method, string $returnType)
public function __construct(string $class, string $method, Type $returnType)
{
$this->class = $class;
$this->method = $method;
@ -38,7 +40,7 @@ final class AddReturnTypeDeclaration
return $this->method;
}
public function getReturnType(): string
public function getReturnType(): Type
{
return $this->returnType;
}

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Iterator;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddParamTypeDeclarationRector\Source\ClassMetadataFactory;
@ -35,13 +37,18 @@ final class AddParamTypeDeclarationRectorTest extends AbstractRectorTestCase
return [
AddParamTypeDeclarationRector::class => [
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => [
new AddParamTypeDeclaration(ParentInterfaceWithChangeTypeInterface::class, 'process', 0, 'string'),
new AddParamTypeDeclaration(ParserInterface::class, 'parse', 0, 'string'),
new AddParamTypeDeclaration(
ParentInterfaceWithChangeTypeInterface::class,
'process',
0,
new StringType()
),
new AddParamTypeDeclaration(ParserInterface::class, 'parse', 0, new StringType()),
new AddParamTypeDeclaration(
ClassMetadataFactory::class,
'setEntityManager',
0,
'Doctrine\ORM\EntityManagerInterface'
new ObjectType('Doctrine\ORM\EntityManagerInterface')
),
],
],

View File

@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Iterator;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Symplify\SmartFileSystem\SmartFileInfo;
final class AddReturnTypeDeclarationRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
/**
* @return array<string, mixed[]>
*/
protected function getRectorsWithConfiguration(): array
{
$arrayType = new ArrayType(new MixedType(), new MixedType());
$nullableObjectUnionType = new UnionType([new ObjectType('SomeType'), new NullType()]);
return [
AddReturnTypeDeclarationRector::class => [
AddReturnTypeDeclarationRector::METHOD_RETURN_TYPES => [
new AddReturnTypeDeclaration(
'Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture\SomeClass',
'parse',
$arrayType
),
new AddReturnTypeDeclaration(
'Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture\SomeClass',
'resolve',
new ObjectType('SomeType')
),
new AddReturnTypeDeclaration(
'Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture\SomeClass',
'nullable',
$nullableObjectUnionType
),
new AddReturnTypeDeclaration(
'Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture\RemoveReturnType',
'clear',
new MixedType()
),
new AddReturnTypeDeclaration(PHPUnitTestCase::class, 'tearDown', new VoidType()),
],
],
];
}
}

View File

@ -1,7 +1,7 @@
<?php
namespace {
use Rector\Generic\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
abstract class Abstract_Test_Case extends PHPUnitTestCase
{
@ -11,7 +11,7 @@ namespace {
}
}
namespace Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture
{
final class FinalTestCase extends \Abstract_Test_Case
{
@ -26,7 +26,7 @@ namespace Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fi
<?php
namespace {
use Rector\Generic\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
use Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source\PHPUnitTestCase;
abstract class Abstract_Test_Case extends PHPUnitTestCase
{
@ -36,7 +36,7 @@ namespace {
}
}
namespace Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture
{
final class FinalTestCase extends \Abstract_Test_Case
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture;
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture;
class SomeClass
{
@ -21,7 +21,7 @@ class SomeClass
-----
<?php
namespace Rector\Generic\Tests\Rector\Typehint\AddReturnTypeDeclarationRector\Fixture;
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture;
class SomeClass
{

View File

@ -0,0 +1,25 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture;
class RemoveReturnType
{
public function clear(): array
{
}
}
?>
-----
<?php
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Fixture;
class RemoveReturnType
{
public function clear()
{
}
}
?>

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddReturnTypeDeclarationRector\Source;
abstract class PHPUnitTestCase
{
}