Conditions | 13 |
Paths | 10 |
Total Lines | 51 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 | |||
69 | if (!is_string($resource)) { |
||
70 | $io->error('The provided resource cannot be processed.'); |
||
71 | |||
72 | return 1; |
||
73 | } |
||
74 | |||
75 | $itemOperation = $input->getOption('itemOperation'); |
||
76 | $collectionOperation = $input->getOption('collectionOperation'); |
||
77 | |||
78 | $format = $input->getOption('format'); |
||
79 | |||
80 | $outputType = $input->getOption('output'); |
||
81 | |||
82 | if (!is_string($format)) { |
||
83 | $io->error('The provided format needs to be a valid string.'); |
||
84 | |||
85 | return 1; |
||
86 | } |
||
87 | |||
88 | if (!in_array($format, $this->formats, true)) { |
||
89 | |||
90 | throw new InvalidOptionException(sprintf('The response format "%s" is not supported. Supported formats are : %s.', $format, (string) implode(', ', $this->formats))); |
||
91 | } |
||
92 | |||
93 | $operationType = null; |
||
94 | $operationName = null; |
||
95 | |||
96 | if ($itemOperation && $collectionOperation) { |
||
97 | throw new InvalidOptionException('You can only use one of "--itemOperation" and "--collectionOperation" options at the same time.'); |
||
98 | } |
||
99 | |||
100 | if (null !== $itemOperation || null !== $collectionOperation) { |
||
101 | $operationType = $itemOperation ? OperationType::ITEM : OperationType::COLLECTION; |
||
102 | $operationName = $itemOperation ?? $collectionOperation; |
||
103 | } |
||
104 | |||
105 | $schema = $this->schemaFactory->buildSchema($resource, $format, (bool) $outputType, $operationType, $operationName); |
||
106 | |||
107 | if (null !== $operationType && null !== $operationName && !$schema->isDefined()) { |
||
108 | $io->error(sprintf('There is no %s defined for the operation "%s" of the resource "%s".', $outputType ? 'outputs' : 'inputs', $operationName, $resource)); |
||
|
|||
109 | |||
110 | return 1; |
||
111 | } |
||
112 | |||
113 | $io->text((string) json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
||
114 | } |
||
116 |