| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 35 | public function testExecute() |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * Check autoloading |
||
| 39 | */ |
||
| 40 | |||
| 41 | /* @var $application Application */ |
||
| 42 | $application = require __DIR__ . '/../../../src/bootstrap.php'; |
||
| 43 | $application->setMagentoRootFolder($this->getTestMagentoRoot()); |
||
| 44 | |||
| 45 | $this->assertInstanceOf('\N98\Magento\Application', $application); |
||
| 46 | $loader = $application->getAutoloader(); |
||
| 47 | $this->assertInstanceOf('\Composer\Autoload\ClassLoader', $loader); |
||
| 48 | |||
| 49 | /* @var $loader \Composer\Autoload\ClassLoader */ |
||
| 50 | $prefixes = $loader->getPrefixes(); |
||
| 51 | $this->assertArrayHasKey('N98', $prefixes); |
||
| 52 | |||
| 53 | $distConfigArray = Yaml::parse(file_get_contents(__DIR__ . '/../../../config.yaml')); |
||
| 54 | |||
| 55 | $configArray = array( |
||
| 56 | 'autoloaders' => array( |
||
| 57 | 'N98MagerunTest' => __DIR__ . '/_ApplicationTestSrc', |
||
| 58 | ), |
||
| 59 | 'commands' => array( |
||
| 60 | 'customCommands' => array( |
||
| 61 | 0 => 'N98MagerunTest\TestDummyCommand' |
||
| 62 | ), |
||
| 63 | 'aliases' => array( |
||
| 64 | array( |
||
| 65 | 'ssl' => 'sys:store:list' |
||
| 66 | ) |
||
| 67 | ), |
||
| 68 | ), |
||
| 69 | 'init' => array( |
||
| 70 | 'options' => array( |
||
| 71 | 'config_model' => 'N98MagerunTest\AlternativeConfigModel', |
||
| 72 | ) |
||
| 73 | ) |
||
| 74 | ); |
||
| 75 | |||
| 76 | $application->setAutoExit(false); |
||
| 77 | $application->init(ArrayFunctions::mergeArrays($distConfigArray, $configArray)); |
||
|
|
|||
| 78 | $application->run(new StringInput('list'), new NullOutput()); |
||
| 79 | |||
| 80 | // Check if autoloaders, commands and aliases are registered |
||
| 81 | $prefixes = $loader->getPrefixes(); |
||
| 82 | $this->assertArrayHasKey('N98MagerunTest', $prefixes); |
||
| 83 | |||
| 84 | $testDummyCommand = $application->find('n98mageruntest:test:dummy'); |
||
| 85 | $this->assertInstanceOf('\N98MagerunTest\TestDummyCommand', $testDummyCommand); |
||
| 86 | |||
| 87 | $commandTester = new CommandTester($testDummyCommand); |
||
| 88 | $commandTester->execute( |
||
| 89 | array( |
||
| 90 | 'command' => $testDummyCommand->getName(), |
||
| 91 | ) |
||
| 92 | ); |
||
| 93 | $this->assertContains('dummy', $commandTester->getDisplay()); |
||
| 94 | $this->assertTrue($application->getDefinition()->hasOption('root-dir')); |
||
| 95 | |||
| 96 | // check alias |
||
| 97 | $this->assertInstanceOf('\N98\Magento\Command\System\Store\ListCommand', $application->find('ssl')); |
||
| 98 | } |
||
| 99 | |||
| 184 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.