From edec5c5a2e3d62b4edb972066ef47cdf4207e030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 27 Aug 2024 18:03:38 +0200 Subject: [PATCH] Assert there is no failure The pattern is not dynamic, and we know it works. This addresses an issue reported by PHPStan. --- src/Generator/Generator.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Generator/Generator.php b/src/Generator/Generator.php index fdd19854b..1945879b2 100644 --- a/src/Generator/Generator.php +++ b/src/Generator/Generator.php @@ -9,6 +9,7 @@ use Doctrine\Migrations\Tools\Console\Helper\MigrationDirectoryHelper; use InvalidArgumentException; +use function assert; use function explode; use function file_get_contents; use function file_put_contents; @@ -74,11 +75,14 @@ public function generateMigration( string|null $up = null, string|null $down = null, ): string { - $mch = []; - if (preg_match('~(.*)\\\\([^\\\\]+)~', $fqcn, $mch) === 0) { + $mch = []; + $matchResult = preg_match('~(.*)\\\\([^\\\\]+)~', $fqcn, $mch); + if ($matchResult === 0) { throw new InvalidArgumentException(sprintf('Invalid FQCN')); } + assert($matchResult !== false); + [$fqcn, $namespace, $className] = $mch; $dirs = $this->configuration->getMigrationDirectories();