Skip to content

Commit

Permalink
Fix psalm/phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 8, 2024
1 parent 775f697 commit 8b24b23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
11 changes: 11 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
<code>is_array($newColumns)</code>
</RedundantCondition>
</file>
<file src="src/Migration/Manager.php">
<ArgumentTypeCoercion>
<code>array_merge($versions, array_keys($migrations))</code>
</ArgumentTypeCoercion>
<RedundantCondition>
<code>$migrations</code>
</RedundantCondition>
<ReferenceReusedFromConfusingScope>
<code>$executedVersion</code>
</ReferenceReusedFromConfusingScope>
</file>
<file src="src/TableFinderTrait.php">
<PossiblyUndefinedArrayOffset>
<code>$split[0]</code>
Expand Down
24 changes: 11 additions & 13 deletions src/Migration/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class Manager
protected ?array $seeds = null;

/**
* @var \Psr\Container\ContainerInterface
* @var \Psr\Container\ContainerInterface|null
*/
protected ContainerInterface $container;
protected ?ContainerInterface $container;

/**
* @var int
Expand Down Expand Up @@ -159,7 +159,7 @@ public function printStatus(string $environment, ?string $format = null): array

// any migration left in the migrations (ie. not unset when sorting the migrations by the version order) is
// a migration that is down, so we add them to the end of the sorted migrations list
if (!empty($migrations)) {
if ($migrations) {
$sortedMigrations = array_merge($sortedMigrations, $migrations);
}

Expand Down Expand Up @@ -236,7 +236,7 @@ public function printStatus(string $environment, ?string $format = null): array
switch ($format) {
case AbstractCommand::FORMAT_JSON:
$output->setVerbosity($verbosity);
$output->writeln(json_encode(
$output->writeln((string)json_encode(
[
'pending_count' => $pendingMigrationCount,
'missing_count' => $missingCount,
Expand Down Expand Up @@ -847,7 +847,7 @@ function ($phpFile) {
$this->setMigrations($versions);
}

return $this->migrations;
return (array)$this->migrations;
}

/**
Expand Down Expand Up @@ -883,7 +883,7 @@ protected function getSeedDependenciesInstances(SeedInterface $seed): array
{
$dependenciesInstances = [];
$dependencies = $seed->getDependencies();
if (!empty($dependencies)) {
if (!empty($dependencies) && !empty($this->seeds)) {
foreach ($dependencies as $dependency) {
foreach ($this->seeds as $seed) {
if (get_class($seed) === $dependency) {
Expand Down Expand Up @@ -955,20 +955,17 @@ public function getSeeds(string $environment): array

// instantiate it
/** @var \Phinx\Seed\AbstractSeed $seed */
if (isset($this->container)) {
if ($this->container) {
$seed = $this->container->get($class);
} else {
$seed = new $class();
}
$seed->setEnvironment($environment);
$input = $this->getInput();
if ($input !== null) {
$seed->setInput($input);
}
$seed->setInput($input);

$output = $this->getOutput();
if ($output !== null) {
$seed->setOutput($output);
}
$seed->setOutput($output);

if (!($seed instanceof AbstractSeed)) {
throw new InvalidArgumentException(sprintf(
Expand All @@ -986,6 +983,7 @@ public function getSeeds(string $environment): array
$this->setSeeds($seeds);
}

assert(!empty($this->seeds), 'seeds must be set');
$this->seeds = $this->orderSeedsByDependencies($this->seeds);

return $this->seeds;
Expand Down

0 comments on commit 8b24b23

Please sign in to comment.