| Conditions | 11 |
| Paths | 24 |
| Total Lines | 38 |
| Code Lines | 16 |
| 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 |
||
| 32 | public function transform( \Aimeos\MShop\Common\Item\Iface $item, array $fields ) |
||
| 33 | { |
||
| 34 | $this->map = []; |
||
| 35 | |||
| 36 | if( $item instanceof \Aimeos\MShop\Common\Item\AddressRef\Iface ) |
||
| 37 | { |
||
| 38 | foreach( $item->getAddressItems() as $addItem ) { |
||
| 39 | $this->map( $addItem, $fields ); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | if( $item instanceof \Aimeos\MShop\Common\Item\ListRef\Iface ) |
||
| 44 | { |
||
| 45 | foreach( $item->getListItems() as $listItem ) |
||
| 46 | { |
||
| 47 | if( ( $refItem = $listItem->getRefItem() ) !== null && $refItem->isAvailable() ) { |
||
| 48 | $this->map( $refItem, $fields ); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | if( $item instanceof \Aimeos\MShop\Common\Item\PropertyRef\Iface ) |
||
| 54 | { |
||
| 55 | foreach( $item->getPropertyItems() as $propertyItem ) { |
||
| 56 | $this->map( $propertyItem, $fields ); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | $result = []; |
||
| 61 | |||
| 62 | foreach( $this->map as $list ) |
||
| 63 | { |
||
| 64 | foreach( $list as $entry ) { |
||
| 65 | $result[] = $entry; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | return $result; |
||
| 70 | } |
||
| 126 |