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

Import Db/Plan package #669

Merged
merged 2 commits into from
Dec 18, 2023
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
25 changes: 25 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@ parameters:
count: 1
path: src/Command/BakeMigrationSnapshotCommand.php

-
message: "#^Parameter \\#1 \\$table of method Phinx\\\\Db\\\\Adapter\\\\AdapterInterface\\:\\:createTable\\(\\) expects Phinx\\\\Db\\\\Table\\\\Table, Migrations\\\\Db\\\\Table\\\\Table given\\.$#"
count: 2
path: src/Db/Plan/Plan.php

-
message: "#^Parameter \\#1 \\$table of method Phinx\\\\Db\\\\Adapter\\\\AdapterInterface\\:\\:executeActions\\(\\) expects Phinx\\\\Db\\\\Table\\\\Table, Migrations\\\\Db\\\\Table\\\\Table given\\.$#"
count: 2
path: src/Db/Plan/Plan.php

-
message: "#^Parameter \\#2 \\$actions of method Phinx\\\\Db\\\\Adapter\\\\AdapterInterface\\:\\:executeActions\\(\\) expects array\\<Phinx\\\\Db\\\\Action\\\\Action\\>, array\\<Migrations\\\\Db\\\\Action\\\\Action\\> given\\.$#"
count: 2
path: src/Db/Plan/Plan.php

-
message: "#^Parameter \\#2 \\$columns of method Phinx\\\\Db\\\\Adapter\\\\AdapterInterface\\:\\:createTable\\(\\) expects array\\<Phinx\\\\Db\\\\Table\\\\Column\\>, array\\<Migrations\\\\Db\\\\Table\\\\Column\\> given\\.$#"
count: 2
path: src/Db/Plan/Plan.php

-
message: "#^Parameter \\#3 \\$indexes of method Phinx\\\\Db\\\\Adapter\\\\AdapterInterface\\:\\:createTable\\(\\) expects array\\<Phinx\\\\Db\\\\Table\\\\Index\\>, array\\<Migrations\\\\Db\\\\Table\\\\Index\\> given\\.$#"
count: 2
path: src/Db/Plan/Plan.php

-
message: "#^Possibly invalid array key type Cake\\\\Database\\\\Schema\\\\TableSchemaInterface\\|string\\.$#"
count: 2
Expand Down
14 changes: 14 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
<code>setInput</code>
</PossiblyNullReference>
</file>
<file src="src/Db/Plan/Plan.php">
<InvalidArgument>
<code><![CDATA[$newTable->getColumns()]]></code>
<code><![CDATA[$newTable->getColumns()]]></code>
<code><![CDATA[$newTable->getIndexes()]]></code>
<code><![CDATA[$newTable->getIndexes()]]></code>
<code><![CDATA[$newTable->getTable()]]></code>
<code><![CDATA[$newTable->getTable()]]></code>
<code><![CDATA[$update->getActions()]]></code>
<code><![CDATA[$update->getActions()]]></code>
<code><![CDATA[$update->getTable()]]></code>
<code><![CDATA[$update->getTable()]]></code>
</InvalidArgument>
</file>
<file src="src/TableFinderTrait.php">
<PossiblyUndefinedArrayOffset>
<code>$split[0]</code>
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
errorBaseline="./psalm-baseline.xml"
autoloader="tests/bootstrap.php"
findUnusedPsalmSuppress="true"
findUnusedBaselineEntry="true"
Expand Down
73 changes: 73 additions & 0 deletions src/Db/Plan/AlterTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);

/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/

namespace Migrations\Db\Plan;

use Migrations\Db\Action\Action;
use Migrations\Db\Table\Table;

/**
* A collection of ALTER actions for a single table
*/
class AlterTable
{
/**
* The table
*
* @var \Migrations\Db\Table\Table
*/
protected Table $table;

/**
* The list of actions to execute
*
* @var \Migrations\Db\Action\Action[]
*/
protected array $actions = [];

/**
* Constructor
*
* @param \Migrations\Db\Table\Table $table The table to change
*/
public function __construct(Table $table)

Check warning on line 38 in src/Db/Plan/AlterTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/AlterTable.php#L38

Added line #L38 was not covered by tests
{
$this->table = $table;

Check warning on line 40 in src/Db/Plan/AlterTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/AlterTable.php#L40

Added line #L40 was not covered by tests
}

/**
* Adds another action to the collection
*
* @param \Migrations\Db\Action\Action $action The action to add
* @return void
*/
public function addAction(Action $action): void

Check warning on line 49 in src/Db/Plan/AlterTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/AlterTable.php#L49

Added line #L49 was not covered by tests
{
$this->actions[] = $action;

Check warning on line 51 in src/Db/Plan/AlterTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/AlterTable.php#L51

Added line #L51 was not covered by tests
}

/**
* Returns the table associated to this collection
*
* @return \Migrations\Db\Table\Table
*/
public function getTable(): Table

Check warning on line 59 in src/Db/Plan/AlterTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/AlterTable.php#L59

Added line #L59 was not covered by tests
{
return $this->table;

Check warning on line 61 in src/Db/Plan/AlterTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/AlterTable.php#L61

Added line #L61 was not covered by tests
}

/**
* Returns an array with all collected actions
*
* @return \Migrations\Db\Action\Action[]
*/
public function getActions(): array

Check warning on line 69 in src/Db/Plan/AlterTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/AlterTable.php#L69

Added line #L69 was not covered by tests
{
return $this->actions;

Check warning on line 71 in src/Db/Plan/AlterTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/AlterTable.php#L71

Added line #L71 was not covered by tests
}
}
56 changes: 56 additions & 0 deletions src/Db/Plan/Intent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);

