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

Spiral preconition hints #21

Open
wants to merge 6 commits into
base: 2.x
Choose a base branch
from
Open
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
119 changes: 56 additions & 63 deletions resources/.phpstorm.meta.php

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/Atomizer/Atomizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace Cycle\Migrations\Atomizer;

use Spiral\Migrations\Atomizer\RendererInterface as SpiralRendererInterface;
use Cycle\Database\Schema\AbstractTable;
use Spiral\Database\Schema\AbstractTable as SpiralAbstractTable;
use Cycle\Database\Schema\Reflector;
use Spiral\Reactor\Partial\Source;

Expand All @@ -28,21 +30,23 @@ final class Atomizer
private $renderer;

/**
* @param RendererInterface $renderer
* @param RendererInterface|SpiralRendererInterface $renderer The signature of this
* argument will be changed to {@see RendererInterface} in future release.
*/
public function __construct(RendererInterface $renderer)
public function __construct(SpiralRendererInterface $renderer)
{
$this->renderer = $renderer;
}

/**
* Add new table into atomizer.
*
* @param AbstractTable $table
* @param AbstractTable|SpiralAbstractTable $table The signature of this
* argument will be changed to {@see AbstractTable} in future release.
*
* @return Atomizer
*/
public function addTable(AbstractTable $table): self
public function addTable(SpiralAbstractTable $table): self
{
$this->tables[] = $table;

Expand Down
47 changes: 25 additions & 22 deletions src/Atomizer/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Cycle\Database\Schema\AbstractForeignKey;
use Cycle\Database\Schema\AbstractIndex;
use Cycle\Database\Schema\AbstractTable;
use Spiral\Database\Schema\AbstractTable as SpiralAbstractTable;
use Cycle\Database\Schema\Comparator;
use Spiral\Reactor\Partial\Source;
use Spiral\Reactor\Serializer;
Expand All @@ -31,15 +32,11 @@ final class Renderer implements RendererInterface
public const ORIGINAL_STATE = 1;

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function createTable(Source $source, AbstractTable $table): void
public function createTable(Source $source, SpiralAbstractTable $table): void
{
$this->render(
$source,
'$this->table(%s)',
$table
);
$this->render($source, '$this->table(%s)', $table);
$comparator = $table->getComparator();

$this->declareColumns($source, $comparator);
Expand All @@ -59,9 +56,9 @@ public function createTable(Source $source, AbstractTable $table): void
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function updateTable(Source $source, AbstractTable $table): void
public function updateTable(Source $source, SpiralAbstractTable $table): void
{
$this->render(
$source,
Expand All @@ -87,9 +84,9 @@ public function updateTable(Source $source, AbstractTable $table): void
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function revertTable(Source $source, AbstractTable $table): void
public function revertTable(Source $source, SpiralAbstractTable $table): void
{
//Get table blueprint
$this->render(
Expand All @@ -108,9 +105,9 @@ public function revertTable(Source $source, AbstractTable $table): void
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function dropTable(Source $source, AbstractTable $table): void
public function dropTable(Source $source, SpiralAbstractTable $table): void
{
$this->render(
$source,
Expand Down Expand Up @@ -370,7 +367,9 @@ protected function alterColumn(
*
* @param Source $source
* @param string $format
* @param array ...$values
* @param array ...$values
*
* @throws \ReflectionException
*/
protected function render(Source $source, string $format, ...$values): void
{
Expand Down Expand Up @@ -416,9 +415,11 @@ protected function render(Source $source, string $format, ...$values): void
}

/**
* @param Serializer $serializer
* @param Serializer $serializer
* @param AbstractColumn $column
*
* @throws \ReflectionException
*
* @return string
*/
private function columnOptions(Serializer $serializer, AbstractColumn $column): string
Expand All @@ -445,9 +446,11 @@ private function columnOptions(Serializer $serializer, AbstractColumn $column):
}

/**
* @param Serializer $serializer
* @param Serializer $serializer
* @param AbstractIndex $index
*
* @throws \ReflectionException
*
* @return string
*/
private function indexOptions(Serializer $serializer, AbstractIndex $index): string
Expand All @@ -463,15 +466,15 @@ private function indexOptions(Serializer $serializer, AbstractIndex $index): str
}

/**
* @param Serializer $serializer
* @param Serializer $serializer
* @param AbstractForeignKey $reference
*
* @throws \ReflectionException
*
* @return string
*/
private function foreignKeyOptions(
Serializer $serializer,
AbstractForeignKey $reference
): string {
private function foreignKeyOptions(Serializer $serializer, AbstractForeignKey $reference): string
{
return $this->mountIndents(
$serializer->serialize(
[
Expand All @@ -486,7 +489,7 @@ private function foreignKeyOptions(
/**
* Mount indents for column and index options.
*
* @param $serialized
* @param string $serialized
*
* @return string
*/
Expand Down
29 changes: 17 additions & 12 deletions src/Atomizer/RendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Cycle\Migrations\Atomizer;

use Cycle\Database\Schema\AbstractTable;
use Spiral\Database\Schema\AbstractTable as SpiralAbstractTable;
use Spiral\Reactor\Partial\Source;

/**
Expand All @@ -22,32 +23,36 @@ interface RendererInterface
/**
* Migration engine specific table creation syntax.
*
* @param Source $source
* @param AbstractTable $table
* @param Source $source
* @param AbstractTable|SpiralAbstractTable $table The signature of this
* argument will be changed to {@see AbstractTable} in future release.
*/
public function createTable(Source $source, AbstractTable $table);
public function createTable(Source $source, SpiralAbstractTable $table);

/**
* Migration engine specific table update syntax.
*
* @param Source $source
* @param AbstractTable $table
* @param Source $source
* @param AbstractTable|SpiralAbstractTable $table The signature of this
* argument will be changed to {@see AbstractTable} in future release.
*/
public function updateTable(Source $source, AbstractTable $table);
public function updateTable(Source $source, SpiralAbstractTable $table);

/**
* Migration engine specific table revert syntax.
*
* @param Source $source
* @param AbstractTable $table
* @param Source $source
* @param AbstractTable|SpiralAbstractTable $table The signature of this
* argument will be changed to {@see AbstractTable} in future release.
*/
public function revertTable(Source $source, AbstractTable $table);
public function revertTable(Source $source, SpiralAbstractTable $table);

/**
* Migration engine specific table drop syntax.
*
* @param Source $source
* @param AbstractTable $table
* @param Source $source
* @param AbstractTable|SpiralAbstractTable $table The signature of this
* argument will be changed to {@see AbstractTable} in future release.
*/
public function dropTable(Source $source, AbstractTable $table);
public function dropTable(Source $source, SpiralAbstractTable $table);
}
14 changes: 8 additions & 6 deletions src/Capsule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Cycle\Migrations;

use Cycle\Database\Database;
use Spiral\Database\Database as SpiralDatabase;
use Cycle\Database\DatabaseInterface;
use Cycle\Database\DatabaseManager;
use Cycle\Database\Schema\AbstractTable;
Expand All @@ -30,31 +31,32 @@ final class Capsule implements CapsuleInterface
private $schemas = [];

/**
* @param Database $database
* @param Database|SpiralDatabase $database The signature of this argument
* will be changed to {@see Database} in future release.
*/
public function __construct(Database $database)
public function __construct(SpiralDatabase $database)
{
$this->database = $database;
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getDatabase(): DatabaseInterface
{
return $this->database;
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getTable(string $table): TableInterface
{
return $this->database->table($table);
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getSchema(string $table): AbstractTable
{
Expand All @@ -67,7 +69,7 @@ public function getSchema(string $table): AbstractTable
}

/**
* {@inheritdoc}
* {@inheritDoc}
*
* @throws \Throwable
*/
Expand Down
16 changes: 0 additions & 16 deletions src/Exception/AtomizerException.php

This file was deleted.

16 changes: 10 additions & 6 deletions src/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

namespace Cycle\Migrations;

use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\Rules\English\InflectorFactory;
use Spiral\Core\Container;
use Spiral\Core\FactoryInterface;
use Spiral\Files\Files;
use Spiral\Files\FilesInterface;
use Cycle\Migrations\Config\MigrationConfig;
use Spiral\Migrations\Config\MigrationConfig as SpiralMigrationConfig;
use Cycle\Migrations\Exception\RepositoryException;
use Cycle\Migrations\Migration\State;
use Spiral\Tokenizer\Reflection\ReflectionFile;
Expand Down Expand Up @@ -43,23 +46,24 @@ final class FileRepository implements RepositoryInterface
/** @var FilesInterface */
private $files;

/** @var \Doctrine\Inflector\Inflector */
/** @var Inflector */
private $inflector;

/**
* @param MigrationConfig $config
* @param MigrationConfig|SpiralMigrationConfig $config The signature of this
* argument will be changed to {@see MigrationConfig} in future release.
* @param FactoryInterface|null $factory
*/
public function __construct(MigrationConfig $config, FactoryInterface $factory = null)
public function __construct(SpiralMigrationConfig $config, FactoryInterface $factory = null)
{
$this->config = $config;
$this->files = new Files();
$this->factory = $factory ?? new Container();
$this->inflector = (new \Doctrine\Inflector\Rules\English\InflectorFactory())->build();
$this->inflector = (new InflectorFactory())->build();
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getMigrations(): array
{
Expand Down Expand Up @@ -87,7 +91,7 @@ public function getMigrations(): array
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function registerMigration(string $name, string $class, string $body = null): string
{
Expand Down
12 changes: 7 additions & 5 deletions src/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Cycle\Migrations\Migration\DefinitionInterface;
use Cycle\Migrations\Migration\ProvidesSyncStateInterface;
use Cycle\Migrations\Migration\State;
use Spiral\Migrations\Migration\State as SpiralState;
use Spiral\Migrations\CapsuleInterface as SpiralCapsuleInterface;

/**
* Simple migration class with shortcut for database and blueprint instances.
Expand All @@ -41,9 +43,9 @@ public function getDatabase(): ?string
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function withCapsule(CapsuleInterface $capsule): DefinitionInterface
public function withCapsule(SpiralCapsuleInterface $capsule): DefinitionInterface
{
$migration = clone $this;
$migration->capsule = $capsule;
Expand All @@ -52,9 +54,9 @@ public function withCapsule(CapsuleInterface $capsule): DefinitionInterface
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function withState(State $state): ProvidesSyncStateInterface
public function withState(SpiralState $state): ProvidesSyncStateInterface
{
$migration = clone $this;
$migration->state = $state;
Expand All @@ -63,7 +65,7 @@ public function withState(State $state): ProvidesSyncStateInterface
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getState(): State
{
Expand Down
Loading