Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"require": {
"php": ">=7.4",
"illuminate/support": "^8.83 || ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0",
"rector/rector": "^2.3",
"rector/rector": "^2.4.1",
"symfony/polyfill-php80": "^1.33",
"symfony/polyfill-php81": "^1.33",
"webmozart/assert": "^1.12 || ^2.0"
Expand Down
2 changes: 0 additions & 2 deletions rector.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
Expand Down Expand Up @@ -120,7 +119,6 @@
EnumCaseToPascalCaseRector::class,
GeneratorPropertyFetchToMethodCallRector::class,
JsonThrowOnErrorRector::class,
SafeDeclareStrictTypesRector::class,
SortAssociativeArrayByKeyRector::class,
StaticArrowFunctionRector::class,
StaticClosureRector::class,
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/RectorErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

/**
* @see \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
*
* @property \Rector\ValueObject\Application\File $file
*/
final class RectorErrorException extends Error implements ThrowableContract
{
Expand All @@ -35,7 +33,7 @@ public function __construct(AbstractRector $rector, string $message, array $attr
\sprintf(
'[%s:%s%s] %s',
(new \ReflectionObject($rector))->getShortName(),
(string) Str::of((fn (): string => $this->file->getFilePath())->bindTo($rector, $rector)())
(string) Str::of((fn (): string => $this->getFile()->getFilePath())->bindTo($rector, $rector)()) // @phpstan-ignore method.nonObject
// ->chopStart(getcwd().\DIRECTORY_SEPARATOR)
// ->replaceStart(getcwd().\DIRECTORY_SEPARATOR, '')
->whenStartsWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ private function getInspections(): array
/** @var array<non-empty-string, list<string>> $inspectionsMap */
static $inspectionsMap = [];

$inspectionsMap[$this->file->getFilePath()] ??= collect($this->inspectionsMap)
->filter(fn (array $_, string $path) => Str::is($path, $this->file->getFilePath()))
$inspectionsMap[$this->getFile()->getFilePath()] ??= collect($this->inspectionsMap)
->filter(fn (array $_, string $path) => Str::is($path, $this->getFile()->getFilePath()))
// ->flatten()
->collapse()
->unique()
Expand All @@ -167,6 +167,6 @@ private function getInspections(): array
// ->dd()
->all();

return $inspectionsMap[$this->file->getFilePath()];
return $inspectionsMap[$this->getFile()->getFilePath()];
}
}
16 changes: 8 additions & 8 deletions src/Rector/File/SortFileFunctionStmtRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$rootNode = collect($node->stmts)->first(
$stmt = collect($node->stmts)->first(
static fn (Stmt $stmtNode): bool => $stmtNode instanceof Namespace_,
$node
);
\assert($rootNode instanceof FileNode || $rootNode instanceof Namespace_);
\assert($stmt instanceof FileNode || $stmt instanceof Namespace_);

if (
collect($rootNode->stmts)->containsStrict(
collect($stmt->stmts)->containsStrict(
static fn (Stmt $stmtNode): bool => $stmtNode instanceof ClassLike
)
|| !collect($rootNode->stmts)->containsStrict(
|| !collect($stmt->stmts)->containsStrict(
static fn (Stmt $stmtNode): bool => $stmtNode instanceof Function_ || $stmtNode instanceof If_
)
|| !collect($rootNode->stmts)->containsStrict(
|| !collect($stmt->stmts)->containsStrict(
fn (Stmt $stmtNode): ?string => $this->parseFuncName($stmtNode)
)
|| collect($rootNode->stmts)
|| collect($stmt->stmts)
->map(fn (Stmt $stmtNode): ?string => $this->parseFuncName($stmtNode))
->filter()
->pipe(static fn (Collection $funcNames): bool => $funcNames->all() === $funcNames->sort()->all())
Expand All @@ -82,7 +82,7 @@ public function refactor(Node $node): ?Node
}

/** @var list<Stmt> $sortedStmts */
$sortedStmts = collect($rootNode->stmts)
$sortedStmts = collect($stmt->stmts)
->sort(
fn (Stmt $a, Stmt $b): int => ($aName = $this->parseFuncName($a)) && ($bName = $this->parseFuncName($b))
? $aName <=> $bName
Expand All @@ -107,7 +107,7 @@ static function (Collection $stmtNodes, Stmt $stmtNode): Collection {
// return null;
// }

$rootNode->stmts = $sortedStmts;
$stmt->stmts = $sortedStmts;

return $node;
}
Expand Down
Loading