| Conditions | 11 |
| Paths | 75 |
| Total Lines | 61 |
| Code Lines | 32 |
| 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 | $this->detectMagento($output, true); |
||
| 91 | if (!$this->initMagento()) { |
||
| 92 | return; |
||
| 93 | } |
||
| 94 | |||
| 95 | if ($input->getOption('add-all')) { |
||
| 96 | $input->setOption('add-categories', true); |
||
| 97 | $input->setOption('add-products', true); |
||
| 98 | $input->setOption('add-cmspages', true); |
||
| 99 | } |
||
| 100 | |||
| 101 | $stores = explode(',', $input->getArgument('stores')); |
||
| 102 | |||
| 103 | $urls = array(); |
||
| 104 | |||
| 105 | foreach ($stores as $storeId) { |
||
| 106 | try { |
||
| 107 | $currentStore = $this->storeManager->getStore($storeId); |
||
| 108 | } catch (\Exception $e) { |
||
| 109 | throw new \RuntimeException("Store with id {$storeId} doesn´t exist"); |
||
| 110 | } |
||
| 111 | |||
| 112 | // base url |
||
| 113 | $urls[] = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB); |
||
| 114 | |||
| 115 | $linkBaseUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); |
||
| 116 | |||
| 117 | if ($input->getOption('add-categories')) { |
||
| 118 | $urls = $this->getUrls($this->sitemapCategoryCollection, $linkBaseUrl, $storeId, $urls); |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($input->getOption('add-products')) { |
||
| 122 | $urls = $this->getUrls($this->sitemapProductCollection, $linkBaseUrl, $storeId, $urls); |
||
| 123 | } |
||
| 124 | |||
| 125 | if ($input->getOption('add-cmspages')) { |
||
| 126 | $urls = $this->getUrls($this->sitemapPageCollection, $linkBaseUrl, $storeId, $urls); |
||
| 127 | } |
||
| 128 | } // foreach ($stores as $storeId) |
||
| 129 | |||
| 130 | if (count($urls) === 0) { |
||
| 131 | return; |
||
| 132 | } |
||
| 133 | |||
| 134 | foreach ($urls as $url) { |
||
| 135 | |||
| 136 | // pre-process |
||
| 137 | $line = $input->getArgument('linetemplate'); |
||
| 138 | $line = str_replace('{url}', $url, $line); |
||
| 139 | |||
| 140 | $parts = parse_url($url); |
||
| 141 | foreach ($parts as $key => $value) { |
||
| 142 | $line = str_replace('{' . $key . '}', $value, $line); |
||
| 143 | } |
||
| 144 | |||
| 145 | // ... and output |
||
| 146 | $output->writeln($line); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 170 |
This check looks for
@paramannotations 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.