Conditions | 9 |
Paths | 20 |
Total Lines | 53 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
45 | public function process( \Aimeos\MShop\Common\Item\Iface $item, \DOMNode $node ) : \Aimeos\MShop\Common\Item\Iface |
||
46 | { |
||
47 | \Aimeos\Utils::implements( $item, \Aimeos\MShop\Common\Item\ListsRef\Iface::class ); |
||
48 | |||
49 | $context = $this->context(); |
||
50 | $resource = $item->getResourceType(); |
||
51 | $listItems = $item->getListItems( 'supplier', null, null, false ); |
||
52 | $manager = \Aimeos\MShop::create( $context, $resource ); |
||
53 | $map = $this->getItems( $node->childNodes ); |
||
54 | |||
55 | foreach( $node->childNodes as $node ) |
||
56 | { |
||
57 | $attributes = $node->attributes; |
||
58 | |||
59 | if( $node->nodeName !== 'supplieritem' ) { |
||
60 | continue; |
||
61 | } |
||
62 | |||
63 | if( ( $attr = $attributes->getNamedItem( 'ref' ) ) === null ) { |
||
64 | continue; |
||
65 | } |
||
66 | |||
67 | $attrValue = \Aimeos\Base\Str::decode( $attr->nodeValue ); |
||
68 | |||
69 | if( !isset( $map[$attrValue] ) ) { |
||
70 | continue; |
||
71 | } |
||
72 | |||
73 | $list = []; |
||
74 | $refItem = $map[$attrValue]; |
||
75 | $type = ( $attr = $attributes->getNamedItem( 'lists.type' ) ) !== null ? $attr->nodeValue : 'default'; |
||
76 | |||
77 | if( ( $listItem = $item->getListItem( 'supplier', $type, $refItem->getId() ) ) === null ) { |
||
78 | $listItem = $manager->createListItem(); |
||
|
|||
79 | } else { |
||
80 | unset( $listItems[$listItem->getId()] ); |
||
81 | } |
||
82 | |||
83 | foreach( $attributes as $attrName => $attrNode ) { |
||
84 | $list[$resource . '.' . $attrName] = \Aimeos\Base\Str::decode( $attrNode->nodeValue ); |
||
85 | } |
||
86 | |||
87 | $name = $resource . '.lists.config'; |
||
88 | $list[$name] = ( isset( $list[$name] ) ? (array) json_decode( $list[$name] ) : [] ); |
||
89 | $list[$resource . '.lists.type'] = $type; |
||
90 | |||
91 | $this->addType( $resource . '/lists/type', 'supplier', $type ); |
||
92 | |||
93 | $listItem = $listItem->fromArray( $list ); |
||
94 | $item = $item->addListItem( 'supplier', $listItem, $refItem ); |
||
95 | } |
||
96 | |||
97 | return $item->deleteListItems( $listItems->toArray() ); |
||
98 | } |
||
129 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.