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

api-platform / core / 18223414080

03 Oct 2025 01:18PM UTC coverage: 0.0% (-22.0%) from 21.956%
18223414080

Pull #7397

github

web-flow
Merge 69d085182 into 0b8237918
Pull Request #7397: fix(jsonschema/jsonld): make `@id` and `@type` properties required only in the JSON-LD schema for output

0 of 18 new or added lines in 2 files covered. (0.0%)

12304 existing lines in 405 files now uncovered.

0 of 53965 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/Bundle/Command/DebugResourceCommand.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\Bundle\Command;
15

16
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
17
use Symfony\Component\Console\Attribute\AsCommand;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Helper\QuestionHelper;
20
use Symfony\Component\Console\Input\InputArgument;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Output\OutputInterface;
23
use Symfony\Component\Console\Question\ChoiceQuestion;
24
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
25
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
26

27
#[AsCommand(name: 'debug:api-resource')]
28
final class DebugResourceCommand extends Command
29
{
30
    /**
31
     * @param DataDumperInterface $dumper
32
     */
33
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly ClonerInterface $cloner, private $dumper)
34
    {
UNCOV
35
        parent::__construct();
×
36
    }
37

38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function configure(): void
42
    {
UNCOV
43
        $this
×
UNCOV
44
            ->setDescription('Debug API Platform resources')
×
UNCOV
45
            ->addArgument('class', InputArgument::REQUIRED, 'The class you want to debug');
×
46
    }
47

48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected function execute(InputInterface $input, OutputInterface $output): int
52
    {
UNCOV
53
        $resourceClass = $input->getArgument('class');
×
54

UNCOV
55
        $resourceCollection = $this->resourceMetadataCollectionFactory->create($resourceClass);
×
56

UNCOV
57
        if (0 === \count($resourceCollection)) {
×
58
            $output->writeln(\sprintf('<error>No resources found for class %s</error>', $resourceClass));
×
59

60
            return \defined(Command::class.'::INVALID') ? Command::INVALID : 2;
×
61
        }
62

UNCOV
63
        $shortName = (false !== $pos = strrpos($resourceClass, '\\')) ? substr($resourceClass, $pos + 1) : $resourceClass;
×
64

65
        /** @var QuestionHelper $helper */
UNCOV
66
        $helper = $this->getHelper('question');
×
67

UNCOV
68
        $resources = [];
×
UNCOV
69
        foreach ($resourceCollection as $resource) {
×
UNCOV
70
            if ($resource->getUriTemplate()) {
×
UNCOV
71
                $resources[] = ($resource->getRoutePrefix() ?? '').$resource->getUriTemplate();
×
UNCOV
72
                continue;
×
73
            }
74

UNCOV
75
            foreach ($resource->getOperations() as $operation) {
×
UNCOV
76
                if ($operation->getUriTemplate()) {
×
UNCOV
77
                    $resources[] = ($resource->getRoutePrefix() ?? '').$operation->getUriTemplate();
×
UNCOV
78
                    break;
×
79
                }
80
            }
81
        }
82

UNCOV
83
        if (\count($resourceCollection) > 1) {
×
UNCOV
84
            $questionResource = new ChoiceQuestion(
×
UNCOV
85
                \sprintf('There are %d resources declared on the class %s, which one do you want to debug ? ', \count($resourceCollection), $shortName).\PHP_EOL,
×
UNCOV
86
                $resources
×
UNCOV
87
            );
×
88

UNCOV
89
            $answerResource = $helper->ask($input, $output, $questionResource);
×
UNCOV
90
            $resourceIndex = array_search($answerResource, $resources, true);
×
UNCOV
91
            $selectedResource = $resourceCollection[$resourceIndex];
×
92
        } else {
UNCOV
93
            $selectedResource = $resourceCollection[0];
×
UNCOV
94
            $output->writeln(\sprintf('Class %s declares 1 resource.', $shortName).\PHP_EOL);
×
95
        }
96

UNCOV
97
        $operations = ['Debug the resource itself'];
×
UNCOV
98
        foreach ($selectedResource->getOperations() as $operationName => $operation) {
×
UNCOV
99
            $operations[] = $operationName;
×
100
        }
101

UNCOV
102
        $questionOperation = new ChoiceQuestion(
×
UNCOV
103
            \sprintf('There are %d operation%s declared on the resource, which one do you want to debug ? ', $selectedResource->getOperations()->count(), $selectedResource->getOperations()->count() > 1 ? 's' : '').\PHP_EOL,
×
UNCOV
104
            $operations
×
UNCOV
105
        );
×
106

UNCOV
107
        $answerOperation = $helper->ask($input, $output, $questionOperation);
×
UNCOV
108
        if ('Debug the resource itself' === $answerOperation) {
×
UNCOV
109
            $this->dumper->dump($this->cloner->cloneVar($selectedResource));
×
UNCOV
110
            $output->writeln('Successfully dumped the selected resource');
×
111

UNCOV
112
            return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0;
×
113
        }
114

UNCOV
115
        $this->dumper->dump($this->cloner->cloneVar($resourceCollection->getOperation($answerOperation)));
×
UNCOV
116
        $output->writeln('Successfully dumped the selected operation');
×
117

UNCOV
118
        return \defined(Command::class.'::SUCCESS') ? Command::SUCCESS : 0;
×
119
    }
120
}
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

© 2025 Coveralls, Inc