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

api-platform / core / 19171073905

07 Nov 2025 02:17PM UTC coverage: 0.0% (-24.3%) from 24.303%
19171073905

push

github

web-flow
feat(symfony): allow symfony makers namespace configuration (#7497)

0 of 19 new or added lines in 6 files covered. (0.0%)

14716 existing lines in 467 files now uncovered.

0 of 56762 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/Symfony/Maker/MakeFilter.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Symfony\Maker;
15

16
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17
use ApiPlatform\Symfony\Maker\Enum\SupportedFilterTypes;
18
use Symfony\Bundle\MakerBundle\ConsoleStyle;
19
use Symfony\Bundle\MakerBundle\DependencyBuilder;
20
use Symfony\Bundle\MakerBundle\Generator;
21
use Symfony\Bundle\MakerBundle\InputConfiguration;
22
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
23
use Symfony\Component\Console\Command\Command;
24
use Symfony\Component\Console\Input\InputArgument;
25
use Symfony\Component\Console\Input\InputInterface;
26
use Symfony\Component\Console\Input\InputOption;
27

28
final class MakeFilter extends AbstractMaker
29
{
30
    public function __construct(private readonly string $namespacePrefix = '')
31
    {
NEW
32
    }
×
33

34
    /**
35
     * {@inheritdoc}
36
     */
37
    public static function getCommandName(): string
38
    {
UNCOV
39
        return 'make:filter';
×
40
    }
41

42
    /**
43
     * {@inheritdoc}
44
     */
45
    public static function getCommandDescription(): string
46
    {
UNCOV
47
        return 'Creates an API Platform filter';
×
48
    }
49

50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function configureCommand(Command $command, InputConfiguration $inputConfig): void
54
    {
UNCOV
55
        $command
×
UNCOV
56
            ->addArgument('type', InputArgument::REQUIRED, \sprintf('Choose a type for your filter (<fg=yellow>%s</>)', self::getFilterTypesAsString()))
×
UNCOV
57
            ->addArgument('name', InputArgument::REQUIRED, 'Choose a class name for your filter (e.g. <fg=yellow>AwesomeFilter</>)')
×
NEW
58
            ->addOption('namespace-prefix', 'p', InputOption::VALUE_REQUIRED, 'Specify the namespace prefix to use for the filter class', $this->namespacePrefix.'Filter')
×
UNCOV
59
            ->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeFilter.txt'));
×
60
    }
61

62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function configureDependencies(DependencyBuilder $dependencies): void
66
    {
UNCOV
67
    }
×
68

69
    /**
70
     * {@inheritdoc}
71
     *
72
     * @throws \Exception
73
     */
74
    public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
75
    {
UNCOV
76
        $typeArgument = strtolower((string) $input->getArgument('type'));
×
UNCOV
77
        $type = SupportedFilterTypes::tryFrom($typeArgument);
×
UNCOV
78
        if (null === $type) {
×
UNCOV
79
            throw new InvalidArgumentException(\sprintf('The type "%s" is not a valid filter type, valid options are: %s.', $typeArgument, self::getFilterTypesAsString()));
×
80
        }
81

UNCOV
82
        $filterNameDetails = $generator->createClassNameDetails(
×
UNCOV
83
            name: $input->getArgument('name'),
×
NEW
84
            namespacePrefix: trim($input->getOption('namespace-prefix'), '\\').'\\'
×
UNCOV
85
        );
×
UNCOV
86
        $filterName = \sprintf('%sFilter', ucfirst($type->value));
×
87

UNCOV
88
        $generator->generateClass(className: $filterNameDetails->getFullName(), templateName: \sprintf(
×
UNCOV
89
            '%s/Resources/skeleton/%s.php.tpl',
×
UNCOV
90
            __DIR__,
×
UNCOV
91
            $filterName
×
UNCOV
92
        ));
×
93

UNCOV
94
        $generator->writeChanges();
×
95

UNCOV
96
        $this->writeSuccessMessage($io);
×
UNCOV
97
        $io->text([
×
UNCOV
98
            'Next: Open your filter class and start customizing it.',
×
UNCOV
99
        ]);
×
100
    }
101

102
    private static function getFilterTypesAsString(): string
103
    {
UNCOV
104
        $validOptions = array_column(SupportedFilterTypes::cases(), 'value');
×
105

UNCOV
106
        return implode(' or ', array_map('strtoupper', $validOptions));
×
107
    }
108
}
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