Skip to content

Commit 5a2b3aa

Browse files
committed
Code reformat
1 parent 15c3d63 commit 5a2b3aa

File tree

5 files changed

+41
-45
lines changed

5 files changed

+41
-45
lines changed

src/Migrations.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public static function run(array $options)
338338
continue;
339339
}
340340

341-
//Directory depends on Forward or Back Migration
341+
// Directory depends on Forward or Back Migration
342342
if (ModelMigration::DIRECTION_BACK === $direction) {
343343
$migrationsDir = $initialVersion->getPath();
344344
$directoryIterator = $migrationsDir . DIRECTORY_SEPARATOR . $initialVersion->getVersion();
@@ -566,7 +566,7 @@ private static function connectionSetup(array $options): void
566566
* @param array $options Applications options
567567
* @return IncrementalItem|TimestampedItem
568568
*/
569-
public static function getCurrentVersion($options)
569+
public static function getCurrentVersion(array $options)
570570
{
571571
self::connectionSetup($options);
572572

@@ -603,10 +603,9 @@ public static function getCurrentVersion($options)
603603
*
604604
* @param array $options Applications options
605605
* @param string $version Migration version to store
606-
* @param string $startTime Migration start timestamp
607-
* @throws DbException
606+
* @param string|null $startTime Migration start timestamp
608607
*/
609-
public static function addCurrentVersion(array $options, string $version, string $startTime = null): void
608+
public static function addCurrentVersion(array $options, string $version, ?string $startTime = null): void
610609
{
611610
self::connectionSetup($options);
612611

@@ -638,7 +637,6 @@ public static function addCurrentVersion(array $options, string $version, string
638637
*
639638
* @param array $options Applications options
640639
* @param string $version Migration version to remove
641-
* @throws DbException
642640
*/
643641
public static function removeCurrentVersion(array $options, string $version): void
644642
{

src/Mvc/Model/Migration.php

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
use Phalcon\Migrations\Version\ItemCollection as VersionCollection;
3535
use Phalcon\Migrations\Version\ItemInterface;
3636
use Phalcon\Text;
37+
use Throwable;
38+
39+
use function get_called_class;
3740

3841
/**
3942
* Migrations of DML y DDL over databases
@@ -538,13 +541,13 @@ public function morphTable(string $tableName, array $definition): void
538541
if (!isset($localFields[$fieldName])) {
539542
try {
540543
self::$connection->addColumn($tableName, $tableSchema, $column);
541-
} catch (\Throwable $exception) {
544+
} catch (Throwable $exception) {
542545
throw new RuntimeException(
543546
sprintf(
544547
"Failed to add column '%s' in table '%s'. In '%s' migration. DB error: %s",
545548
$column->getName(),
546549
$tableName,
547-
\get_called_class(),
550+
get_called_class(),
548551
$exception->getMessage()
549552
)
550553
);
@@ -577,13 +580,13 @@ public function morphTable(string $tableName, array $definition): void
577580
if ($changed === true) {
578581
try {
579582
self::$connection->modifyColumn($tableName, $tableSchema, $column, $column);
580-
} catch (\Throwable $exception) {
583+
} catch (Throwable $exception) {
581584
throw new RuntimeException(
582585
sprintf(
583586
"Failed to modify column '%s' in table '%s'. In '%s' migration. DB error: %s",
584587
$column->getName(),
585588
$tableName,
586-
\get_called_class(),
589+
get_called_class(),
587590
$exception->getMessage()
588591
)
589592
);
@@ -598,13 +601,13 @@ public function morphTable(string $tableName, array $definition): void
598601
* TODO: Check, why schemaName is empty string.
599602
*/
600603
self::$connection->dropColumn($tableName, '', $fieldName);
601-
} catch (\Throwable $exception) {
604+
} catch (Throwable $exception) {
602605
throw new RuntimeException(
603606
sprintf(
604607
"Failed to drop column '%s' in table '%s'. In '%s' migration. DB error: %s",
605608
$fieldName,
606609
$tableName,
607-
\get_called_class(),
610+
get_called_class(),
608611
$exception->getMessage()
609612
)
610613
);
@@ -614,12 +617,12 @@ public function morphTable(string $tableName, array $definition): void
614617
} else {
615618
try {
616619
self::$connection->createTable($tableName, $tableSchema, $definition);
617-
} catch (\Throwable $exception) {
620+
} catch (Throwable $exception) {
618621
throw new RuntimeException(
619622
sprintf(
620623
"Failed to create table '%s'. In '%s' migration. DB error: %s",
621624
$tableName,
622-
\get_called_class(),
625+
get_called_class(),
623626
$exception->getMessage()
624627
)
625628
);
@@ -659,13 +662,13 @@ public function morphTable(string $tableName, array $definition): void
659662
$schemaName,
660663
$tableReference
661664
);
662-
} catch (\Throwable $exception) {
665+
} catch (Throwable $exception) {
663666
throw new RuntimeException(
664667
sprintf(
665668
"Failed to add foreign key '%s' in '%s'. In '%s' migration. DB error: %s",
666669
$tableReference->getName(),
667670
$tableName,
668-
\get_called_class(),
671+
get_called_class(),
669672
$exception->getMessage()
670673
)
671674
);
@@ -725,13 +728,13 @@ public function morphTable(string $tableName, array $definition): void
725728
$schemaName,
726729
$tableReference->getName()
727730
);
728-
} catch (\Throwable $exception) {
731+
} catch (Throwable $exception) {
729732
throw new RuntimeException(
730733
sprintf(
731734
"Failed to drop foreign key '%s' in '%s'. In '%s' migration. DB error: %s",
732735
$tableReference->getName(),
733736
$tableName,
734-
\get_called_class(),
737+
get_called_class(),
735738
$exception->getMessage()
736739
)
737740
);
@@ -743,13 +746,13 @@ public function morphTable(string $tableName, array $definition): void
743746
$schemaName,
744747
$tableReference
745748
);
746-
} catch (\Throwable $exception) {
749+
} catch (Throwable $exception) {
747750
throw new RuntimeException(
748751
sprintf(
749752
"Failed to add foreign key '%s' in '%s'. In '%s' migration. DB error: %s",
750753
$tableReference->getName(),
751754
$tableName,
752-
\get_called_class(),
755+
get_called_class(),
753756
$exception->getMessage()
754757
)
755758
);
@@ -764,13 +767,13 @@ public function morphTable(string $tableName, array $definition): void
764767
* TODO: Check, why schemaName is empty string.
765768
*/
766769
self::$connection->dropForeignKey($tableName, '', $referenceName);
767-
} catch (\Throwable $exception) {
770+
} catch (Throwable $exception) {
768771
throw new RuntimeException(
769772
sprintf(
770773
"Failed to drop foreign key '%s' in '%s'. In '%s' migration. DB error: %s",
771774
$referenceName,
772775
$tableName,
773-
\get_called_class(),
776+
get_called_class(),
774777
$exception->getMessage()
775778
)
776779
);
@@ -996,13 +999,13 @@ private function addPrimaryKey(string $tableName, string $schemaName, IndexInter
996999
{
9971000
try {
9981001
self::$connection->addPrimaryKey($tableName, $schemaName, $index);
999-
} catch (\Throwable $exception) {
1002+
} catch (Throwable $exception) {
10001003
throw new RuntimeException(
10011004
sprintf(
10021005
"Failed to add primary key '%s' in '%s'. In '%s' migration. DB error: %s",
10031006
$index->getName(),
10041007
$tableName,
1005-
\get_called_class(),
1008+
get_called_class(),
10061009
$exception->getMessage()
10071010
)
10081011
);
@@ -1018,12 +1021,12 @@ private function dropPrimaryKey(string $tableName, string $schemaName): void
10181021
{
10191022
try {
10201023
self::$connection->dropPrimaryKey($tableName, $schemaName);
1021-
} catch (\Throwable $exception) {
1024+
} catch (Throwable $exception) {
10221025
throw new RuntimeException(
10231026
sprintf(
10241027
"Failed to drop primary key in '%s'. In '%s' migration. DB error: %s",
10251028
$tableName,
1026-
\get_called_class(),
1029+
get_called_class(),
10271030
$exception->getMessage()
10281031
)
10291032
);
@@ -1040,13 +1043,13 @@ private function addIndex(string $tableName, string $schemaName, IndexInterface
10401043
{
10411044
try {
10421045
self::$connection->addIndex($tableName, $schemaName, $indexName);
1043-
} catch (\Throwable $exception) {
1046+
} catch (Throwable $exception) {
10441047
throw new RuntimeException(
10451048
sprintf(
10461049
"Failed to add index '%s' in '%s'. In '%s' migration. DB error: %s",
10471050
$indexName->getName(),
10481051
$tableName,
1049-
\get_called_class(),
1052+
get_called_class(),
10501053
$exception->getMessage()
10511054
)
10521055
);
@@ -1063,13 +1066,13 @@ private function dropIndex(string $tableName, string $schemaName, string $indexN
10631066
{
10641067
try {
10651068
self::$connection->dropIndex($tableName, $schemaName, $indexName);
1066-
} catch (\Throwable $exception) {
1069+
} catch (Throwable $exception) {
10671070
throw new RuntimeException(
10681071
sprintf(
10691072
"Failed to drop index '%s' in '%s'. In '%s' migration. DB error: %s",
10701073
$indexName,
10711074
$tableName,
1072-
\get_called_class(),
1075+
get_called_class(),
10731076
$exception->getMessage()
10741077
)
10751078
);

src/Mvc/Model/Migration/TableAware/ListTablesDb.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ListTablesDb implements ListTablesInterface
2424
* Get table names with prefix for running migration
2525
*
2626
* @param string $tablePrefix
27-
* @param DirectoryIterator $iterator
27+
* @param DirectoryIterator|null $iterator
2828
* @return string
2929
* @throws DbException
3030
*/
@@ -34,17 +34,14 @@ public function listTablesForPrefix(string $tablePrefix, DirectoryIterator $iter
3434
throw new InvalidArgumentException("Parameters weren't defined in " . __METHOD__);
3535
}
3636

37-
$modelMigration = new ModelMigration();
38-
$connection = $modelMigration->getConnection();
39-
40-
$tablesList = $connection->listTables();
37+
$tablesList = (new ModelMigration())->getConnection()->listTables();
4138
if (empty($tablesList)) {
4239
return '';
4340
}
4441

45-
$strlen = strlen($tablePrefix);
42+
$length = strlen($tablePrefix);
4643
foreach ($tablesList as $key => $value) {
47-
if (substr($value, 0, $strlen) != $tablePrefix) {
44+
if (substr($value, 0, $length) !== $tablePrefix) {
4845
unset($tablesList[$key]);
4946
}
5047
}

src/Mvc/Model/Migration/TableAware/ListTablesInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface ListTablesInterface
2121
* Get list table from prefix
2222
*
2323
* @param string $tablePrefix Table prefix
24-
* @param DirectoryIterator $iterator
24+
* @param DirectoryIterator|null $iterator
2525
* @return string
2626
*/
2727
public function listTablesForPrefix(string $tablePrefix, DirectoryIterator $iterator = null): string;

src/Mvc/Model/Migration/TableAware/ListTablesIterator.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,24 @@ class ListTablesIterator implements ListTablesInterface
2222
* Get table names with prefix for running migration
2323
*
2424
* @param string $tablePrefix
25-
* @param DirectoryIterator $iterator
25+
* @param DirectoryIterator|null $iterator
2626
* @return string
2727
*/
2828
public function listTablesForPrefix(string $tablePrefix, DirectoryIterator $iterator = null): string
2929
{
30-
if (empty($tablePrefix) || empty($iterator)) {
30+
if (empty($tablePrefix) || $iterator === null) {
3131
throw new InvalidArgumentException("Parameters weren't defined in " . __METHOD__);
3232
}
3333

34-
$strlen = strlen($tablePrefix);
3534
$fileNames = [];
35+
$length = strlen($tablePrefix);
3636
foreach ($iterator as $fileInfo) {
37-
if (substr($fileInfo->getFilename(), 0, $strlen) == $tablePrefix) {
37+
if (substr($fileInfo->getFilename(), 0, $length) === $tablePrefix) {
3838
$file = explode('.', $fileInfo->getFilename());
3939
$fileNames[] = $file[0];
4040
}
4141
}
4242

43-
$fileNames = array_unique($fileNames);
44-
45-
return implode(',', $fileNames);
43+
return implode(',', array_unique($fileNames));
4644
}
4745
}

0 commit comments

Comments
 (0)