| Conditions | 10 |
| Paths | 512 |
| Total Lines | 15 |
| Code Lines | 12 |
| 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 __construct(array $release, MusicBrainz $brainz) |
||
| 65 | { |
||
| 66 | $this->data = $release; |
||
| 67 | $this->brainz = $brainz; |
||
|
|
|||
| 68 | |||
| 69 | $this->id = isset($release['id']) ? (string)$release['id'] : ''; |
||
| 70 | $this->title = isset($release['title']) ? (string)$release['title'] : ''; |
||
| 71 | $this->status = isset($release['status']) ? (string)$release['status'] : ''; |
||
| 72 | $this->quality = isset($release['quality']) ? (string)$release['quality'] : ''; |
||
| 73 | $this->language = isset($release['text-representation']['language']) ? (string)$release['text-representation']['language'] : ''; |
||
| 74 | $this->script = isset($release['text-representation']['script']) ? (string)$release['text-representation']['script'] : ''; |
||
| 75 | $this->date = isset($release['date']) ? (string)$release['date'] : ''; |
||
| 76 | $this->country = isset($release['country']) ? (string)$release['country'] : ''; |
||
| 77 | $this->barcode = isset($release['barcode']) ? (string)$release['barcode'] : ''; |
||
| 78 | } |
||
| 79 | |||
| 131 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: