• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

valksor / php-doctrine-tools / 21323315897

28 Dec 2025 12:41AM UTC coverage: 6.965% (-16.9%) from 23.881%
21323315897

push

github

k0d3r1s
funding coffee

14 of 201 relevant lines covered (6.97%)

0.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/EventSubscriber/DoctrineMigrationsFilter.php
1
<?php declare(strict_types = 1);
2

3
/*
4
 * This file is part of the Valksor package.
5
 *
6
 * (c) Davis Zalitis (k0d3r1s)
7
 * (c) SIA Valksor <packages@valksor.com>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

13
namespace Valksor\Component\DoctrineTools\EventSubscriber;
14

15
use Doctrine\DBAL\Schema\AbstractAsset;
16
use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration;
17
use Doctrine\Migrations\Tools\Console\Command\DoctrineCommand;
18
use Symfony\Component\Console\ConsoleEvents;
19
use Symfony\Component\Console\Event\ConsoleCommandEvent;
20
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
21
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
22
use Valksor\Functions\Local;
23

24
#[AutoconfigureTag('doctrine.dbal.schema_filter')]
25
class DoctrineMigrationsFilter implements EventSubscriberInterface
26
{
27
    private bool $enabled = true;
28

29
    public function __invoke(
30
        AbstractAsset|string $asset,
31
    ): bool {
32
        if (!$this->enabled) {
×
33
            return true;
×
34
        }
35

36
        static $_helper = null;
×
37

38
        if (null === $_helper) {
×
39
            $_helper = new class {
×
40
                use Local\Traits\_Exists;
41
            };
×
42
        }
43

44
        if (!$_helper->exists(TableMetadataStorageConfiguration::class)) {
×
45
            return true;
×
46
        }
47

48
        if ($asset instanceof AbstractAsset) {
×
49
            $asset = $asset->getName();
×
50
        }
51

52
        return $asset !== new TableMetadataStorageConfiguration()->getTableName();
×
53
    }
54

55
    public function onConsoleCommand(
56
        ConsoleCommandEvent $event,
57
    ): void {
58
        $command = $event->getCommand();
×
59

60
        if (null === $command) {
×
61
            return;
×
62
        }
63

64
        /*
65
         * Any console commands from the Doctrine Migrations bundle may attempt
66
         * to initialize migrations information storage table. Because of this
67
         * they should not be affected by this filter because their logic may
68
         * get broken since they will not "see" the table, they may try to use
69
         */
70
        if ($command instanceof DoctrineCommand) {
×
71
            $this->enabled = false;
×
72
        }
73
    }
74

75
    public static function getSubscribedEvents(): array
76
    {
77
        return [
×
78
            ConsoleEvents::COMMAND => 'onConsoleCommand',
×
79
        ];
×
80
    }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc