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
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
"stan": "@phpstan",
"stan-baseline": "tools/phpstan --generate-baseline",
"stan-setup": "phive install",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.3.1\" && mv composer.backup composer.json",
"rector-check": "vendor/bin/rector process --dry-run",
"rector-fix": "vendor/bin/rector process",
"test": "phpunit",
"test-coverage": "phpunit --coverage-clover=clover.xml"
}
Expand Down
81 changes: 81 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector;
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php80\Rector\Class_\StringableForToStringRector;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictFluentReturnRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
use Rector\TypeDeclaration\Rector\Function_\AddFunctionVoidReturnTypeWhereNoReturnRector;

$cacheDir = getenv('RECTOR_CACHE_DIR') ?: sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'rector';

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])

->withCache(
cacheClass: FileCacheStorage::class,
cacheDirectory: $cacheDir,
)

->withPhpSets()
->withAttributesSets()

->withSets([
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::DEAD_CODE,
SetList::EARLY_RETURN,
SetList::INSTANCEOF,
SetList::TYPE_DECLARATION,
])

->withSkip([
__DIR__ . '/tests/comparisons',
__DIR__ . '/tests/test_app',

ClassPropertyAssignToConstructorPromotionRector::class,
CatchExceptionNameMatchingTypeRector::class,
ClosureToArrowFunctionRector::class,
RemoveUselessReturnTagRector::class,
ReturnTypeFromStrictFluentReturnRector::class,
NewlineAfterStatementRector::class,
StringClassNameToClassConstantRector::class,
ReturnTypeFromStrictTypedCallRector::class,
ParamTypeByMethodCallTypeRector::class,
AddFunctionVoidReturnTypeWhereNoReturnRector::class,
StringableForToStringRector::class,
CompactToVariablesRector::class,
SplitDoubleAssignRector::class,
ChangeOrIfContinueToMultiContinueRector::class,
ExplicitBoolCompareRector::class,
NewlineBeforeNewAssignSetRector::class,
SimplifyEmptyCheckOnEmptyArrayRector::class,
DisallowedEmptyRuleFixerRector::class,
EncapsedStringsToSprintfRector::class,

// these causes problems with the testsuite
UseClassKeywordForClassNameResolutionRector::class,
FunctionFirstClassCallableRector::class,
]);
8 changes: 2 additions & 6 deletions src/BakePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ class BakePlugin extends BasePlugin
{
/**
* Plugin name.
*
* @var string|null
*/
protected ?string $name = 'Bake';

/**
* Load routes or not
*
* @var bool
*/
protected bool $routesEnabled = false;

Expand Down Expand Up @@ -95,13 +91,13 @@ protected function discoverCommands(CommandCollection $commands): CommandCollect
$pluginPath = $plugin->getClassPath();

$found = $this->findInPath($namespace, $pluginPath);
if (count($found)) {
if ($found !== []) {
$commands->addMany($found);
}
}

$found = $this->findInPath(Configure::read('App.namespace'), APP);
if (count($found)) {
if ($found !== []) {
$commands->addMany($found);
}

Expand Down
9 changes: 3 additions & 6 deletions src/CodeGen/ClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

class ClassBuilder
{
/**
* @var \Bake\CodeGen\ParsedClass|null
*/
protected ?ParsedClass $parsedClass;

/**
Expand Down Expand Up @@ -50,7 +47,7 @@ public function getImplements(array $generated = []): array
*/
public function getUserConstants(array $generated = []): array
{
if ($this->parsedClass === null) {
if (!$this->parsedClass instanceof ParsedClass) {
return [];
}

Expand All @@ -65,7 +62,7 @@ public function getUserConstants(array $generated = []): array
*/
public function getUserProperties(array $generated = []): array
{
if ($this->parsedClass === null) {
if (!$this->parsedClass instanceof ParsedClass) {
return [];
}

Expand All @@ -80,7 +77,7 @@ public function getUserProperties(array $generated = []): array
*/
public function getUserFunctions(array $generated = []): array
{
if ($this->parsedClass === null) {
if (!$this->parsedClass instanceof ParsedClass) {
return [];
}

Expand Down
27 changes: 6 additions & 21 deletions src/CodeGen/CodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

use PhpParser\Error;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Namespace_;
Expand All @@ -41,24 +43,12 @@ class CodeParser extends NodeVisitorAbstract
*/
protected const INDENT = ' ';

/**
* @var \PhpParser\Parser
*/
protected Parser $parser;

/**
* @var \PhpParser\NodeTraverser
*/
protected NodeTraverser $traverser;

/**
* @var string
*/
protected string $fileText = '';

/**
* @var array
*/
protected array $parsed = [];

/**
Expand Down Expand Up @@ -204,7 +194,7 @@ public function enterNode(Node $node)
$methods[$name] = $this->getNodeCode($method);
}

$implements = array_map(function ($name) {
$implements = array_map(function (Name $name): string {
return (string)$name;
}, $node->implements);

Expand Down Expand Up @@ -237,9 +227,8 @@ protected function getNodeCode(NodeAbstract $node): string

$startPos = $node->getStartFilePos();
$endPos = $node->getEndFilePos();
$code .= static::INDENT . substr($this->fileText, $startPos, $endPos - $startPos + 1);

return $code;
return $code . static::INDENT . substr($this->fileText, $startPos, $endPos - $startPos + 1);
}

/**
Expand All @@ -255,13 +244,9 @@ protected function normalizeUse(UseItem $use, ?string $prefix = null): array
}

$alias = $use->alias;
if (!$alias) {
if (!$alias instanceof Identifier) {
$last = strrpos($name, '\\', -1);
if ($last !== false) {
$alias = substr($name, strrpos($name, '\\', -1) + 1);
} else {
$alias = $name;
}
$alias = $last !== false ? substr($name, strrpos($name, '\\', -1) + 1) : $name;
}

return [(string)$alias, $name];
Expand Down
Loading
Loading