| Conditions | 11 |
| Paths | 8 |
| Total Lines | 34 |
| Code Lines | 20 |
| 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 |
||
| 63 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 64 | { |
||
| 65 | $io = new SymfonyStyle($input, $output); |
||
| 66 | |||
| 67 | $resource = $input->getArgument('resource'); |
||
| 68 | $itemOperation = $input->getOption('itemOperation'); |
||
| 69 | $collectionOperation = $input->getOption('collectionOperation'); |
||
| 70 | $format = $input->getOption('format'); |
||
| 71 | $outputType = $input->getOption('output'); |
||
| 72 | |||
| 73 | if (!isset($this->formats[$format])) { |
||
| 74 | throw new InvalidOptionException(sprintf('The response format "%s" is not supported. Supported formats are : %s.', $format, implode(', ', array_keys($this->formats)))); |
||
|
|
|||
| 75 | } |
||
| 76 | |||
| 77 | $operationType = null; |
||
| 78 | $operationName = null; |
||
| 79 | |||
| 80 | if ($itemOperation && $collectionOperation) { |
||
| 81 | throw new InvalidOptionException('You can only use one of "--itemOperation" and "--collectionOperation" options at the same time.'); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (null !== $itemOperation || null !== $collectionOperation) { |
||
| 85 | $operationType = $itemOperation ? OperationType::ITEM : OperationType::COLLECTION; |
||
| 86 | $operationName = $itemOperation ?? $collectionOperation; |
||
| 87 | } |
||
| 88 | |||
| 89 | $schema = $this->schemaFactory->buildSchema($resource, $format, $outputType, $operationType, $operationName); |
||
| 90 | |||
| 91 | if (null !== $operationType && null !== $operationName && !$schema->isDefined()) { |
||
| 92 | $io->error(sprintf('There is no %s defined for the operation "%s" of the resource "%s".', $outputType ? 'outputs' : 'inputs', $operationName, $resource)); |
||
| 93 | return 1; |
||
| 94 | } |
||
| 95 | |||
| 96 | $io->text(json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
||
| 97 | } |
||
| 99 |