Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfox committed Sep 21, 2024
1 parent 37fd929 commit c4e286c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
6 changes: 4 additions & 2 deletions config/sets/type-declaration/eloquent.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\FunctionLike\AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration;
use RectorLaravel\Util\AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRectorConfigGenerator;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../config.php');

$generator = new \RectorLaravel\Util\AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRectorConfigGenerator;
$generator = new AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRectorConfigGenerator;

$builderClass = new ObjectType(
'Illuminate\Contracts\Database\Query\Builder'
Expand Down Expand Up @@ -144,7 +146,7 @@
'handleLazyLoadingViolationUsing',
0,
1,
new \PHPStan\Type\StringType,
new StringType,
),
]
);
Expand Down
8 changes: 4 additions & 4 deletions config/sets/type-declaration/service-container.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@

$ruleConfiguration = [];

foreach ($classesToApplyTo as $targetClass) {
foreach ($classesToApplyTo as $classToApplyTo) {
foreach ([
'bind', 'bindIf', 'singleton', 'singletonIf', 'scoped', 'scopedIf',
] as $method) {
$ruleConfiguration[] = new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
$targetClass,
$classToApplyTo,
$method,
1,
0,
$applicationClass,
);
}
$ruleConfiguration[] = new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
$targetClass,
$classToApplyTo,
'resolving',
1,
1,
$applicationClass,
);
$ruleConfiguration[] = new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
$targetClass,
$classToApplyTo,
'extends',
1,
1,
Expand Down
31 changes: 17 additions & 14 deletions config/sets/type-declaration/validation.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\FunctionLike\AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration;
Expand All @@ -22,21 +25,21 @@
'make',
1,
0,
new \PHPStan\Type\StringType,
new StringType,
),
new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
$targetClass,
'make',
1,
1,
new \PHPStan\Type\MixedType(true),
new MixedType(true),
),
new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
$targetClass,
'make',
1,
2,
new \PHPStan\Type\ObjectType('Closure'),
new ObjectType('Closure'),
),
]
);
Expand All @@ -50,21 +53,21 @@
'validate',
0,
0,
new \PHPStan\Type\StringType,
new StringType,
),
new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
'Illuminate\Http\Request',
'validate',
0,
1,
new \PHPStan\Type\MixedType(true),
new MixedType(true),
),
new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
'Illuminate\Http\Request',
'validate',
0,
2,
new \PHPStan\Type\ObjectType('Closure'),
new ObjectType('Closure'),
),
]
);
Expand All @@ -77,7 +80,7 @@
'after',
0,
0,
new \PHPStan\Type\ObjectType('Illuminate\Contracts\Validation\Validator'),
new ObjectType('Illuminate\Contracts\Validation\Validator'),
),
]
);
Expand All @@ -90,14 +93,14 @@
'sometimes',
2,
0,
new \PHPStan\Type\ObjectType('Illuminate\Support\Fluent'),
new ObjectType('Illuminate\Support\Fluent'),
),
new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
'Illuminate\Contracts\Validation\Validator',
'sometimes',
2,
1,
new \PHPStan\Type\MixedType(true),
new MixedType(true),
),
]
);
Expand All @@ -110,14 +113,14 @@
'forEach',
0,
0,
new \PHPStan\Type\MixedType(true),
new MixedType(true),
),
new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
'Illuminate\Validation\Rule',
'forEach',
0,
1,
new \PHPStan\Type\StringType,
new StringType,
),
]
);
Expand All @@ -130,21 +133,21 @@
'where',
0,
0,
new \PHPStan\Type\ObjectType('Illuminate\Contracts\Database\Query\Builder'),
new ObjectType('Illuminate\Contracts\Database\Query\Builder'),
),
new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
'Illuminate\Validation\Rules\Exists',
'where',
1,
0,
new \PHPStan\Type\ObjectType('Illuminate\Contracts\Database\Query\Builder'),
new ObjectType('Illuminate\Contracts\Database\Query\Builder'),
),
new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
'Illuminate\Validation\Rules\Exists',
'using',
0,
0,
new \PHPStan\Type\ObjectType('Illuminate\Contracts\Database\Query\Builder'),
new ObjectType('Illuminate\Contracts\Database\Query\Builder'),
),
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,8 @@ class AddParamTypeForFunctionLikeWithinCallLikeArgArrayValuesDeclarationRector e
private $hasChanged = false;

public function __construct(
/**
* @readonly
*/
private readonly TypeComparator $typeComparator,
/**
* @readonly
*/
private readonly PhpVersionProvider $phpVersionProvider,
/**
* @readonly
*/
private readonly StaticTypeMapper $staticTypeMapper
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ public function generate(
array $targetClasses,
int $functionPosition,
string $methodName,
ObjectType $type
ObjectType $objectType
): array {
$configurations = [];

foreach ($callPositionsOrNames as $callPositionsOrName) {
foreach ($callPositionsOrNames as $callPositionOrName) {
foreach ($targetClasses as $targetClass) {
$configurations[] = new AddParamTypeForFunctionLikeWithinCallLikeArgDeclaration(
$targetClass,
$methodName,
$callPositionsOrName,
$callPositionOrName,
$functionPosition,
$type
$objectType
);
}
}
Expand Down

0 comments on commit c4e286c

Please sign in to comment.