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

api-platform / core / 18370496742

09 Oct 2025 08:35AM UTC coverage: 0.0% (-21.9%) from 21.92%
18370496742

push

github

soyuka
docs: changelog 4.2.2

0 of 56436 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

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

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

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

56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function configureDependencies(DependencyBuilder $dependencies): void
60
    {
61
    }
×
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'));
×
71
        $type = SupportedFilterTypes::tryFrom($typeArgument);
×
72
        if (null === $type) {
×
73
            throw new InvalidArgumentException(\sprintf('The type "%s" is not a valid filter type, valid options are: %s.', $typeArgument, self::getFilterTypesAsString()));
×
74
        }
75

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

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

88
        $generator->writeChanges();
×
89

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

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

100
        return implode(' or ', array_map('strtoupper', $validOptions));
×
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