| Conditions | 4 |
| Paths | 4 |
| Total Lines | 60 |
| 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 |
||
| 38 | public function createMenu(array $options): ItemInterface |
||
| 39 | { |
||
| 40 | $menu = $this->factory->createItem('root'); |
||
| 41 | |||
| 42 | if (!isset($options['product'])) { |
||
| 43 | return $menu; |
||
| 44 | } |
||
| 45 | |||
| 46 | $product = $options['product']; |
||
| 47 | if (!$product instanceof ProductInterface) { |
||
| 48 | return $menu; |
||
| 49 | } |
||
| 50 | |||
| 51 | $manageVariantsItem = $this->factory |
||
| 52 | ->createItem('manage_variants') |
||
| 53 | ->setAttribute('type', 'links') |
||
| 54 | ->setLabel('sylius.ui.manage_variants') |
||
| 55 | ->setLabelAttribute('icon', 'cubes') |
||
| 56 | ; |
||
| 57 | |||
| 58 | $manageVariantsItem |
||
| 59 | ->addChild('product_variant_index', [ |
||
| 60 | 'route' => 'sylius_admin_product_variant_index', |
||
| 61 | 'routeParameters' => ['productId' => $product->getId()], |
||
| 62 | ]) |
||
| 63 | ->setAttribute('type', 'link') |
||
| 64 | ->setLabel('sylius.ui.list_variants') |
||
| 65 | ->setLabelAttribute('icon', 'list') |
||
| 66 | ; |
||
| 67 | $manageVariantsItem |
||
| 68 | ->addChild('product_variant_create', [ |
||
| 69 | 'route' => 'sylius_admin_product_variant_create', |
||
| 70 | 'routeParameters' => ['productId' => $product->getId()], |
||
| 71 | ]) |
||
| 72 | ->setAttribute('type', 'link') |
||
| 73 | ->setLabel('sylius.ui.create') |
||
| 74 | ->setLabelAttribute('icon', 'plus') |
||
| 75 | ; |
||
| 76 | |||
| 77 | if ($product->hasOptions()) { |
||
| 78 | $manageVariantsItem |
||
| 79 | ->addChild('product_variant_generate', [ |
||
| 80 | 'route' => 'sylius_admin_product_variant_generate', |
||
| 81 | 'routeParameters' => ['productId' => $product->getId()], |
||
| 82 | ]) |
||
| 83 | ->setAttribute('type', 'link') |
||
| 84 | ->setLabel('sylius.ui.generate') |
||
| 85 | ->setLabelAttribute('icon', 'random') |
||
| 86 | ; |
||
| 87 | } |
||
| 88 | |||
| 89 | $menu->addChild($manageVariantsItem); |
||
| 90 | |||
| 91 | $this->eventDispatcher->dispatch( |
||
| 92 | self::EVENT_NAME, |
||
| 93 | new ProductMenuBuilderEvent($this->factory, $menu, $product) |
||
| 94 | ); |
||
| 95 | |||
| 96 | return $menu; |
||
| 97 | } |
||
| 98 | } |
||
| 99 |