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

api-platform / core / 19799301771

30 Nov 2025 01:04PM UTC coverage: 25.229% (-0.03%) from 25.257%
19799301771

push

github

web-flow
fix(metadata): repeatable attribute mutators (#7542)

14557 of 57700 relevant lines covered (25.23%)

28.11 hits per line

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

100.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

27
final class MakeFilter extends AbstractMaker
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public static function getCommandName(): string
33
    {
34
        return 'make:filter';
8✔
35
    }
36

37
    /**
38
     * {@inheritdoc}
39
     */
40
    public static function getCommandDescription(): string
41
    {
42
        return 'Creates an API Platform filter';
8✔
43
    }
44

45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function configureCommand(Command $command, InputConfiguration $inputConfig): void
49
    {
50
        $command
16✔
51
            ->addArgument('type', InputArgument::REQUIRED, \sprintf('Choose a type for your filter (<fg=yellow>%s</>)', self::getFilterTypesAsString()))
16✔
52
            ->addArgument('name', InputArgument::REQUIRED, 'Choose a class name for your filter (e.g. <fg=yellow>AwesomeFilter</>)')
16✔
53
            ->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeFilter.txt'));
16✔
54
    }
55

56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function configureDependencies(DependencyBuilder $dependencies): void
60
    {
61
    }
16✔
62

63
    /**
64
     * {@inheritdoc}
65
     *
66
     * @throws \Exception
67
     */
68
    public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
69
    {
70
        $typeArgument = strtolower((string) $input->getArgument('type'));
12✔
71
        $type = SupportedFilterTypes::tryFrom($typeArgument);
12✔
72
        if (null === $type) {
12✔
73
            throw new InvalidArgumentException(\sprintf('The type "%s" is not a valid filter type, valid options are: %s.', $typeArgument, self::getFilterTypesAsString()));
4✔
74
        }
75

76
        $filterNameDetails = $generator->createClassNameDetails(
8✔
77
            name: $input->getArgument('name'),
8✔
78
            namespacePrefix: 'Filter\\'
8✔
79
        );
8✔
80
        $filterName = \sprintf('%sFilter', ucfirst($type->value));
8✔
81

82
        $generator->generateClass(className: $filterNameDetails->getFullName(), templateName: \sprintf(
8✔
83
            '%s/Resources/skeleton/%s.php.tpl',
8✔
84
            __DIR__,
8✔
85
            $filterName
8✔
86
        ));
8✔
87

88
        $generator->writeChanges();
8✔
89

90
        $this->writeSuccessMessage($io);
8✔
91
        $io->text([
8✔
92
            'Next: Open your filter class and start customizing it.',
8✔
93
        ]);
8✔
94
    }
95

96
    private static function getFilterTypesAsString(): string
97
    {
98
        $validOptions = array_column(SupportedFilterTypes::cases(), 'value');
16✔
99

100
        return implode(' or ', array_map('strtoupper', $validOptions));
16✔
101
    }
102
}
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