| Conditions | 6 |
| Paths | 8 |
| Total Lines | 75 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 50 | public function wire(ContainerInterface $dic) |
||
| 51 | { |
||
| 52 | if (empty($dic['Yapeal.Network.Client'])) { |
||
| 53 | $dic['Yapeal.Network.Client'] = function ($dic) { |
||
| 54 | $appComment = $dic['Yapeal.Network.appComment']; |
||
| 55 | $appName = $dic['Yapeal.Network.appName']; |
||
| 56 | $appVersion = $dic['Yapeal.Network.appVersion']; |
||
| 57 | if ('' === $appName) { |
||
| 58 | $appComment = ''; |
||
| 59 | $appVersion = ''; |
||
| 60 | } |
||
| 61 | $userAgent = trim(str_replace([ |
||
| 62 | '{machineType}', |
||
| 63 | '{osName}', |
||
| 64 | '{osRelease}', |
||
| 65 | '{phpVersion}', |
||
| 66 | '{appComment}', |
||
| 67 | '{appName}', |
||
| 68 | '{appVersion}' |
||
| 69 | ], [ |
||
| 70 | php_uname('m'), |
||
| 71 | php_uname('s'), |
||
| 72 | php_uname('r'), |
||
| 73 | PHP_VERSION, |
||
| 74 | $appComment, |
||
| 75 | $appName, |
||
| 76 | $appVersion |
||
| 77 | ], $dic['Yapeal.Network.userAgent']) |
||
| 78 | ); |
||
| 79 | $userAgent = ltrim($userAgent, '/ '); |
||
| 80 | $headers = [ |
||
| 81 | 'Accept' => $dic['Yapeal.Network.Headers.Accept'], |
||
| 82 | 'Accept-Charset' => $dic['Yapeal.Network.Headers.Accept-Charset'], |
||
| 83 | 'Accept-Encoding' => $dic['Yapeal.Network.Headers.Accept-Encoding'], |
||
| 84 | 'Accept-Language' => $dic['Yapeal.Network.Headers.Accept-Language'], |
||
| 85 | 'Connection' => $dic['Yapeal.Network.Headers.Connection'], |
||
| 86 | 'Keep-Alive' => $dic['Yapeal.Network.Headers.Keep-Alive'] |
||
| 87 | ]; |
||
| 88 | // Clean up any extra spaces and EOL chars from Yaml. |
||
| 89 | array_walk($headers, function (&$value) { |
||
| 90 | /** @noinspection ReferenceMismatchInspection */ |
||
| 91 | return trim(str_replace(' ', '', $value)); |
||
| 92 | }); |
||
| 93 | if ('' !== $userAgent) { |
||
| 94 | $headers['User-Agent'] = $userAgent; |
||
| 95 | } |
||
| 96 | $defaults = [ |
||
| 97 | 'base_uri' => $dic['Yapeal.Network.baseUrl'], |
||
| 98 | 'connect_timeout' => (int)$dic['Yapeal.Network.connect_timeout'], |
||
| 99 | 'headers' => $headers, |
||
| 100 | 'timeout' => (int)$dic['Yapeal.Network.timeout'], |
||
| 101 | 'verify' => $dic['Yapeal.Network.verify'] |
||
| 102 | ]; |
||
| 103 | return new $dic['Yapeal.Network.class']($defaults); |
||
| 104 | }; |
||
| 105 | } |
||
| 106 | if (empty($dic['Yapeal.Network.Retriever'])) { |
||
| 107 | $dic['Yapeal.Network.Retriever'] = function ($dic) { |
||
| 108 | return new GuzzleNetworkRetriever($dic['Yapeal.Network.Client']); |
||
| 109 | }; |
||
| 110 | } |
||
| 111 | if (!isset($dic['Yapeal.Event.Mediator'])) { |
||
| 112 | $mess = 'Tried to call Mediator before it has been added'; |
||
| 113 | throw new \LogicException($mess); |
||
| 114 | } |
||
| 115 | /** |
||
| 116 | * @var \Yapeal\Event\MediatorInterface $mediator |
||
| 117 | */ |
||
| 118 | $mediator = $dic['Yapeal.Event.Mediator']; |
||
| 119 | $mediator->addServiceSubscriberByEventList( |
||
| 120 | 'Yapeal.Network.Retriever', |
||
| 121 | ['Yapeal.EveApi.retrieve' => ['retrieveEveApi', 'last']] |
||
| 122 | ); |
||
| 123 | return $this; |
||
| 124 | } |
||
| 125 | } |
||
| 126 |