Conditions | 9 |
Paths | 50 |
Total Lines | 54 |
Code Lines | 30 |
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 |
||
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 | $listItems = $item->getListItems( 'media', null, null, false )->reverse(); |
||
50 | $resource = $item->getResourceType(); |
||
51 | $context = $this->context(); |
||
52 | |||
53 | $manager = \Aimeos\MShop::create( $context, $resource ); |
||
54 | $mediaManager = \Aimeos\MShop::create( $context, 'media' ); |
||
55 | |||
56 | foreach( $node->childNodes as $refNode ) |
||
57 | { |
||
58 | if( $refNode->nodeName !== 'mediaitem' ) { |
||
59 | continue; |
||
60 | } |
||
61 | |||
62 | if( ( $listItem = $listItems->pop() ) === null ) { |
||
63 | $listItem = $manager->createListItem(); |
||
|
|||
64 | } |
||
65 | |||
66 | if( ( $refItem = $listItem->getRefItem() ) === null ) { |
||
67 | $refItem = $mediaManager->create(); |
||
68 | } |
||
69 | |||
70 | $list = []; |
||
71 | |||
72 | foreach( $refNode->childNodes as $tag ) |
||
73 | { |
||
74 | if( in_array( $tag->nodeName, ['lists', 'property'] ) ) { |
||
75 | $refItem = $this->getProcessor( $tag->nodeName )->process( $refItem, $tag ); |
||
76 | } else { |
||
77 | $list[$tag->nodeName] = \Aimeos\Base\Str::decode( $tag->nodeValue ); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | $refItem = $this->update( $refItem, $list ); |
||
82 | |||
83 | foreach( $refNode->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 | $name = $resource . '.lists.type'; |
||
90 | $list[$name] = $list[$name] ?? 'default'; |
||
91 | |||
92 | $this->addType( $resource . '/lists/type', 'media', $list[$resource . '.lists.type'] ); |
||
93 | |||
94 | $listItem = $listItem->fromArray( $list ); |
||
95 | $item->addListItem( 'media', $listItem, $refItem ); |
||
96 | } |
||
97 | |||
98 | return $item->deleteListItems( $listItems->toArray() ); |
||
99 | } |
||
136 |
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.