| Conditions | 3 |
| Paths | 4 |
| Total Lines | 65 |
| Code Lines | 38 |
| 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 |
||
| 10 | * @test |
||
| 11 | */ |
||
| 12 | public function deleteOne() |
||
| 13 | { |
||
| 14 | $input = array( |
||
| 15 | 'command' => 'config:set', |
||
| 16 | 'path' => 'n98_magerun/foo/bar', |
||
| 17 | 'value' => '1234', |
||
| 18 | ); |
||
| 19 | $this->assertDisplayContains($input, 'n98_magerun/foo/bar => 1234'); |
||
| 20 | |||
| 21 | $input = array( |
||
| 22 | 'command' => 'config:delete', |
||
| 23 | 'path' => 'n98_magerun/foo/bar', |
||
| 24 | ); |
||
| 25 | $this->assertDisplayContains($input, '| n98_magerun/foo/bar | default | 0 |'); |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @test |
||
| 30 | */ |
||
| 31 | public function deleteAll() |
||
| 32 | { |
||
| 33 | $input = array( |
||
| 34 | 'command' => 'config:set', |
||
| 35 | 'path' => 'n98_magerun/foo/bar', |
||
| 36 | '--scope' => 'stores', |
||
| 37 | '--scope-id' => null, # placeholder |
||
| 38 | 'value' => 'fake-value', |
||
| 39 | ); |
||
| 40 | |||
| 41 | foreach ($this->getStores() as $store) { |
||
| 42 | $input['--scope-id'] = $store->getId(); |
||
| 43 | $this->assertDisplayContains($input, "n98_magerun/foo/bar => fake-value"); |
||
| 44 | } |
||
| 45 | |||
| 46 | $input = array( |
||
| 47 | 'command' => 'config:delete', |
||
| 48 | 'path' => 'n98_magerun/foo/bar', |
||
| 49 | '--all' => true, |
||
| 50 | ); |
||
| 51 | $this->assertDisplayContains($input, '| n98_magerun/foo/bar | stores |'); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return array|\Magento\Store\Api\Data\StoreInterface[] |
||
| 56 | */ |
||
| 57 | private function getStores() |
||
| 58 | { |
||
| 59 | $application = $this->getApplication(); |
||
| 60 | |||
| 61 | /* @var $storeManager \Magento\Store\Model\StoreManager */ |
||
| 62 | $storeManager = $application->getObjectManager()->get('Magento\Store\Model\StoreManager'); |
||
|
|
|||
| 63 | |||
| 64 | return $storeManager->getStores(); |
||
| 65 | } |
||
| 66 | } |
||
| 67 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: