Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cycle:migrate --split command #97

Merged
merged 4 commits into from
Feb 7, 2025
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 .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
->include(__DIR__ . '/tests')
->include(__FILE__)
->cache('./runtime/php-cs-fixer.cache')
->allowRisky(false)
->allowRisky(true)
->build();
62 changes: 31 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,41 @@
],
"require": {
"php": ">=8.1",
"cycle/annotated": "^4.0",
"cycle/migrations": "^4.0.1",
"cycle/orm": "^2.0.2",
"cycle/schema-migrations-generator": "^2.1",
"cycle/annotated": "^4.2.3",
"cycle/migrations": "^4.2.4",
"cycle/orm": "^2.9.3",
"cycle/schema-migrations-generator": "^2.3",
"cycle/schema-renderer": "^1.2",
"cycle/schema-builder": "^2.7",
"doctrine/inflector": "^1.4 || ^2.0",
"spiral/attributes": "^2.10 || ^3.0",
"spiral/reactor": "^3.0",
"spiral/scaffolder": "^3.0",
"spiral/prototype": "^3.0",
"spiral/console": "^3.0",
"spiral/core": "^3.0",
"spiral/boot": "^3.0",
"spiral/auth": "^3.0",
"spiral/tokenizer": "^3.0",
"spiral/config": "^3.0",
"spiral/filters": "^3.10",
"spiral/data-grid-bridge": "^3.0",
"psr/container": "^1.1 || ^2.0"
"cycle/schema-builder": "^2.11.1",
"doctrine/inflector": "^1.4 || ^2.0.10",
"spiral/attributes": "^2.10 || ^3.1.8",
"spiral/reactor": "^3.15",
"spiral/scaffolder": "^3.15",
"spiral/prototype": "^3.15",
"spiral/console": "^3.15",
"spiral/core": "^3.15",
"spiral/boot": "^3.15",
"spiral/auth": "^3.15",
"spiral/tokenizer": "^3.15",
"spiral/config": "^3.15",
"spiral/filters": "^3.15",
"spiral/data-grid-bridge": "^3.0.1",
"psr/container": "^1.1 || ^2.0.2"
},
"require-dev": {
"cycle/entity-behavior": "^1.2",
"doctrine/collections": "^2.0",
"illuminate/collections": "^9.0",
"infection/infection": "^0.26.6",
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^9.5.20",
"spiral-packages/database-seeder": "^3.1",
"spiral/code-style": "^2.2.1",
"spiral/framework": "^3.11.1",
"cycle/entity-behavior": "^1.3.1",
"doctrine/collections": "^2.2.2",
"illuminate/collections": "^10.48",
"infection/infection": "^0.29.9",
"mockery/mockery": "^1.6.12",
"phpunit/phpunit": "^9.6.22",
"spiral-packages/database-seeder": "^3.3",
"spiral/code-style": "^2.2.2",
"spiral/framework": "^3.15.1",
"spiral/nyholm-bridge": "^1.3",
"spiral/testing": "^2.4",
"spiral/validator": "^1.5",
"vimeo/psalm": "^5.19"
"spiral/testing": "^2.9",
"spiral/validator": "^1.5.4",
"vimeo/psalm": "^6.4"
},
"autoload": {
"psr-4": {
Expand Down
50 changes: 9 additions & 41 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<files psalm-version="6.4.0@04f312ac6ea48ba1c3e5db4d815bf6d74641c0ee">
<file src="src/Annotated/Locator/ListenerEntityLocator.php">
<RedundantConditionGivenDocblockType>
<code><![CDATA[$attribute !== null]]></code>
Expand All @@ -13,12 +13,12 @@
<code><![CDATA[$this->normalizedPayload]]></code>
<code><![CDATA[$this->normalizedPayload]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[array]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$this->normalizedPayload]]></code>
</MixedReturnStatement>
<PossiblyFalseArgument>
<code><![CDATA[\stream_get_contents($this->payload)]]></code>
</PossiblyFalseArgument>
</file>
<file src="src/Auth/TokenStorage.php">
<ArgumentTypeCoercion>
Expand Down Expand Up @@ -53,10 +53,6 @@
<code><![CDATA[$nameGenerator]]></code>
<code><![CDATA[$strategy]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[GeneratorStrategyInterface]]></code>
<code><![CDATA[NameGeneratorInterface]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$container->get($nameGenerator)]]></code>
<code><![CDATA[$container->get($strategy)]]></code>
Expand Down Expand Up @@ -93,11 +89,6 @@
<code><![CDATA[GeneratorInterface[]]]></code>
</MoreSpecificReturnType>
</file>
<file src="src/Bootloader/ValidationBootloader.php">
<MissingReturnType>
<code><![CDATA[boot]]></code>
</MissingReturnType>
</file>
<file src="src/Config/CycleConfig.php">
<MixedArrayAccess>
<code><![CDATA[$config['default']]]></code>
Expand All @@ -110,9 +101,6 @@
<code><![CDATA[$config]]></code>
<code><![CDATA[$defaultSchema]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[?array]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$this->config['schema']['generators'] ?? null]]></code>
<code><![CDATA[$this->config['schema']['generators'] ?? null]]></code>
Expand Down Expand Up @@ -157,12 +145,6 @@
<code><![CDATA[DESCRIPTION]]></code>
<code><![CDATA[NAME]]></code>
</InvalidClassConstantType>
<MixedArgumentTypeCoercion>
<code><![CDATA[[$migrations]]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$migrations]]></code>
</MixedAssignment>
<PossiblyNullArgument>
<code><![CDATA[$this->output]]></code>
</PossiblyNullArgument>
Expand Down Expand Up @@ -251,10 +233,6 @@
<MixedArgument>
<code><![CDATA[static::OPTIONS]]></code>
</MixedArgument>
<MixedInferredReturnType>
<code><![CDATA[bool]]></code>
<code><![CDATA[bool]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$question->ask(
$this->input,
Expand Down Expand Up @@ -318,9 +296,6 @@
<MixedAssignment>
<code><![CDATA[$field]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[string]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$this->config->declarationOptions($element)[(string) $this->argument('format')]]]></code>
</MixedReturnStatement>
Expand Down Expand Up @@ -392,9 +367,6 @@
<code><![CDATA[$injector]]></code>
<code><![CDATA[$injector]]></code>
</MixedArgument>
<MixedInferredReturnType>
<code><![CDATA[string]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$this->expression->getValue()]]></code>
</MixedReturnStatement>
Expand Down Expand Up @@ -438,9 +410,6 @@
<code><![CDATA[$source]]></code>
<code><![CDATA[$source]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[string]]></code>
</MixedInferredReturnType>
<MixedMethodCall>
<code><![CDATA[limit]]></code>
<code><![CDATA[offset]]></code>
Expand All @@ -466,11 +435,9 @@
<code><![CDATA[$value]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$object]]></code>
<code><![CDATA[$this->orm]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[ORMInterface]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$this->orm]]></code>
<code><![CDATA[$this->orm]]></code>
Expand Down Expand Up @@ -515,6 +482,10 @@
<MixedAssignment>
<code><![CDATA[$value]]></code>
</MixedAssignment>
<MixedReturnStatement>
<code><![CDATA[$this->orm->getRepository($role)->findByPK($parameter)]]></code>
<code><![CDATA[$this->orm->getRepository($role)->findByPK($parameter)]]></code>
</MixedReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[array<non-empty-string, non-empty-string>]]></code>
</MoreSpecificReturnType>
Expand All @@ -533,9 +504,6 @@
<code><![CDATA[$channel]]></code>
<code><![CDATA[$this->config]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[LoggerInterface]]></code>
</MixedInferredReturnType>
<MixedMethodCall>
<code><![CDATA[getLogger]]></code>
</MixedMethodCall>
Expand Down
5 changes: 0 additions & 5 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@
</projectFiles>
<issueHandlers>
<MissingClassConstType errorLevel="suppress"/>
<UndefinedAttributeClass>
<errorLevel type="suppress">
<referencedClass name="JetBrains\PhpStorm\ExpectedValues"/>
</errorLevel>
</UndefinedAttributeClass>
</issueHandlers>
</psalm>
16 changes: 8 additions & 8 deletions src/Auth/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public function __construct(
$this->id = $id;

$this->secretValue = $secretValue;
$this->hashedValue = hash('sha512', $secretValue);
$this->hashedValue = \hash('sha512', $secretValue);

$this->createdAt = $createdAt;
$this->expiresAt = $expiresAt;

$this->payload = json_encode($payload);
$this->payload = \json_encode($payload);
}

public function setSecretValue(string $value): void
Expand All @@ -56,7 +56,7 @@ public function setSecretValue(string $value): void

public function getID(): string
{
return sprintf('%s:%s', $this->id, $this->secretValue);
return \sprintf('%s:%s', $this->id, $this->secretValue);
}

public function getHashedValue(): string
Expand All @@ -76,15 +76,15 @@ public function getExpiresAt(): ?\DateTimeInterface

public function getPayload(): array
{
if (is_array($this->normalizedPayload)) {
if (\is_array($this->normalizedPayload)) {
return $this->normalizedPayload;
}

if (is_resource($this->payload)) {
if (\is_resource($this->payload)) {
// postgres
$this->normalizedPayload = json_decode(stream_get_contents($this->payload), true);
} elseif (is_string($this->payload)) {
$this->normalizedPayload = json_decode($this->payload, true);
$this->normalizedPayload = \json_decode(\stream_get_contents($this->payload), true);
} elseif (\is_string($this->payload)) {
$this->normalizedPayload = \json_decode($this->payload, true);
}

if ($this->normalizedPayload === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/TokenStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ private function issueID(): string

private function randomHash(int $length): string
{
return \substr(\bin2hex(random_bytes($length)), 0, $length);
return \substr(\bin2hex(\random_bytes($length)), 0, $length);
}
}
2 changes: 1 addition & 1 deletion src/Bootloader/DisconnectsBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class DisconnectsBootloader extends Bootloader
public function init(FinalizerInterface $finalizer, ContainerInterface $container): void
{
$finalizer->addFinalizer(
function (bool $terminate) use ($container): void {
static function (bool $terminate) use ($container): void {
if ($terminate) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bootloader/ValidationBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class ValidationBootloader extends Bootloader
{
public function boot(ValidatorBootloader $validation)
public function boot(ValidatorBootloader $validation): void
{
$validation->addChecker('entity', EntityChecker::class);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Console/Command/CycleOrm/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ public function perform(

if ($print->hasChanges()) {
if ($this->option('split')) {
\assert($this->container instanceof BinderInterface);
$this->container->bind(GeneratorStrategyInterface::class, MultipleFilesStrategy::class);
$binder = $this->container?->get(BinderInterface::class);
\assert($binder instanceof BinderInterface);
$binder->getBinder('root')
->bind(GeneratorStrategyInterface::class, MultipleFilesStrategy::class);
}

$migrations = $this->container->get(GenerateMigrations::class);
\assert($migrations instanceof GenerateMigrations);

(new \Cycle\Schema\Compiler())->compile($registry, [$migrations]);

Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/CycleOrm/RenderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function perform(
'color' => new OutputSchemaRenderer(OutputSchemaRenderer::FORMAT_CONSOLE_COLOR),
'plain' => new OutputSchemaRenderer(OutputSchemaRenderer::FORMAT_PLAIN_TEXT),
default => throw new \InvalidArgumentException(
sprintf("Format `%s` isn't supported.", $this->argument('format')),
\sprintf("Format `%s` isn't supported.", $this->argument('format')),
),
};

Expand Down
10 changes: 5 additions & 5 deletions src/Console/Command/Database/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function perform(DatabaseConfig $config, DatabaseProviderInterface $dbal)
} catch (\Exception $exception) {
$this->renderException($grid, $header, $exception);

if ($database->getName() != end($databases)) {
if ($database->getName() != \end($databases)) {
$grid->addRow(new TableSeparator());
}

Expand All @@ -74,7 +74,7 @@ public function perform(DatabaseConfig $config, DatabaseProviderInterface $dbal)

$header[] = '<info>connected</info>';
$this->renderTables($grid, $header, $database);
if ($database->getName() != end($databases)) {
if ($database->getName() != \end($databases)) {
$grid->addRow(new TableSeparator());
}
}
Expand Down Expand Up @@ -102,14 +102,14 @@ private function renderTables(Table $grid, array $header, Database $database): v
{
foreach ($database->getTables() as $table) {
$grid->addRow(
array_merge(
\array_merge(
$header,
[$table->getName(), number_format($table->count())],
[$table->getName(), \number_format($table->count())],
),
);
$header = ['', '', '', '', ''];
}

$header[1] && $grid->addRow(array_merge($header, ['no tables', 'no records']));
$header[1] && $grid->addRow(\array_merge($header, ['no tables', 'no records']));
}
}
2 changes: 1 addition & 1 deletion src/Console/Command/Migrate/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function verifyEnvironment(string $message = 'Confirmation is required

protected function defineOptions(): array
{
return array_merge(
return \array_merge(
static::OPTIONS,
[
['force', 's', InputOption::VALUE_NONE, 'Skip safe environment check'],
Expand Down
4 changes: 2 additions & 2 deletions src/DataGrid/Writer/PostgresQueryWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function write(mixed $source, SpecificationInterface $specification, Comp
return $source->where(
$specification->getExpression(),
'ILIKE',
sprintf($specification->getPattern(), $this->fetchValue($specification->getValue())),
\sprintf($specification->getPattern(), $this->fetchValue($specification->getValue())),
);
}

Expand All @@ -43,7 +43,7 @@ public function write(mixed $source, SpecificationInterface $specification, Comp
protected function targetAcceptable($target): bool
{
if (
class_exists(SelectQuery::class)
\class_exists(SelectQuery::class)
&& $target instanceof SelectQuery
&& $target->getDriver() instanceof PostgresDriver
) {
Expand Down
Loading
Loading