Skip to content

Commit fae2739

Browse files
authored
Merge pull request #101 from phalcon/#99-enhance-error-table-create
#99 - Enhance error output during table morping
2 parents 395f59a + 1ce7025 commit fae2739

File tree

14 files changed

+1241
-826
lines changed

14 files changed

+1241
-826
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"require-dev": {
3434
"ext-pdo": "*",
3535
"phalcon/ide-stubs": "^4.0.0",
36-
"vimeo/psalm": "3.6.2",
37-
"squizlabs/php_codesniffer": "3.5.1",
36+
"vimeo/psalm": "^4.1",
37+
"squizlabs/php_codesniffer": "^3.5",
3838
"fzaninotto/faker": "^1.9",
3939
"humbug/box": "^3.8",
4040
"codeception/codeception": "^4.1",

composer.lock

+851-705
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm.xml.dist

+2-50
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,15 @@
11
<?xml version="1.0"?>
22
<psalm
3-
totallyTyped="false"
3+
errorLevel="3"
44
resolveFromConfigFile="true"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
88
>
99
<projectFiles>
10-
<directory name="src/" />
11-
<file name="phalcon-migrations" />
10+
<directory name="src" />
1211
<ignoreFiles>
1312
<directory name="vendor" />
1413
</ignoreFiles>
1514
</projectFiles>
16-
17-
<issueHandlers>
18-
<LessSpecificReturnType errorLevel="info" />
19-
20-
<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->
21-
22-
<DeprecatedMethod errorLevel="info" />
23-
<DeprecatedProperty errorLevel="info" />
24-
<DeprecatedClass errorLevel="info" />
25-
<DeprecatedConstant errorLevel="info" />
26-
<DeprecatedFunction errorLevel="info" />
27-
<DeprecatedInterface errorLevel="info" />
28-
<DeprecatedTrait errorLevel="info" />
29-
30-
<MissingClosureReturnType errorLevel="info" />
31-
<MissingReturnType errorLevel="info" />
32-
<MissingPropertyType errorLevel="info" />
33-
<InvalidDocblock errorLevel="info" />
34-
<MisplacedRequiredParam errorLevel="info" />
35-
36-
<PropertyNotSetInConstructor errorLevel="info" />
37-
<MissingClosureParamType errorLevel="info" />
38-
<MissingParamType errorLevel="info" />
39-
40-
<RedundantCondition errorLevel="info" />
41-
42-
<DocblockTypeContradiction errorLevel="info" />
43-
44-
<UnresolvableInclude errorLevel="info" />
45-
46-
<!-- level 4 issues - points to possible deficiencies in logic, higher false-positives -->
47-
48-
<MoreSpecificReturnType errorLevel="info" />
49-
<LessSpecificReturnStatement errorLevel="info" />
50-
<TypeCoercion errorLevel="info" />
51-
52-
<PossiblyInvalidPropertyAssignmentValue errorLevel="info" />
53-
<PossiblyNullArgument errorLevel="info" />
54-
<PossiblyNullArrayOffset errorLevel="info" />
55-
<PossiblyNullPropertyAssignmentValue errorLevel="info" />
56-
<PossiblyNullReference errorLevel="info" />
57-
58-
<!-- level 8 issues - some fatal errors in PHP -->
59-
60-
<MethodSignatureMismatch errorLevel="info" />
61-
62-
</issueHandlers>
6315
</psalm>

src/Console/OptionParserTrait.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ public function getVersionNameGeneratingMigration(): ItemInterface
6767
if (is_array($migrationsDirList)) {
6868
foreach ($migrationsDirList as $migrationsDir) {
6969
$migrationsSubDirList = ModelMigration::scanForVersions($migrationsDir);
70-
if (is_array($migrationsSubDirList)) {
71-
foreach ($migrationsSubDirList as $item) {
72-
if ($item->getVersion() != $versionItem->getVersion()) {
73-
continue;
74-
}
75-
if (!$this->options['force']) {
76-
throw new \LogicException('Version ' . $item->getVersion() . ' already exists');
77-
} else {
78-
rmdir(rtrim($migrationsDir, '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion());
79-
}
70+
71+
foreach ($migrationsSubDirList as $item) {
72+
if ($item->getVersion() != $versionItem->getVersion()) {
73+
continue;
74+
}
75+
76+
if (!$this->options['force']) {
77+
throw new \LogicException('Version ' . $item->getVersion() . ' already exists');
78+
} else {
79+
rmdir(rtrim($migrationsDir, '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion());
8080
}
8181
}
8282
}

src/Migration/Action/Generate.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public function getReferences(bool $skipRefSchema = false): Generator
309309
$this->wrapWithQuotes($referencedSchema)
310310
);
311311
}
312-
312+
313313
yield $constraintName => array_merge($referencesOptions, [
314314
sprintf("'referencedTable' => %s", $this->wrapWithQuotes($reference->getReferencedTable())),
315315
"'columns' => [" . join(',', array_unique($referenceColumns)) . "]",
@@ -338,7 +338,7 @@ public function getOptions(bool $skipAI): array
338338

339339
$options[] = sprintf('%s => %s', $this->wrapWithQuotes($name), $this->wrapWithQuotes((string)$value));
340340
}
341-
341+
342342
return $options;
343343
}
344344

src/Migrations.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ public static function run(array $options)
270270
$finalVersion = VersionCollection::maximum($versionItems);
271271
}
272272

273+
if ($finalVersion === null) {
274+
echo Color::info('No versions were found');
275+
return;
276+
}
277+
273278
ModelMigration::setup($optionStack->getOption('config')->database, $optionStack->getOption('verbose'));
274279
self::connectionSetup($optionStack->getOptions());
275280

@@ -581,8 +586,9 @@ public static function getCurrentVersion($options)
581586
} else {
582587
// Get and clean migration
583588
$version = file_exists(self::$storage) ? file_get_contents(self::$storage) : null;
589+
$version = $version ? trim($version) : null;
584590

585-
if ($version = trim($version) ?: null) {
591+
if ($version !== null) {
586592
$version = preg_split('/\r\n|\r|\n/', $version, -1, PREG_SPLIT_NO_EMPTY);
587593
natsort($version);
588594
$version = array_pop($version);

0 commit comments

Comments
 (0)