| Conditions | 13 |
| Paths | 2 |
| Total Lines | 43 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 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 | public function setItems($items) |
||
| 28 | { |
||
| 29 | // by Warringer\Types\Base |
||
| 30 | $converters = []; |
||
| 31 | $converters['matchesInProgress'] = function ($values) { |
||
| 32 | // by Warringer\Types\Reference |
||
| 33 | $func = function ($value) { return new Reference($value); }; |
||
| 34 | |||
| 35 | foreach ($values as $key => $value) { |
||
| 36 | $values[$key] = $func($value); |
||
| 37 | } |
||
| 38 | return $values; |
||
| 39 | }; |
||
| 40 | |||
| 41 | $converters['redTeam'] = function ($value) { return $value; }; |
||
| 42 | $converters['matchesWon'] = function ($value) { return $value; }; |
||
| 43 | $converters['matches'] = function ($value) { return new Reference($value); }; |
||
| 44 | $converters['self'] = function ($value) { return new Reference($value); }; |
||
| 45 | $converters['winner'] = function ($value) { return $value; }; |
||
| 46 | $converters['loser'] = function ($value) { return $value; }; |
||
| 47 | $converters['length'] = function ($value) { return $value; }; |
||
| 48 | $converters['blueTeam'] = function ($value) { return $value; }; |
||
| 49 | $converters['structure'] = function ($value) { return $value; }; |
||
| 50 | |||
| 51 | $func = function ($value) use($converters) { |
||
| 52 | $return = new \ArrayObject($value, \ArrayObject::ARRAY_AS_PROPS); |
||
| 53 | $return['matchesInProgress'] = isset($value->{'matchesInProgress'}) ? $converters['matchesInProgress']($value->{'matchesInProgress'}) : null; |
||
| 54 | $return['redTeam'] = isset($value->{'redTeam'}) ? $converters['redTeam']($value->{'redTeam'}) : null; |
||
| 55 | $return['matchesWon'] = isset($value->{'matchesWon'}) ? $converters['matchesWon']($value->{'matchesWon'}) : null; |
||
| 56 | $return['matches'] = isset($value->{'matches'}) ? $converters['matches']($value->{'matches'}) : null; |
||
| 57 | $return['self'] = isset($value->{'self'}) ? $converters['self']($value->{'self'}) : null; |
||
| 58 | $return['winner'] = isset($value->{'winner'}) ? $converters['winner']($value->{'winner'}) : null; |
||
| 59 | $return['loser'] = isset($value->{'loser'}) ? $converters['loser']($value->{'loser'}) : null; |
||
| 60 | $return['length'] = isset($value->{'length'}) ? $converters['length']($value->{'length'}) : null; |
||
| 61 | $return['blueTeam'] = isset($value->{'blueTeam'}) ? $converters['blueTeam']($value->{'blueTeam'}) : null; |
||
| 62 | $return['structure'] = isset($value->{'structure'}) ? $converters['structure']($value->{'structure'}) : null; |
||
| 63 | return $return; |
||
| 64 | }; |
||
| 65 | |||
| 66 | foreach ($items as $key => $value) { |
||
| 67 | $this->items[$key] = $func($value); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 90 |