| Conditions | 9 |
| Paths | 97 |
| Total Lines | 63 |
| Code Lines | 39 |
| 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 |
||
| 64 | public function create(Message $message) |
||
| 65 | { |
||
| 66 | try { |
||
| 67 | $response = $this->client->request('key.search', [ |
||
| 68 | 'project_id' => $this->projectId, |
||
| 69 | 'locale_id' => $this->getLocaleId($message->getLocale()), |
||
| 70 | 'q' => 'tags:' . $message->getDomain() . ' name:' . $message->getDomain() . '::' . $message->getKey(), |
||
| 71 | ]); |
||
| 72 | |||
| 73 | foreach ($response as $key) { |
||
| 74 | if ($key['name'] === $message->getDomain() . '::' . $message->getKey()) { |
||
| 75 | $keyId = $key['id']; |
||
| 76 | break; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | if (! isset($keyId)) { |
||
| 81 | $response = $this->client->request('key.create', [ |
||
| 82 | 'project_id' => $this->projectId, |
||
| 83 | 'locale_id' => $this->getLocaleId($message->getLocale()), |
||
| 84 | 'name' => $message->getDomain() . '::' . $message->getKey(), |
||
| 85 | 'tags' => $message->getDomain(), |
||
| 86 | ]); |
||
| 87 | |||
| 88 | $keyId = $response['id']; |
||
| 89 | } |
||
| 90 | |||
| 91 | $response = $this->client->request('translation.indexKeys', [ |
||
| 92 | 'project_id' => $this->projectId, |
||
| 93 | 'key_id' => $keyId |
||
| 94 | ]); |
||
| 95 | |||
| 96 | if (empty($response)) { |
||
| 97 | $this->client->request('translation.create', [ |
||
| 98 | 'project_id' => $this->projectId, |
||
| 99 | 'locale_id' => $this->getLocaleId($message->getLocale()), |
||
| 100 | 'key_id' => $keyId, |
||
| 101 | 'content' => $message->getDomain() . '::' . $message->getTranslation(), |
||
| 102 | ]); |
||
| 103 | |||
| 104 | return; |
||
| 105 | } |
||
| 106 | |||
| 107 | foreach ($response as $translation) { |
||
| 108 | if ($translation['locale']['name'] === $message->getLocale()) { |
||
| 109 | $id = $translation['id']; |
||
| 110 | } |
||
| 111 | break; |
||
| 112 | } |
||
| 113 | |||
| 114 | if (! isset($id)) { |
||
| 115 | throw new StorageException('Translation id not found.'); |
||
| 116 | } |
||
| 117 | |||
| 118 | $this->client->request('translation.update', [ |
||
| 119 | 'project_id' => $this->projectId, |
||
| 120 | 'id' => $id, |
||
| 121 | 'content' => $message->getDomain() . '::' . $message->getTranslation(), |
||
| 122 | ]); |
||
| 123 | } catch (\Throwable $e) { |
||
| 124 | throw new StorageException($e->getMessage()); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 252 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.