/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/

namespace Migrations\Db\Plan;

use Migrations\Db\Action\Action;

/**
* An intent is a collection of actions for many tables
*/
class Intent
{
/**
* List of actions to be executed
*
* @var \Migrations\Db\Action\Action[]
*/
protected array $actions = [];

/**
* Adds a new action to the collection
*
* @param \Migrations\Db\Action\Action $action The action to add
* @return void
*/
public function addAction(Action $action): void

Check warning on line 31 in src/Db/Plan/Intent.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/Intent.php#L31

Added line #L31 was not covered by tests
{
$this->actions[] = $action;

Check warning on line 33 in src/Db/Plan/Intent.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/Intent.php#L33

Added line #L33 was not covered by tests
}

/**
* Returns the full list of actions
*
* @return \Migrations\Db\Action\Action[]
*/
public function getActions(): array

Check warning on line 41 in src/Db/Plan/Intent.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/Intent.php#L41

Added line #L41 was not covered by tests
{
return $this->actions;

Check warning on line 43 in src/Db/Plan/Intent.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/Intent.php#L43

Added line #L43 was not covered by tests
}

/**
* Merges another Intent object with this one
*
* @param \Migrations\Db\Plan\Intent $another The other intent to merge in
* @return void
*/
public function merge(Intent $another): void

Check warning on line 52 in src/Db/Plan/Intent.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/Intent.php#L52

Added line #L52 was not covered by tests
{
$this->actions = array_merge($this->actions, $another->getActions());

Check warning on line 54 in src/Db/Plan/Intent.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/Intent.php#L54

Added line #L54 was not covered by tests
}
}
102 changes: 102 additions & 0 deletions src/Db/Plan/NewTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);

/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/

namespace Migrations\Db\Plan;

use Migrations\Db\Table\Column;
use Migrations\Db\Table\Index;
use Migrations\Db\Table\Table;

/**
* Represents the collection of actions for creating a new table
*/
class NewTable
{
/**
* The table to create
*
* @var \Migrations\Db\Table\Table
*/
protected Table $table;

/**
* The list of columns to add
*
* @var \Migrations\Db\Table\Column[]
*/
protected array $columns = [];

/**
* The list of indexes to create
*
* @var \Migrations\Db\Table\Index[]
*/
protected array $indexes = [];

/**
* Constructor
*
* @param \Migrations\Db\Table\Table $table The table to create
*/
public function __construct(Table $table)

Check warning on line 46 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L46

Added line #L46 was not covered by tests
{
$this->table = $table;

Check warning on line 48 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L48

Added line #L48 was not covered by tests
}

/**
* Adds a column to the collection
*
* @param \Migrations\Db\Table\Column $column The column description
* @return void
*/
public function addColumn(Column $column): void

Check warning on line 57 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L57

Added line #L57 was not covered by tests
{
$this->columns[] = $column;

Check warning on line 59 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L59

Added line #L59 was not covered by tests
}

/**
* Adds an index to the collection
*
* @param \Migrations\Db\Table\Index $index The index description
* @return void
*/
public function addIndex(Index $index): void

Check warning on line 68 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L68

Added line #L68 was not covered by tests
{
$this->indexes[] = $index;

Check warning on line 70 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L70

Added line #L70 was not covered by tests
}

/**
* Returns the table object associated to this collection
*
* @return \Migrations\Db\Table\Table
*/
public function getTable(): Table

Check warning on line 78 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L78

Added line #L78 was not covered by tests
{
return $this->table;

Check warning on line 80 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L80

Added line #L80 was not covered by tests
}

/**
* Returns the columns collection
*
* @return \Migrations\Db\Table\Column[]
*/
public function getColumns(): array

Check warning on line 88 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L88

Added line #L88 was not covered by tests
{
return $this->columns;

Check warning on line 90 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L90

Added line #L90 was not covered by tests
}

/**
* Returns the indexes collection
*
* @return \Migrations\Db\Table\Index[]
*/
public function getIndexes(): array

Check warning on line 98 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L98

Added line #L98 was not covered by tests
{
return $this->indexes;

Check warning on line 100 in src/Db/Plan/NewTable.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Plan/NewTable.php#L100

Added line #L100 was not covered by tests
}
}
Loading
Loading