| Conditions | 7 | 
| Paths | 7 | 
| Total Lines | 76 | 
| Code Lines | 51 | 
| Lines | 8 | 
| Ratio | 10.53 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 1 | 
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  | 
            ||
| 38 | protected function execute(InputInterface $input, OutputInterface $output)  | 
            ||
| 39 |     { | 
            ||
| 40 | $this->detectMagento($output, true);  | 
            ||
| 41 | $this->initMagento();  | 
            ||
| 42 | |||
| 43 |         $output->writeln("<warning>This only create sample categories, do not use on production environment</warning>\r\n"); | 
            ||
| 44 | |||
| 45 | // MANAGE ARGUMENTS  | 
            ||
| 46 | $_argument = $this->manageArguments($input, $output);  | 
            ||
| 47 | |||
| 48 | /**  | 
            ||
| 49 | * LOOP to create categories  | 
            ||
| 50 | */  | 
            ||
| 51 |         for ($i = 0; $i < $_argument['category-number']; $i++) { | 
            ||
| 52 |             if(!is_null($_argument['category-name-prefix'])) { | 
            ||
| 53 | $name = $_argument['category-name-prefix'] . " " . $i;  | 
            ||
| 54 | }  | 
            ||
| 55 |             else { | 
            ||
| 56 | $name = self::DEFAULT_CATEGORY_NAME . " " . $i;  | 
            ||
| 57 | }  | 
            ||
| 58 | |||
| 59 | // Check if product exists  | 
            ||
| 60 |             $collection = \Mage::getModel('catalog/category')->getCollection() | 
            ||
| 61 |                 ->addAttributeToSelect('name') | 
            ||
| 62 |                 ->addAttributeToFilter('name', array('eq' => $name)); | 
            ||
| 63 | $_size = $collection->getSize();  | 
            ||
| 64 |             if($_size > 0) { | 
            ||
| 65 |                 $output->writeln("<comment>CATEGORY: WITH NAME: '" . $name . "' EXISTS! Skip</comment>\r"); | 
            ||
| 66 | $_argument['category-number']++;  | 
            ||
| 67 | continue;  | 
            ||
| 68 | }  | 
            ||
| 69 | unset($collection);  | 
            ||
| 70 | |||
| 71 | $_category_root_id = \Mage::app()->getStore($_argument['store-id'])->getRootCategoryId();  | 
            ||
| 72 | |||
| 73 |             $category = \Mage::getModel('catalog/category'); | 
            ||
| 74 | $category->setName($name);  | 
            ||
| 75 | $category->setIsActive(self::DEFAULT_CATEGORY_STATUS);  | 
            ||
| 76 |             $category->setDisplayMode('PRODUCTS'); | 
            ||
| 77 | $category->setIsAnchor(self::DEFAULT_CATEGORY_ANCHOR);  | 
            ||
| 78 | |||
| 79 | View Code Duplication | if(\Mage::getVersion() === "1.5.1.0")  | 
            |
| 80 | $category->setStoreId(array(0,$_argument['store-id']));  | 
            ||
| 81 | else  | 
            ||
| 82 | $category->setStoreId($_argument['store-id']);  | 
            ||
| 83 |             $parentCategory = \Mage::getModel('catalog/category')->load($_category_root_id); | 
            ||
| 84 | $category->setPath($parentCategory->getPath());  | 
            ||
| 85 | |||
| 86 | $category->save();  | 
            ||
| 87 | $_parent_id = $category->getId();  | 
            ||
| 88 |             $output->writeln("<comment>CATEGORY: '" . $category->getName() . "' WITH ID: '" . $category->getId() . "' CREATED!</comment>\r"); | 
            ||
| 89 | unset($category);  | 
            ||
| 90 | |||
| 91 | // CREATE CHILDREN CATEGORIES  | 
            ||
| 92 |             for ($j = 0; $j < $_argument['children-categories-number']; $j++) { | 
            ||
| 93 | $name_child = $name . " child " . $j;  | 
            ||
| 94 | |||
| 95 |                 $category = \Mage::getModel('catalog/category'); | 
            ||
| 96 | $category->setName($name_child);  | 
            ||
| 97 | $category->setIsActive(self::DEFAULT_CATEGORY_STATUS);  | 
            ||
| 98 |                 $category->setDisplayMode('PRODUCTS'); | 
            ||
| 99 | $category->setIsAnchor(self::DEFAULT_CATEGORY_ANCHOR);  | 
            ||
| 100 | |||
| 101 | View Code Duplication | if(\Mage::getVersion() === "1.5.1.0")  | 
            |
| 102 | $category->setStoreId(array(0,$_argument['store-id']));  | 
            ||
| 103 | else  | 
            ||
| 104 | $category->setStoreId($_argument['store-id']);  | 
            ||
| 105 |                 $parentCategory = \Mage::getModel('catalog/category')->load($_parent_id); | 
            ||
| 106 | $category->setPath($parentCategory->getPath());  | 
            ||
| 107 | |||
| 108 | $category->save();  | 
            ||
| 109 |                 $output->writeln("<comment>CATEGORY CHILD: '" . $category->getName() . "' WITH ID: '" . $category->getId() . "' CREATED!</comment>\r"); | 
            ||
| 110 | unset($category);  | 
            ||
| 111 | }  | 
            ||
| 112 | }  | 
            ||
| 113 | }  | 
            ||
| 114 | |||
| 204 | 
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.