Conditions | 2 |
Paths | 1 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |
||
50 | protected function execute(InputInterface $input, OutputInterface $output) |
||
51 | { |
||
52 | $srcDir = $input->getArgument('sourceDirectory'); |
||
53 | $cacheDir = $input->getArgument('cacheDirectory'); |
||
54 | |||
55 | $clientStub = new class implements HttpClient { |
||
56 | |||
57 | /** |
||
58 | * Send a request synchronously and return a PSR-7 [@see ResponseInterface] |
||
59 | * |
||
60 | * @param RequestInterface $request |
||
61 | * @return ResponseInterface |
||
62 | */ |
||
63 | public function send(RequestInterface $request): ResponseInterface |
||
64 | { |
||
65 | return new Response(); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Send a request asynchronously |
||
70 | * |
||
71 | * The response callback must be called if any response is returned from the request, and the failure |
||
72 | * callback should only be executed if a request was not completed. |
||
73 | * |
||
74 | * The response callback should pass a PSR-7 [@see ResponseInterface] as the one and only argument. The |
||
75 | * failure callback should pass a [@see Throwable] as the one and only argument. |
||
76 | * |
||
77 | * @param RequestInterface $request |
||
78 | * @param callable $onResponse |
||
79 | * @param callable $onFailure |
||
80 | * @return void |
||
81 | */ |
||
82 | public function sendAsync(RequestInterface $request, callable $onResponse, callable $onFailure): void |
||
83 | { |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Calling this method should execute any enqueued requests asynchronously |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | public function wait(): void |
||
92 | { |
||
93 | } |
||
94 | }; |
||
95 | |||
96 | $retrofit = Retrofit::builder() |
||
97 | ->setBaseUrl('') |
||
98 | ->setHttpClient($clientStub) |
||
99 | ->setCacheDir($cacheDir) |
||
|
|||
100 | ->enableCache() |
||
101 | ->build(); |
||
102 | $count = $retrofit->createAll($srcDir); |
||
103 | |||
104 | $output->writeln(sprintf('<info>Compiled %s %s successfully</info>', $count, ($count === 1) ? 'class' : 'classes')); |
||
105 | } |
||
106 | } |
||
107 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.