Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert there is no failure #1453

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had the same problem in DBAL. If you change this check to…

if ($matchResult !== 1) {

… you should not need the assert. Alternatively, we could think about using the composer/pcre library which has a saner API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derrabus that's the solution I went first at first, but then I felt wrong because there's a tiny chance that false might occur and misdiagnose it as an invalid FQCN. composer/pcre might indeed be a good solution.

throw new InvalidArgumentException(sprintf('Invalid FQCN'));
}

assert($matchResult !== false);

[$fqcn, $namespace, $className] = $mch;

$dirs = $this->configuration->getMigrationDirectories();
Expand Down
Loading