| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 24 |
| 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 |
||
| 25 | protected function configure() |
||
| 26 | { |
||
| 27 | $this->setName('element:list'); |
||
| 28 | $this->setDescription('Extracts all of the AbstractConfigurableElement-based objects'); |
||
| 29 | $this->setHelp(<<<HELP |
||
| 30 | This command will traverse all known directories, or a specific directory, and return a list of all the classes found that extend Magium\\AbstractConfigurableElement in some way. |
||
| 31 | |||
| 32 | It can be used in conjunction with the magium:element:get to narrow down exactly which configuration value you are looking for. |
||
| 33 | |||
| 34 | There are two modes of operation to be aware of. |
||
| 35 | |||
| 36 | 1. Argument mode |
||
| 37 | |||
| 38 | If you run with the "directory" and "namespace" arguments (if one is provided both are required) then this command will recursively descend into this directory and find all configurable elements. |
||
| 39 | |||
| 40 | 2. Argument-less mode |
||
| 41 | |||
| 42 | Running without the options will cause the command to search through all registered paths. |
||
| 43 | |||
| 44 | An individual module is responsible to register its paths and does so by creating an autoload register.php file which contains at least the following code |
||
| 45 | |||
| 46 | <?php |
||
| 47 | |||
| 48 | Magium\Cli\Command\ListElements::addDirectory('my test dir', 'my\\test\\namespace'); |
||
| 49 | |||
| 50 | Again, all classes must be defined in PSR-4-autoload format. Custom autoloaders may be used, but the PSR-4 format is there to deduce the name of the class based on the file name. |
||
| 51 | |||
| 52 | HELP |
||
| 53 | ); |
||
| 54 | $this->addArgument( |
||
| 55 | 'directory', |
||
| 56 | InputArgument::OPTIONAL, |
||
| 57 | 'The name of the directory to traverse' |
||
| 58 | ); |
||
| 59 | |||
| 60 | $this->addArgument( |
||
| 61 | 'namespace', |
||
| 62 | InputArgument::OPTIONAL, |
||
| 63 | 'The psr-4 base namespace of the directory. Required if <directory> is used' |
||
| 64 | ); |
||
| 65 | $this->addArgument( |
||
| 66 | 'filter', |
||
| 67 | InputArgument::OPTIONAL, |
||
| 68 | 'A stripos()-compatible filter' |
||
| 69 | ); |
||
| 70 | |||
| 71 | $this->addOption( |
||
| 72 | 'escape', |
||
| 73 | '--esc', |
||
| 74 | InputOption::VALUE_NONE, |
||
| 75 | 'Set if you want the namespace output escaped (useful for copy and paste)' |
||
| 76 | ); |
||
| 77 | |||
| 78 | self::addDirectory(realpath(__DIR__ . '/../..'), 'Magium'); |
||
| 79 | } |
||
| 80 | |||
| 157 | } |