Skip to content

Commit

Permalink
Merge pull request #101 from phalcon/#99-enhance-error-table-create
Browse files Browse the repository at this point in the history
#99 - Enhance error output during table morping
  • Loading branch information
Jeckerson authored Nov 2, 2020
2 parents 395f59a + 1ce7025 commit fae2739
Show file tree
Hide file tree
Showing 14 changed files with 1,241 additions and 826 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"require-dev": {
"ext-pdo": "*",
"phalcon/ide-stubs": "^4.0.0",
"vimeo/psalm": "3.6.2",
"squizlabs/php_codesniffer": "3.5.1",
"vimeo/psalm": "^4.1",
"squizlabs/php_codesniffer": "^3.5",
"fzaninotto/faker": "^1.9",
"humbug/box": "^3.8",
"codeception/codeception": "^4.1",
Expand Down
1,556 changes: 851 additions & 705 deletions composer.lock

Large diffs are not rendered by default.

52 changes: 2 additions & 50 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,63 +1,15 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
errorLevel="3"
resolveFromConfigFile="true"
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"
>
<projectFiles>
<directory name="src/" />
<file name="phalcon-migrations" />
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->

<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedClass errorLevel="info" />
<DeprecatedConstant errorLevel="info" />
<DeprecatedFunction errorLevel="info" />
<DeprecatedInterface errorLevel="info" />
<DeprecatedTrait errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />
<MissingClosureParamType errorLevel="info" />
<MissingParamType errorLevel="info" />

<RedundantCondition errorLevel="info" />

<DocblockTypeContradiction errorLevel="info" />

<UnresolvableInclude errorLevel="info" />

<!-- level 4 issues - points to possible deficiencies in logic, higher false-positives -->

<MoreSpecificReturnType errorLevel="info" />
<LessSpecificReturnStatement errorLevel="info" />
<TypeCoercion errorLevel="info" />

<PossiblyInvalidPropertyAssignmentValue errorLevel="info" />
<PossiblyNullArgument errorLevel="info" />
<PossiblyNullArrayOffset errorLevel="info" />
<PossiblyNullPropertyAssignmentValue errorLevel="info" />
<PossiblyNullReference errorLevel="info" />

<!-- level 8 issues - some fatal errors in PHP -->

<MethodSignatureMismatch errorLevel="info" />

</issueHandlers>
</psalm>
20 changes: 10 additions & 10 deletions src/Console/OptionParserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ public function getVersionNameGeneratingMigration(): ItemInterface
if (is_array($migrationsDirList)) {
foreach ($migrationsDirList as $migrationsDir) {
$migrationsSubDirList = ModelMigration::scanForVersions($migrationsDir);
if (is_array($migrationsSubDirList)) {
foreach ($migrationsSubDirList as $item) {
if ($item->getVersion() != $versionItem->getVersion()) {
continue;
}
if (!$this->options['force']) {
throw new \LogicException('Version ' . $item->getVersion() . ' already exists');
} else {
rmdir(rtrim($migrationsDir, '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion());
}

foreach ($migrationsSubDirList as $item) {
if ($item->getVersion() != $versionItem->getVersion()) {
continue;
}

if (!$this->options['force']) {
throw new \LogicException('Version ' . $item->getVersion() . ' already exists');
} else {
rmdir(rtrim($migrationsDir, '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Action/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function getReferences(bool $skipRefSchema = false): Generator
$this->wrapWithQuotes($referencedSchema)
);
}

yield $constraintName => array_merge($referencesOptions, [
sprintf("'referencedTable' => %s", $this->wrapWithQuotes($reference->getReferencedTable())),
"'columns' => [" . join(',', array_unique($referenceColumns)) . "]",
Expand Down Expand Up @@ -338,7 +338,7 @@ public function getOptions(bool $skipAI): array

$options[] = sprintf('%s => %s', $this->wrapWithQuotes($name), $this->wrapWithQuotes((string)$value));
}

return $options;
}

Expand Down
8 changes: 7 additions & 1 deletion src/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ public static function run(array $options)
$finalVersion = VersionCollection::maximum($versionItems);
}

if ($finalVersion === null) {
echo Color::info('No versions were found');
return;
}

ModelMigration::setup($optionStack->getOption('config')->database, $optionStack->getOption('verbose'));
self::connectionSetup($optionStack->getOptions());

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

if ($version = trim($version) ?: null) {
if ($version !== null) {
$version = preg_split('/\r\n|\r|\n/', $version, -1, PREG_SPLIT_NO_EMPTY);
natsort($version);
$version = array_pop($version);
Expand Down
Loading

0 comments on commit fae2739

Please sign in to comment.