Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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((fn (): string => $this->getFile()->getFilePath())->bindTo($rector, $rector)()) // @phpstan-ignore method.nonObject
// ->chopStart(getcwd().\DIRECTORY_SEPARATOR)
// ->replaceStart(getcwd().\DIRECTORY_SEPARATOR, '')
->whenStartsWith(
Expand Down
2 changes: 1 addition & 1 deletion src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final public function getRuleDefinition(): RuleDefinition

protected function description(): string
{
return (string) Str::of(static::class)
return (string) \str(static::class)
->afterLast('\\')
->beforeLast('Rector')
->headline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private function parseConfigFile(ClassReflection $classReflection): string
// ['/tests/', '/config/configured_rule.php'],
// $classReflection->getNativeReflection()->getFileName()
// );
return (string) Str::of($classReflection->getNativeReflection()->getName())
return (string) \str($classReflection->getNativeReflection()->getName())
->replace(['Guanguans\\RectorRules\\', '\\'], ['tests/', '/'])
->append('/config/configured_rule.php');
}
Expand All @@ -292,15 +292,15 @@ private function parseFixtureFiles(ClassReflection $classReflection): array
// $classReflection->getNativeReflection()->getFileName()
// ));
return glob(
(string) Str::of($classReflection->getNativeReflection()->getName())
(string) \str($classReflection->getNativeReflection()->getName())
->replace(['Guanguans\\RectorRules\\', '\\'], ['tests/', '/'])
->append('/Fixture/fixture.php.inc')
);
}

private function sanitizeCode(string $code): string
{
return (string) Str::of($code)
return (string) \str($code)
->trim()
->whenStartsWith($start = '<?php', static fn (Stringable $code) => $code->replaceFirst($start, ''))
->whenEndsWith($finish = '?>', static fn (Stringable $code) => $code->replaceLast($finish, ''))
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
6 changes: 3 additions & 3 deletions src/Support/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ public static function listFiles(Event $event): int
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/rector/rector/vendor/autoload.php';

classes(
static fn (string $class, string $file): bool => Str::of($class)->startsWith('Rector\\')
&& Str::of($class)->afterLast('\\')->contains([
static fn (string $class, string $file): bool => \str($class)->startsWith('Rector\\')
&& \str($class)->afterLast('\\')->contains([
'Better',
// 'Factory',
// 'Resolver',
// 'er',
// 'Renamer',
])
&& !Str::of($file)->contains([
&& !\str($file)->contains([
'/rector-doctrine/',
'/rector-downgrade-php/',
'/rector-phpunit/',
Expand Down
7 changes: 3 additions & 4 deletions tests/Rector/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final public function testRectorTestCaseClassName(): void
{
self::assertSame(
static::class,
(string) Str::of(static::rectorClass())
(string) \str(static::rectorClass())
->replace('RectorRules', 'RectorRulesTests')
->append('\\', static::rectorReflectionClass()->getShortName(), 'Test')
);
Expand All @@ -82,7 +82,6 @@ final public function testRuleDefinition(): void
* @noinspection PhpLanguageLevelInspection
* @noinspection PhpUndefinedNamespaceInspection
*/
#[\PHPUnit\Framework\Attributes\DataProvider('provideCases')]
final public function test(string $filePath): void
{
$this->doTestFile($filePath);
Expand All @@ -93,7 +92,7 @@ final public static function provideCases(): iterable
yield from self::yieldFilesFromDirectory(static::directory().'/Fixture/');

foreach ((array) glob(static::directory().'/Fixture\d*/', \GLOB_ONLYDIR) as $directory) {
if ((int) (\PHP_MAJOR_VERSION.\PHP_MINOR_VERSION) >= (int) (string) Str::of($directory)->basename()->substr(7)) {
if ((int) (\PHP_MAJOR_VERSION.\PHP_MINOR_VERSION) >= (int) (string) \str($directory)->basename()->substr(7)) {
yield from self::yieldFilesFromDirectory($directory);
}
}
Expand Down Expand Up @@ -146,7 +145,7 @@ protected static function rectorReflectionClass(): \ReflectionClass
*/
protected static function rectorClass(): string
{
return (string) Str::of((new \ReflectionClass(static::class))->getNamespaceName())->replace(
return (string) \str((new \ReflectionClass(static::class))->getNamespaceName())->replace(
'RectorRulesTests',
'RectorRules'
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
use function Guanguans\RectorRules\Support\is_subclass_of_any;

it('will throw `ReflectionException` when call classes function', function (): void {
classes(fn (string $class): bool => Str::of($class)->startsWith('Illuminate\Support'));
classes(fn (string $class): bool => \str($class)->startsWith('Illuminate\Support'));
})
->group(__DIR__, __FILE__)
->throws(ReflectionException::class);

it('can get classes', function (): void {
expect(classes(fn (string $class): bool => Str::of($class)->startsWith(Str::class)))
expect(classes(fn (string $class): bool => \str($class)->startsWith(Str::class)))
->toBeInstanceOf(Collection::class);
})->group(__DIR__, __FILE__);

Expand Down