Skip to content

Commit

Permalink
mainly cs
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Sep 23, 2019
1 parent 9b75152 commit e62e8ca
Show file tree
Hide file tree
Showing 36 changed files with 126 additions and 88 deletions.
5 changes: 4 additions & 1 deletion lib/Doctrine/Migrations/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class AbstractMigration
/** @var LoggerInterface */
private $logger;

/** @var array */
/** @var mixed[] */
private $plannedSql = [];

public function __construct(Connection $connection, LoggerInterface $logger)
Expand Down Expand Up @@ -127,6 +127,9 @@ protected function addSql(
$this->plannedSql[] = func_get_args();
}

/**
* @return mixed[]
*/
public function getSql() : array
{
return $this->plannedSql;
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/Migrations/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function addMigrationsDirectory(string $namespace, string $path) : void
$this->migrationsDirectories[$namespace] = $path;
}

/**
* @return array<string,string>
*/
public function getMigrationDirectories() : array
{
return $this->migrationsDirectories;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
*/
abstract class AbstractFileLoader implements Loader
{
/**
* @param array<string,string> $input
*
* @return array<string,string>
*/
protected function getDirectoryRelativeToFile(string $file, array $input) : array
{
foreach ($input as $ns => $dir) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/Migrations/Configuration/Loader/ArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class ArrayLoader implements Loader
{
/**
* @param mixed|array $array
* @param mixed $array
*/
public function load($array) : Configuration
{
Expand Down Expand Up @@ -64,9 +64,9 @@ public function load($array) : Configuration
}

/**
* @param array $configMap
* @param mixed[] $configMap
* @param Configuration|TableMetadataStorageConfiguration $object
* @param array $data
* @param mixed[] $data
*/
private static function applyConfigs(array $configMap, $object, array $data) : void
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Migrations/Configuration/Loader/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface Loader
/**
* @param mixed $resource
*/
function load($resource) : Configuration;
public function load($resource) : Configuration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class XmlFileLoader extends AbstractFileLoader
/** @var ArrayLoader */
private $arrayLoader;

/**
* @return mixed[]
*/
private function extractParameters(SimpleXMLElement $root, bool $nodes = true) : array
{
$config = [];
Expand Down Expand Up @@ -52,6 +55,9 @@ public function __construct(?ArrayLoader $arrayLoader = null)
$this->arrayLoader = $arrayLoader ?: new ArrayLoader();
}

/**
* @param mixed|string $file
*/
public function load($file) : Configuration
{
if (! file_exists($file)) {
Expand Down
4 changes: 0 additions & 4 deletions lib/Doctrine/Migrations/Event/MigrationsVersionEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\Common\EventArgs;
use Doctrine\DBAL\Connection;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Metadata\MigrationPlan;
use Doctrine\Migrations\MigratorConfiguration;

Expand All @@ -15,9 +14,6 @@
*/
class MigrationsVersionEventArgs extends EventArgs
{
/** @var Configuration */
private $configuration;

/** @var Connection */
private $connection;

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Migrations/Generator/FileBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function buildMigrationFile(
return $string;
}

// @todo this is hard to implement since MetadataStorage abstracts the migrations table
private function getVersionUpdateQuery(string $version, string $direction) : string
{
// @todo this is hard to implement since MetadataStorage abstracts the migrations table
return '';

if ($direction === Direction::DOWN) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/Migrations/Metadata/AvailableMigrationsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class AvailableMigrationsList implements Countable
/** @var AvailableMigration[] */
private $items = [];

/**
* @param AvailableMigration[] $items
*/
public function __construct(array $items)
{
$this->items = array_values($items);
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/Migrations/Metadata/ExecutedMigrationsSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class ExecutedMigrationsSet implements Countable
/** @var ExecutedMigration[] */
private $items = [];

/**
* @param ExecutedMigration[] $items
*/
public function __construct(array $items)
{
$this->items = array_values($items);
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/Migrations/Metadata/MigrationPlanList.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class MigrationPlanList implements Countable
/** @var MigrationPlan[] */
private $items = [];

/**
* @param MigrationPlan[] $items
*/
public function __construct(array $items, string $direction)
{
$this->items = $items;
Expand Down
10 changes: 9 additions & 1 deletion lib/Doctrine/Migrations/MigrationPlanCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ private function findDirection(Version $to, Metadata\ExecutedMigrationsSet $exec
return Direction::UP;
}

/**
* @return Metadata\AvailableMigration[]
*/
private function arrangeMigrationsForDirection(string $direction, Metadata\AvailableMigrationsList $availableMigrations) : array
{
return $direction === Direction::UP ? $availableMigrations->getItems() : array_reverse($availableMigrations->getItems());
}

private function findMigrationsToExecute(Version $to, $migrationsToCheck, string $direction, Metadata\ExecutedMigrationsSet $executedMigrations) : array
/**
* @param ExecutedMigration[] $migrationsToCheck
*
* @return ExecutedMigration[]
*/
private function findMigrationsToExecute(Version $to, array $migrationsToCheck, string $direction, Metadata\ExecutedMigrationsSet $executedMigrations) : array
{
$toExecute = [];
foreach ($migrationsToCheck as $availableMigration) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/Migrations/MigrationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class MigrationRepository
/** @var callable */
private $sorter;

/**
* @param array<string, string> $migrationDirectories
*/
public function __construct(
array $migrationDirectories,
MigrationFinder $migrationFinder,
Expand Down
6 changes: 6 additions & 0 deletions lib/Doctrine/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ private function executeMigrations(
return $sql;
}

/**
* @return array<string, string[]>
*/
private function executePlan(MigrationPlanList $migrationsPlan, MigratorConfiguration $migratorConfiguration) : array
{
$sql = [];
Expand Down Expand Up @@ -130,6 +133,9 @@ private function endMigrations(
);
}

/**
* @return string[][]
*/
public function migrate(MigrationPlanList $migrationsPlan, MigratorConfiguration $migratorConfiguration) : array
{
/**
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/Migrations/MigratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
*/
interface MigratorInterface
{
/**
* @return string[][]
*/
public function migrate(MigrationPlanList $migrationsPlan, MigratorConfiguration $migratorConfiguration) : array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public function execute(
$configuration = $this->dependencyFactory->getConfiguration();
$versionNumber = $configuration->generateVersionNumber();

if (! ($namespace = $input->getOption('namespace'))) {
$namespace = $input->getOption('namespace');
if ($namespace === null) {
$dirs = $configuration->getMigrationDirectories();
$namespace = key($dirs);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/Migrations/Version/AliasResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ public function resolveVersionAlias(string $alias) : Version
if ($info !== null) {
return $info->getVersion();
}

throw UnknownMigrationVersion::new($alias);
case self::ALIAS_CURRENT:
$info = $executedMigrations->getLast();

if ($info !== null) {
return $info->getVersion();
}
return $info !== null ? $info->getVersion() : new Version('0');
case self::ALIAS_PREV:
$info = $executedMigrations->getLast(-1);

Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/Migrations/Version/ExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public function getSql() : array

/**
* @param string[] $sql
* @param mixed[] $params
* @param int[] $types
*/
public function setSql(array $sql, array $params = [], array $types = []) : void
{
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/Migrations/Version/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ private function executeMigration(
return $result;
}

/**
* @return mixed[]
*/
private function getMigrationHeader(MigrationPlan $planItem, AbstractMigration $migration, string $direction) : array
{
$versionInfo = (string) $planItem->getVersion();
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/Migrations/Version/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class Factory
/** @var Connection */
private $connection;

/** @var ExecutorInterface */
private $versionExecutor;

/** @var LoggerInterface */
private $logger;

Expand Down
10 changes: 1 addition & 9 deletions tests/Doctrine/Migrations/Tests/AbstractMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\Migrations\Exception\IrreversibleMigration;
use Doctrine\Migrations\Exception\SkipMigration;
use Doctrine\Migrations\Tests\Stub\AbstractMigrationStub;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;

class AbstractMigrationTest extends MigrationTestCase
Expand All @@ -21,14 +20,7 @@ class AbstractMigrationTest extends MigrationTestCase

protected function setUp() : void
{
$this->logger = new class () extends AbstractLogger {
public $logs = [];

public function log($level, $message, array $context = []) : void
{
$this->logs[] = $message;
}
};
$this->logger = new TestLogger();

$this->migration = new AbstractMigrationStub($this->getSqliteConnection(), $this->logger);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

abstract class AbstractLoaderTest extends TestCase
{
abstract public function load($prefix = '') : Configuration;
abstract public function load(string $prefix = '') : Configuration;

public function testLoad() : void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class JsonLoaderTest extends AbstractLoaderTest
{
public function load($prefix = '') : Configuration
public function load(string $prefix = '') : Configuration
{
$loader = new JsonFileLoader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class PhpLoaderTest extends AbstractLoaderTest
{
public function load($prefix = '') : Configuration
public function load(string $prefix = '') : Configuration
{
$loader = new PHPFileLoader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class XmlLoaderTest extends AbstractLoaderTest
{
public function load($prefix = '') : Configuration
public function load(string $prefix = '') : Configuration
{
$loader = new XmlFileLoader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class YamlLoaderTest extends AbstractLoaderTest
{
public function load($prefix = '') : Configuration
public function load(string $prefix = '') : Configuration
{
$loader = new YamlFileLoader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\Migrations\Tests\Metadata;

use DateTime;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\Migrations\Exception\MigrationNotExecuted;
use Doctrine\Migrations\Metadata\ExecutedMigration;
use Doctrine\Migrations\Metadata\ExecutedMigrationsSet;
Expand All @@ -14,14 +13,6 @@

class ExecutedMigrationSetTest extends TestCase
{
/** @var AbstractMigration */
private $abstractMigration;

public function setUp() : void
{
$this->abstractMigration = $this->createMock(AbstractMigration::class);
}

public function testFirst() : void
{
$m1 = new ExecutedMigration(new Version('A'));
Expand Down
14 changes: 12 additions & 2 deletions tests/Doctrine/Migrations/Tests/MigrationPlanCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function testPlanForExactVersionWhenNoMigrations() : void
}

/**
* @param string[] $expectedPlan
*
* @dataProvider getPlanUpWhenNoMigrations
*/
public function testPlanWhenNoMigrations(?string $to, array $expectedPlan, string $direction) : void
Expand Down Expand Up @@ -100,7 +102,10 @@ public function testPlanWhenNoMigrations(?string $to, array $expectedPlan, strin
}
}

public function getPlanUpWhenNoMigrations()
/**
* @return mixed[]
*/
public function getPlanUpWhenNoMigrations() : array
{
return [
['A', ['A'], Direction::UP],
Expand All @@ -112,6 +117,8 @@ public function getPlanUpWhenNoMigrations()
}

/**
* @param string[] $expectedPlan
*
* @dataProvider getPlanUpWhenMigrations
*/
public function testPlanWhenMigrations(?string $to, array $expectedPlan, ?string $direction) : void
Expand Down Expand Up @@ -216,7 +223,10 @@ public function testGetExecutedUnavailableMigrations() : void
self::assertSame([$e2, $e3], $newSet->getItems());
}

public function getPlanUpWhenMigrations()
/**
* @return mixed[]
*/
public function getPlanUpWhenMigrations() : array
{
return [
['0', ['B', 'A'], Direction::DOWN],
Expand Down
Loading

0 comments on commit e62e8ca

Please sign in to comment.