Conditions | 11 |
Paths | 3 |
Total Lines | 21 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 11.055 |
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 |
||
15 | 1 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null): SyncOptions |
|
16 | { |
||
17 | 1 | $reader = new Json(); |
|
18 | 1 | $config = $reader->fromFile(__DIR__ . '/../../../../config.json'); |
|
19 | |||
20 | 1 | if ((!isset($config['jiraUsername']) || empty($config['jiraUsername'])) || |
|
21 | 1 | (!isset($config['jiraPassword']) || empty($config['jiraPassword'])) || |
|
22 | 1 | (!isset($config['togglApiKey']) || empty($config['togglApiKey'])) || |
|
23 | 1 | (!isset($config['jiraUrl']) || empty($config['jiraUrl'])) |
|
24 | ) { |
||
25 | throw new \RuntimeException('Invalid config.json, please fill out everything except lastSync'); |
||
26 | } |
||
27 | |||
28 | 1 | if (isset($config['lastSync']['date']) && isset($config['lastSync']['timezone'])) { |
|
29 | 1 | $config['lastSync'] = new \DateTimeImmutable( |
|
30 | 1 | $config['lastSync']['date'], |
|
31 | 1 | new \DateTimeZone($config['lastSync']['timezone']) |
|
32 | ); |
||
33 | } |
||
34 | |||
35 | 1 | return new SyncOptions($config); |
|
36 | } |
||
38 |