| Conditions | 15 |
| Paths | 2 |
| Total Lines | 40 |
| Code Lines | 33 |
| 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['buy'] = function ($value) { return $value; }; |
||
| 32 | $converters['issued'] = function ($value) { return $value; }; |
||
| 33 | $converters['price'] = function ($value) { return $value; }; |
||
| 34 | $converters['volumeEntered'] = function ($value) { return $value; }; |
||
| 35 | $converters['minVolume'] = function ($value) { return $value; }; |
||
| 36 | $converters['volume'] = function ($value) { return $value; }; |
||
| 37 | $converters['item'] = function ($value) { return new Reference($value); }; |
||
| 38 | $converters['range'] = function ($value) { return $value; }; |
||
| 39 | $converters['href'] = function ($value) { return new Uri($value); }; |
||
| 40 | $converters['location'] = function ($value) { return new Reference($value); }; |
||
| 41 | $converters['duration'] = function ($value) { return $value; }; |
||
| 42 | $converters['type'] = function ($value) { return new Reference($value); }; |
||
| 43 | $converters['id'] = function ($value) { return $value; }; |
||
| 44 | |||
| 45 | $func = function ($value) use($converters) { |
||
| 46 | $return = new \ArrayObject($value, \ArrayObject::ARRAY_AS_PROPS); |
||
| 47 | $return['buy'] = isset($value->{'buy'}) ? $converters['buy']($value->{'buy'}) : null; |
||
| 48 | $return['issued'] = isset($value->{'issued'}) ? $converters['issued']($value->{'issued'}) : null; |
||
| 49 | $return['price'] = isset($value->{'price'}) ? $converters['price']($value->{'price'}) : null; |
||
| 50 | $return['volumeEntered'] = isset($value->{'volumeEntered'}) ? $converters['volumeEntered']($value->{'volumeEntered'}) : null; |
||
| 51 | $return['minVolume'] = isset($value->{'minVolume'}) ? $converters['minVolume']($value->{'minVolume'}) : null; |
||
| 52 | $return['volume'] = isset($value->{'volume'}) ? $converters['volume']($value->{'volume'}) : null; |
||
| 53 | $return['item'] = isset($value->{'item'}) ? $converters['item']($value->{'item'}) : null; |
||
| 54 | $return['range'] = isset($value->{'range'}) ? $converters['range']($value->{'range'}) : null; |
||
| 55 | $return['href'] = isset($value->{'href'}) ? $converters['href']($value->{'href'}) : null; |
||
| 56 | $return['location'] = isset($value->{'location'}) ? $converters['location']($value->{'location'}) : null; |
||
| 57 | $return['duration'] = isset($value->{'duration'}) ? $converters['duration']($value->{'duration'}) : null; |
||
| 58 | $return['type'] = isset($value->{'type'}) ? $converters['type']($value->{'type'}) : null; |
||
| 59 | $return['id'] = isset($value->{'id'}) ? $converters['id']($value->{'id'}) : null; |
||
| 60 | return $return; |
||
| 61 | }; |
||
| 62 | |||
| 63 | foreach ($items as $key => $value) { |
||
| 64 | $this->items[$key] = $func($value); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 87 |