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 @@ -76,6 +76,9 @@
"stan-setup": "phive install",
"lowest": "validate-prefer-lowest",
"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
"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
12 changes: 12 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,24 @@ parameters:
count: 1
path: src/Migration/Environment.php

-
message: '#^Method Migrations\\Migration\\Manager\:\:getMigrationClassName\(\) should return class\-string\<Migrations\\MigrationInterface\> but returns string\.$#'
identifier: return.type
count: 2
path: src/Migration/Manager.php

-
message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, array given\.$#'
identifier: argument.type
count: 1
path: src/Migration/Manager.php

-
message: '#^Parameter \#3 \$length of function substr expects int\|null, int\<0, max\>\|false given\.$#'
identifier: argument.type
count: 1
path: src/Migration/Manager.php

-
message: '#^Offset 0 on non\-empty\-list\<string\> in isset\(\) always exists and is not nullable\.$#'
identifier: isset.offset
Expand Down
54 changes: 54 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
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\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictFluentReturnRector;

$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([
ClassPropertyAssignToConstructorPromotionRector::class,
CatchExceptionNameMatchingTypeRector::class,
ClosureToArrowFunctionRector::class,
RemoveUselessReturnTagRector::class,
CompactToVariablesRector::class,
ReturnTypeFromStrictFluentReturnRector::class,
SplitDoubleAssignRector::class,
NewlineAfterStatementRector::class,
ExplicitBoolCompareRector::class,
TypedPropertyFromCreateMockAssignRector::class,
]);
35 changes: 9 additions & 26 deletions src/BaseMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,18 @@ class BaseMigration implements MigrationInterface
{
/**
* The Adapter instance
*
* @var \Migrations\Db\Adapter\AdapterInterface
*/
protected ?AdapterInterface $adapter = null;

/**
* The ConsoleIo instance
*
* @var \Cake\Console\ConsoleIo
*/
protected ?ConsoleIo $io = null;

/**
* The config instance.
*
* @var \Migrations\Config\ConfigInterface
*/
protected ?ConfigInterface $config;
protected ?ConfigInterface $config = null;

/**
* List of all the table objects created by this migration
Expand All @@ -58,15 +52,11 @@ class BaseMigration implements MigrationInterface

/**
* Is migrating up prop
*
* @var bool
*/
protected bool $isMigratingUp = true;

/**
* The version number.
*
* @var int
*/
protected int $version;

Expand All @@ -77,8 +67,6 @@ class BaseMigration implements MigrationInterface
* This option is global for all tables created in the migration file.
* If you set it to false, you have to manually add the primary keys for your
* tables using the Migrations\Table::addPrimaryKey() method
*
* @var bool
*/
public bool $autoId = true;

Expand Down Expand Up @@ -110,7 +98,7 @@ public function setAdapter(AdapterInterface $adapter)
*/
public function getAdapter(): AdapterInterface
{
if (!$this->adapter) {
if (!$this->adapter instanceof AdapterInterface) {
throw new RuntimeException('Adapter not set.');
}

Expand Down Expand Up @@ -458,18 +446,13 @@ public function index(string|array $columns): Index
*/
public function preFlightCheck(): void
{
if (method_exists($this, MigrationInterface::CHANGE)) {
if (
method_exists($this, MigrationInterface::UP) ||
method_exists($this, MigrationInterface::DOWN)
) {
$io = $this->getIo();
if ($io) {
$io->out(
'<comment>warning</comment> Migration contains both change() and up()/down() methods.' .
' <warning>Ignoring up() and down()</warning>.',
);
}
if (method_exists($this, MigrationInterface::CHANGE) && (method_exists($this, MigrationInterface::UP) || method_exists($this, MigrationInterface::DOWN))) {
$io = $this->getIo();
if ($io instanceof ConsoleIo) {
$io->out(
'<comment>warning</comment> Migration contains both change() and up()/down() methods.' .
' <warning>Ignoring up() and down()</warning>.',
);
}
}
}
Expand Down
27 changes: 6 additions & 21 deletions src/BaseSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,18 @@ class BaseSeed implements SeedInterface
{
/**
* The Adapter instance
*
* @var \Migrations\Db\Adapter\AdapterInterface
*/
protected ?AdapterInterface $adapter = null;

/**
* The ConsoleIo instance
*
* @var \Cake\Console\ConsoleIo
*/
protected ?ConsoleIo $io = null;

/**
* The config instance.
*
* @var \Migrations\Config\ConfigInterface
*/
protected ?ConfigInterface $config;

/**
* No-op constructor.
*/
public function __construct()
{
}
protected ?ConfigInterface $config = null;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -81,7 +68,7 @@ public function setAdapter(AdapterInterface $adapter)
*/
public function getAdapter(): AdapterInterface
{
if (!$this->adapter) {
if (!$this->adapter instanceof AdapterInterface) {
throw new RuntimeException('Adapter not set.');
}

Expand Down Expand Up @@ -130,10 +117,8 @@ public function setConfig(ConfigInterface $config)
public function getName(): string
{
$name = static::class;
if (str_starts_with($name, 'Migrations\BaseSeed@anonymous')) {
if (preg_match('#[/\\\\]([a-zA-Z0-9_]+)\.php:#', $name, $matches)) {
$name = $matches[1];
}
if (str_starts_with($name, 'Migrations\BaseSeed@anonymous') && preg_match('#[/\\\\](\w+)\.php:#', $name, $matches)) {
return $matches[1];
}

return $name;
Expand Down Expand Up @@ -238,7 +223,7 @@ public function isIdempotent(): bool
public function call(string $seeder, array $options = []): void
{
$io = $this->getIo();
if ($io === null) {
if (!$io instanceof ConsoleIo) {
throw new RuntimeException('ConsoleIo is required for calling other seeders.');
}
$io->out('');
Expand Down Expand Up @@ -287,7 +272,7 @@ protected function runCall(string $seeder, array $options = []): void
'source' => $options['source'],
]);
$io = $this->getIo();
if ($io === null) {
if (!$io instanceof ConsoleIo) {
throw new RuntimeException('ConsoleIo is required for calling other seeders.');
}
$manager = $factory->createManager($io);
Expand Down
5 changes: 1 addition & 4 deletions src/Command/BakeMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
*/
class BakeMigrationCommand extends BakeSimpleMigrationCommand
{
/**
* @var string
*/
protected string $_name;

/**
Expand All @@ -45,7 +42,7 @@ public static function defaultName(): string
/**
* @inheritDoc
*/
public function bake(string $name, Arguments $args, ConsoleIo $io): void
protected function bake(string $name, Arguments $args, ConsoleIo $io): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP allows widening visibility when overriding methods, just not narrowing.
So should be fine.

{
EventManager::instance()->on('Bake.initialize', function (Event $event): void {
/** @var \Bake\View\BakeView $view */
Expand Down
Loading
Loading