Conditions | 11 |
Paths | 9 |
Total Lines | 52 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
62 | protected function execute(InputInterface $input, OutputInterface $output) |
||
63 | { |
||
64 | $io = new SymfonyStyle($input, $output); |
||
65 | |||
66 | /** @var string $resource */ |
||
67 | $resource = $input->getArgument('resource'); |
||
68 | /** @var ?string $itemOperation */ |
||
69 | $itemOperation = $input->getOption('itemOperation'); |
||
70 | /** @var ?string $collectionOperation */ |
||
71 | $collectionOperation = $input->getOption('collectionOperation'); |
||
72 | /** @var string $format */ |
||
73 | $format = $input->getOption('format'); |
||
74 | /** @var string $outputType */ |
||
75 | $outputType = $input->getOption('type'); |
||
76 | |||
77 | if (!\in_array($outputType, ['input', 'output'], true)) { |
||
78 | $io->error('You can only use "input" or "output" for the "type" option'); |
||
79 | |||
80 | return 1; |
||
81 | } |
||
82 | |||
83 | if (!\in_array($format, $this->formats, true)) { |
||
84 | throw new InvalidOptionException(sprintf('The response format "%s" is not supported. Supported formats are : %s.', $format, implode(', ', $this->formats))); |
||
85 | } |
||
86 | |||
87 | /** @var ?string $operationType */ |
||
88 | $operationType = null; |
||
89 | /** @var ?string $operationName */ |
||
90 | $operationName = null; |
||
91 | |||
92 | if ($itemOperation && $collectionOperation) { |
||
93 | $io->error('You can only use one of "--itemOperation" and "--collectionOperation" options at the same time.'); |
||
94 | |||
95 | return 1; |
||
96 | } |
||
97 | |||
98 | if (null !== $itemOperation || null !== $collectionOperation) { |
||
99 | $operationType = $itemOperation ? OperationType::ITEM : OperationType::COLLECTION; |
||
100 | $operationName = $itemOperation ?? $collectionOperation; |
||
101 | } |
||
102 | |||
103 | $schema = $this->schemaFactory->buildSchema($resource, $format, 'output' === $outputType, $operationType, $operationName); |
||
104 | |||
105 | if (null !== $operationType && null !== $operationName && !$schema->isDefined()) { |
||
106 | $io->error(sprintf('There is no %ss defined for the operation "%s" of the resource "%s".', $outputType, $operationName, $resource)); |
||
107 | |||
108 | return 1; |
||
109 | } |
||
110 | |||
111 | $io->text((string) json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
||
112 | |||
113 | return 0; |
||
114 | } |
||
116 |