| Conditions | 13 |
| Paths | 48 |
| Total Lines | 48 |
| Code Lines | 20 |
| 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 |
||
| 33 | public function transform( \Aimeos\MShop\Common\Item\Iface $item, array $fields, array $fcn = [] ) |
||
| 34 | { |
||
| 35 | $this->map = []; |
||
| 36 | |||
| 37 | if( $item instanceof \Aimeos\MShop\Common\Item\Tree\Iface ) |
||
| 38 | { |
||
| 39 | foreach( $item->getChildren() as $catItem ) |
||
| 40 | { |
||
| 41 | if( $catItem->isAvailable() ) { |
||
| 42 | $this->map( $catItem, $fields, $fcn ); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | if( $item instanceof \Aimeos\MShop\Common\Item\AddressRef\Iface ) |
||
| 48 | { |
||
| 49 | foreach( $item->getAddressItems() as $addrItem ) { |
||
| 50 | $this->map( $addrItem, $fields, $fcn ); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | if( $item instanceof \Aimeos\MShop\Common\Item\ListRef\Iface ) |
||
| 55 | { |
||
| 56 | foreach( $item->getListItems() as $listItem ) |
||
| 57 | { |
||
| 58 | if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
||
| 59 | $this->map( $refItem, $fields, $fcn ); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | if( $item instanceof \Aimeos\MShop\Common\Item\PropertyRef\Iface ) |
||
| 65 | { |
||
| 66 | foreach( $item->getPropertyItems() as $propItem ) { |
||
| 67 | $this->map( $propItem, $fields, $fcn ); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | $result = []; |
||
| 72 | |||
| 73 | foreach( $this->map as $list ) |
||
| 74 | { |
||
| 75 | foreach( $list as $entry ) { |
||
| 76 | $result[] = $entry; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | return $result; |
||
| 81 | } |
||
| 159 |