Conditions | 10 |
Paths | 37 |
Total Lines | 87 |
Code Lines | 39 |
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 |
||
57 | public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface |
||
58 | { |
||
59 | if( !isset( $view->pageContent ) ) { |
||
60 | return parent::data( $view, $tags, $expire ); |
||
61 | } |
||
62 | |||
63 | $texts = []; |
||
64 | $context = $this->context(); |
||
65 | $config = $context->config(); |
||
66 | $cntl = \Aimeos\Controller\Frontend::create( $context, 'product' ); |
||
67 | |||
68 | /** client/html/cms/page/template-cataloglist |
||
69 | * Relative path to the HTML template of the page catalog list client. |
||
70 | * |
||
71 | * The template file contains the HTML code and processing instructions |
||
72 | * to generate the HTML code that is inserted into the HTML page |
||
73 | * of the rendered page in the frontend. The configuration string is the |
||
74 | * path to the template file relative to the templates directory (usually |
||
75 | * in client/html/templates). |
||
76 | * |
||
77 | * You can overwrite the template file configuration in extensions and |
||
78 | * provide alternative templates. These alternative templates should be |
||
79 | * named like the default one but with the string "standard" replaced by |
||
80 | * an unique name. You may use the name of your project for this. If |
||
81 | * you've implemented an alternative client class as well, "standard" |
||
82 | * should be replaced by the name of the new class. |
||
83 | * |
||
84 | * @param string Relative path to the template creating code for the catalog list |
||
85 | * @since 2021.07 |
||
86 | * @category Developer |
||
87 | * @see client/html/cms/page/template-body |
||
88 | * @see client/html/cms/page/template-header |
||
89 | */ |
||
90 | $template = $config->get( 'client/html/cms/page/template-cataloglist', 'cms/page/cataloglist/list' ); |
||
91 | $domains = $config->get( 'client/html/catalog/lists/domains', ['media', 'media/property', 'price', 'text'] ); |
||
92 | |||
93 | if( $view->config( 'client/html/cms/page/basket-add', false ) ) { |
||
94 | $domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute' => ['variant', 'custom', 'config']] ); |
||
95 | } |
||
96 | |||
97 | libxml_use_internal_errors( true ); |
||
98 | |||
99 | foreach( $view->pageContent as $content ) |
||
100 | { |
||
101 | $dom = new \DOMDocument( '1.0', 'UTF-8' ); |
||
102 | $dom->loadHTML( '<?xml encoding="utf-8" ?>' . $content, LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD ); |
||
103 | $nodes = $dom->getElementsByTagName( 'cataloglist' ); |
||
104 | |||
105 | while( $nodes->length > 0 ) |
||
106 | { |
||
107 | $node = $nodes->item( 0 ); |
||
108 | $catid = $node->hasAttribute( 'catid' ) ? $node->getAttribute( 'catid' ) : null; |
||
|
|||
109 | $type = $node->hasAttribute( 'type' ) ? $node->getAttribute( 'type' ) : 'default'; |
||
110 | $limit = $node->hasAttribute( 'limit' ) ? $node->getAttribute( 'limit' ) : 3; |
||
111 | |||
112 | $products = ( clone $cntl )->uses( $domains ) |
||
113 | ->category( $catid, $type ) |
||
114 | ->slice( 0, $limit ) |
||
115 | ->search(); |
||
116 | |||
117 | $articles = $products->getRefItems( 'product', 'default', 'default' )->flat( 1 )->union( $products ); |
||
118 | $attrMap = $articles->getRefItems( 'attribute' )->flat( 1 )->groupBy( 'attribute.type' ); |
||
119 | $attrTypes = $this->attributeTypes( $attrMap->keys() ); |
||
120 | |||
121 | $this->addMetaItems( $products, $expire, $tags ); |
||
122 | |||
123 | $tview = $context->view()->set( 'products', $products )->set( 'attributeTypes', $attrTypes ); |
||
124 | |||
125 | if( !$products->isEmpty() && (bool) $config->get( 'client/html/catalog/lists/stock/enable', true ) === true ) { |
||
126 | $tview->itemsStockUrl = $this->getStockUrl( $tview, $articles ); |
||
127 | } |
||
128 | |||
129 | $pdom = new \DOMDocument( '1.0', 'UTF-8' ); |
||
130 | $pdom->loadHTML( '<?xml encoding="utf-8" ?>' . $tview->render( $template ), LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD ); |
||
131 | |||
132 | $pnode = $dom->importNode( $pdom->documentElement, true ); |
||
133 | $node->parentNode->replaceChild( $pnode, $node ); |
||
134 | } |
||
135 | |||
136 | $texts[] = substr( $dom->saveHTML(), 25 ); |
||
137 | } |
||
138 | |||
139 | libxml_clear_errors(); |
||
140 | |||
141 | $view->pageContent = $texts; |
||
142 | |||
143 | return parent::data( $view, $tags, $expire ); |
||
144 | } |
||
165 |
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.