Conditions | 19 |
Paths | 1 |
Total Lines | 71 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
27 | protected function execute(InputInterface $input, OutputInterface $output) |
||
28 | { |
||
29 | $test = new TestSkeleton(); |
||
30 | $test->configureDi(); |
||
31 | $api = $test->get('Magium\Util\Api\ApiConfiguration'); |
||
32 | /* @var $api ApiConfiguration */ |
||
33 | $api->setEnabled(true); // Gotta force this for this test |
||
34 | |||
35 | $output->writeln('Sending un-authenticated payload...'); |
||
36 | $client = new Client('http://' . $api->getApiHostname(). '/api/ping'); |
||
37 | $request = $client->get(); |
||
38 | $response = $request->send(); |
||
39 | $output->writeln( |
||
40 | 'Checking for 200 status message... ' |
||
41 | . ($response->getStatusCode() == '200'?'OK':'Failed') |
||
42 | ); |
||
43 | $output->writeln( |
||
44 | 'Checking for application/json content type... ' |
||
45 | . (stripos($response->getContentType(), 'application/json') !== false?'OK':'Failed') |
||
46 | ); |
||
47 | $content = json_decode($response->getBody(), true); |
||
48 | $output->writeln( |
||
49 | 'Checking for successful response... ' |
||
50 | . (is_array($content) && isset($content['status']) && $content['status'] === 'success'?'OK':'Failed') |
||
51 | ); |
||
52 | |||
53 | $output->writeln(''); |
||
54 | $output->writeln('Attempting authenticated ping...'); |
||
55 | |||
56 | $request = $test->get('Magium\Util\Api\Request'); |
||
57 | /* @var $request \Magium\Util\Api\Request */ |
||
58 | $response = $request->fetch('/api/ping-authed'); |
||
59 | |||
60 | $output->writeln( |
||
61 | 'Checking for 200 status message... ' |
||
62 | . ($response->getStatusCode() == '200'?'OK':'Failed') |
||
63 | ); |
||
64 | $output->writeln( |
||
65 | 'Checking for application/json content type... ' |
||
66 | . (stripos($response->getContentType(), 'application/json') !== false?'OK':'Failed') |
||
67 | ); |
||
68 | $content = $request->getPayload($response); |
||
|
|||
69 | $output->writeln( |
||
70 | 'Checking for successful response... ' |
||
71 | . (is_array($content) && isset($content['status']) && $content['status'] === 'success'?'OK':'Failed') |
||
72 | ); |
||
73 | |||
74 | |||
75 | $output->writeln(''); |
||
76 | $output->writeln('Attempting authenticated echo...'); |
||
77 | $request = $test->get('Magium\Util\Api\Request'); |
||
78 | /* @var $request \Magium\Util\Api\Request */ |
||
79 | $response = $request->push('/api/echo-authed', ['message' => 'hello world']); |
||
80 | $output->writeln( |
||
81 | 'Checking for 200 status message... ' |
||
82 | . ($response->getStatusCode() == '200'?'OK':'Failed') |
||
83 | ); |
||
84 | $output->writeln( |
||
85 | 'Checking for application/json content type... ' |
||
86 | . (stripos($response->getContentType(), 'application/json') !== false?'OK':'Failed') |
||
87 | ); |
||
88 | $content = $request->getPayload($response); |
||
89 | $output->writeln( |
||
90 | 'Checking for successful response... ' |
||
91 | . (is_array($content) && isset($content['status']) && $content['status'] === 'success'?'OK':'Failed') |
||
92 | ); |
||
93 | $output->writeln( |
||
94 | 'Checking for matching echo message... ' |
||
95 | . (is_array($content) && isset($content['message']) && $content['message'] === 'hello world'?'OK':'Failed') |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | } |
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.