Conditions | 11 |
Paths | 76 |
Total Lines | 59 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 2 | 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 |
||
88 | protected function execute(InputInterface $input, OutputInterface $output) |
||
89 | { |
||
90 | if ($input->getOption('add-all')) { |
||
91 | $input->setOption('add-categories', true); |
||
92 | $input->setOption('add-products', true); |
||
93 | $input->setOption('add-cmspages', true); |
||
94 | } |
||
95 | |||
96 | $this->detectMagento($output, true); |
||
97 | if ($this->initMagento()) { |
||
98 | $stores = explode(',', $input->getArgument('stores')); |
||
99 | |||
100 | $urls = array(); |
||
101 | |||
102 | foreach ($stores as $storeId) { |
||
103 | try { |
||
104 | $currentStore = $this->storeManager->getStore($storeId); |
||
105 | } catch (\Exception $e) { |
||
106 | throw new \RuntimeException("Store with id {$storeId} doesn´t exist"); |
||
107 | } |
||
108 | |||
109 | // base url |
||
110 | $urls[] = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB); |
||
111 | |||
112 | $linkBaseUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); |
||
113 | |||
114 | if ($input->getOption('add-categories')) { |
||
115 | $urls = $this->getUrls($this->sitemapCategoryCollection, $linkBaseUrl, $storeId, $urls); |
||
116 | } |
||
117 | |||
118 | if ($input->getOption('add-products')) { |
||
119 | $urls = $this->getUrls($this->sitemapProductCollection, $linkBaseUrl, $storeId, $urls); |
||
120 | } |
||
121 | |||
122 | if ($input->getOption('add-cmspages')) { |
||
123 | $urls = $this->getUrls($this->sitemapPageCollection, $linkBaseUrl, $storeId, $urls); |
||
124 | } |
||
125 | } // foreach ($stores as $storeId) |
||
126 | |||
127 | if (count($urls) === 0) { |
||
128 | return; |
||
129 | } |
||
130 | |||
131 | foreach ($urls as $url) { |
||
132 | |||
133 | // pre-process |
||
134 | $line = $input->getArgument('linetemplate'); |
||
135 | $line = str_replace('{url}', $url, $line); |
||
136 | |||
137 | $parts = parse_url($url); |
||
138 | foreach ($parts as $key => $value) { |
||
139 | $line = str_replace('{' . $key . '}', $value, $line); |
||
140 | } |
||
141 | |||
142 | // ... and output |
||
143 | $output->writeln($line); |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | |||
169 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.