Completed
Branch master (8a4183)
by Jakub
06:55
created
src/ConditionPermission.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
6
-use Nette\Security\User,
7
-    Nette\Utils\Strings;
6
+use Nette\Security\User;
7
+use Nette\Utils\Strings;
8 8
 
9 9
 /**
10 10
  * ConditionPermission
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
    * @throws \OutOfBoundsException
38 38
    */
39 39
   function isAllowed($parameter = NULL): bool {
40
-    if(!is_string($parameter)) {
40
+    if (!is_string($parameter)) {
41 41
       throw new \InvalidArgumentException("Method " . static::class . "::isAllowed expects string as parameter.");
42
-    } elseif(!Strings::contains($parameter, ":")) {
42
+    } elseif (!Strings::contains($parameter, ":")) {
43 43
       throw new \OutOfBoundsException("Method " . static::class . "::isAllowed expects parameter in format resource:privilege.");
44 44
     }
45 45
     return $this->user->isAllowed(Strings::before($parameter, ":"), Strings::after($parameter, ":"));
Please login to merge, or discard this patch.
src/DI/MenuExtension.php 2 patches
Unused Use Statements   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -3,15 +3,15 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Menu\DI;
5 5
 
6
-use Nexendrie\Menu\IMenuControlFactory,
7
-    Nexendrie\Menu\Menu,
8
-    Nette\DI\Config\Helpers,
9
-    Nexendrie\Menu\ConditionUserLoggedIn,
10
-    Nexendrie\Menu\ConditionUserInRole,
11
-    Nexendrie\Menu\ConditionPermission,
12
-    Nexendrie\Menu\ConditionCallback,
13
-    Nette\Reflection\ClassType,
14
-    Nette\Utils\Strings;
6
+use Nexendrie\Menu\IMenuControlFactory;
7
+use Nexendrie\Menu\Menu;
8
+use Nette\DI\Config\Helpers;
9
+use Nexendrie\Menu\ConditionUserLoggedIn;
10
+use Nexendrie\Menu\ConditionUserInRole;
11
+use Nexendrie\Menu\ConditionPermission;
12
+use Nexendrie\Menu\ConditionCallback;
13
+use Nette\Reflection\ClassType;
14
+use Nette\Utils\Strings;
15 15
 
16 16
 /**
17 17
  * MenuExtension
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu\DI;
5 5
 
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
     ];
58 58
     $this->defaults[static::SECTION_CONDITIONS] = [];
59 59
     $constants = (new ClassType(static::class))->constants;
60
-    foreach($constants as $name => $value) {
61
-      if(Strings::startsWith($name, "SECTION_")) {
60
+    foreach ($constants as $name => $value) {
61
+      if (Strings::startsWith($name, "SECTION_")) {
62 62
         $this->specialSections[] = $value;
63 63
       }
64 64
     }
@@ -72,26 +72,26 @@  discard block
 block discarded – undo
72 72
     $builder->addDefinition($this->prefix(static::SERVICE_MENU_FACTORY))
73 73
       ->setFactory(MenuFactory::class, [$config[static::SECTION_CONDITIONS]])
74 74
       ->setAutowired(false);
75
-    if(count($config[static::SECTION_CONDITIONS])) {
75
+    if (count($config[static::SECTION_CONDITIONS])) {
76 76
       trigger_error("Section " . $this->prefix(static::SECTION_CONDITIONS) . "is deprecated. Register custom conditions manually.", E_USER_DEPRECATED);
77 77
     }
78
-    foreach($config[static::SECTION_CONDITIONS] as $name => $class) {
78
+    foreach ($config[static::SECTION_CONDITIONS] as $name => $class) {
79 79
       $builder->addDefinition($this->prefix("condition.$name"))
80 80
         ->setClass($class);
81 81
     }
82
-    foreach($this->defaultConditions as $name => $class) {
82
+    foreach ($this->defaultConditions as $name => $class) {
83 83
       $builder->addDefinition($this->prefix("condition.$name"))
84 84
         ->setClass($class);
85 85
     }
86
-    foreach($config as $name => $menu) {
87
-      if(in_array($name, $this->specialSections)) {
86
+    foreach ($config as $name => $menu) {
87
+      if (in_array($name, $this->specialSections)) {
88 88
         continue;
89 89
       }
90 90
       $data = Helpers::merge($menu, $this->menuDefaults);
91 91
       $service = $builder->addDefinition($this->prefix($name))
92 92
         ->setFactory("@" . $this->prefix(static::SERVICE_MENU_FACTORY) . "::createMenu", [$name, $data])
93 93
         ->setAutowired(($name === "default"));
94
-      if($data["translate"]) {
94
+      if ($data["translate"]) {
95 95
         $service->addSetup("setTranslator");
96 96
       }
97 97
     }
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
     $config = $this->getConfig($this->defaults);
103 103
     $control = $builder->getDefinition($this->prefix(static::SERVICE_COMPONENT_FACTORY));
104 104
     $menus = $builder->findByType(Menu::class);
105
-    foreach($menus as $menuName => $menu) {
105
+    foreach ($menus as $menuName => $menu) {
106 106
       $control->addSetup('?->addMenu(?);', ["@self", "@$menuName"]);
107 107
     }
108
-    foreach($config[static::SECTION_MENU_TYPES] as $type => $template) {
108
+    foreach ($config[static::SECTION_MENU_TYPES] as $type => $template) {
109 109
       $control->addSetup('?->addMenuType(?,?);', ["@self", $type, $template]);
110 110
     }
111 111
   }
Please login to merge, or discard this patch.
src/DI/MenuFactory.php 2 patches
Unused Use Statements   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Menu\DI;
5 5
 
6
-use Nette\DI\Container,
7
-    Nexendrie\Menu\Menu,
8
-    Nexendrie\Menu\MenuItem,
9
-    Nexendrie\Menu\IMenuItemCondition,
10
-    Nexendrie\Menu\InvalidMenuItemDefinitionException,
11
-    Nexendrie\Menu\MenuItemConditionNotSupportedException;
6
+use Nette\DI\Container;
7
+use Nexendrie\Menu\Menu;
8
+use Nexendrie\Menu\MenuItem;
9
+use Nexendrie\Menu\IMenuItemCondition;
10
+use Nexendrie\Menu\InvalidMenuItemDefinitionException;
11
+use Nexendrie\Menu\MenuItemConditionNotSupportedException;
12 12
 
13 13
 /**
14 14
  * MenuFactory
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu\DI;
5 5
 
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
    * @throws MenuItemConditionNotSupportedException
36 36
    */
37 37
   protected function getCondition(string $name): IMenuItemCondition {
38
-    foreach($this->container->findByType(IMenuItemCondition::class) as $serviceName) {
38
+    foreach ($this->container->findByType(IMenuItemCondition::class) as $serviceName) {
39 39
       /** @var IMenuItemCondition $service */
40 40
       $service = $this->container->createService($serviceName);
41
-      if($service->getName() === $name) {
41
+      if ($service->getName() === $name) {
42 42
         return $service;
43 43
       }
44 44
     }
@@ -54,19 +54,19 @@  discard block
 block discarded – undo
54 54
    * @throws MenuItemConditionNotSupportedException
55 55
    */
56 56
   protected function createItem(string $text, $definition): MenuItem {
57
-    if(is_string($definition)) {
57
+    if (is_string($definition)) {
58 58
       return new MenuItem($definition, $text);
59
-    } elseif(!is_array($definition)) {
59
+    } elseif (!is_array($definition)) {
60 60
       throw new \InvalidArgumentException("Menu item has to be either string or array.");
61
-    } elseif(!array_key_exists("link", $definition)) {
61
+    } elseif (!array_key_exists("link", $definition)) {
62 62
       throw new InvalidMenuItemDefinitionException("Menu item is missing link.");
63 63
     }
64 64
     $item = new MenuItem($definition["link"], $text);
65
-    if(array_key_exists(MenuExtension::SECTION_CONDITIONS, $definition) AND is_array($definition[MenuExtension::SECTION_CONDITIONS])) {
66
-      foreach($definition[MenuExtension::SECTION_CONDITIONS] as $condition => $value) {
65
+    if (array_key_exists(MenuExtension::SECTION_CONDITIONS, $definition) AND is_array($definition[MenuExtension::SECTION_CONDITIONS])) {
66
+      foreach ($definition[MenuExtension::SECTION_CONDITIONS] as $condition => $value) {
67 67
         try {
68 68
           $conditionService = $this->getCondition($condition);
69
-        } catch(MenuItemConditionNotSupportedException $e) {
69
+        } catch (MenuItemConditionNotSupportedException $e) {
70 70
           throw $e;
71 71
         }
72 72
         $item->addCondition($conditionService, $value);
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
   function createMenu(string $name, array $config): Menu {
87 87
     $menu = new Menu($name, $config["htmlId"]);
88 88
     $menu->title = $config["title"];
89
-    foreach($config["items"] as $text => $definition) {
89
+    foreach ($config["items"] as $text => $definition) {
90 90
       $menu[] = $this->createItem($text, $definition);
91 91
     }
92 92
     return $menu;
Please login to merge, or discard this patch.
src/Menu.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
6
-use Nette\Localization\ITranslator,
7
-    Nexendrie\Utils\Collection;
6
+use Nette\Localization\ITranslator;
7
+use Nexendrie\Utils\Collection;
8 8
 
9 9
 /**
10 10
  * Menu
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
    */
97 97
   function getAllowedItems(): array {
98 98
     $items = [];
99
-    foreach($this->items as $item) {
100
-      if($item->isAllowed()) {
99
+    foreach ($this->items as $item) {
100
+      if ($item->isAllowed()) {
101 101
         $items[] = $item;
102 102
       }
103 103
     }
Please login to merge, or discard this patch.
src/MenuControl.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
6
-use Nette\Utils\Arrays,
7
-    Nette\Utils\Strings;
6
+use Nette\Utils\Arrays;
7
+use Nette\Utils\Strings;
8 8
 
9 9
 /**
10 10
  * MenuControl
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
    * @throws TemplateNotFoundException
37 37
    */
38 38
   function addMenuType(string $name, string $template): void {
39
-    if(array_key_exists($name, $this->templates)) {
39
+    if (array_key_exists($name, $this->templates)) {
40 40
       throw new MenuTypeAlreadyDefinedException("Menu type $name is already defined");
41 41
     }
42
-    if(!file_exists($template)) {
42
+    if (!file_exists($template)) {
43 43
       throw new TemplateNotFoundException("File $template does not exist.");
44 44
     }
45 45
     $this->templates[$name] = realpath($template);
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
    * @throws MenuNotFoundException
52 52
    */
53 53
   protected function getMenu(string $menuName): Menu {
54
-    foreach($this->menus as $name => $menu) {
55
-      if($name === $menuName) {
54
+    foreach ($this->menus as $name => $menu) {
55
+      if ($name === $menuName) {
56 56
         return $menu;
57 57
       }
58 58
     }
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
    */
69 69
   protected function getTemplateFilename(string $menuType): string {
70 70
     $filename = Arrays::get($this->templates, $menuType, "");
71
-    if($filename === "") {
71
+    if ($filename === "") {
72 72
       throw new MenuTypeNotSupportedException("Menu type $menuType is not supported.");
73 73
     } else {
74 74
       return $filename;
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     try {
89 89
       $menu = $this->getMenu($menuName);
90 90
       $templateFile = $this->getTemplateFilename($menuType);
91
-    } catch(MenuNotFoundException | MenuTypeNotSupportedException $e) {
91
+    } catch (MenuNotFoundException | MenuTypeNotSupportedException $e) {
92 92
       throw $e;
93 93
     }
94 94
     $this->template->setFile($templateFile);
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
    * @return mixed
108 108
    */
109 109
   function __call($name, $args) {
110
-    if($name === "render") {
110
+    if ($name === "render") {
111 111
       $name = "renderInline";
112 112
     }
113
-    if(Strings::startsWith($name, "render")) {
113
+    if (Strings::startsWith($name, "render")) {
114 114
       $render = Strings::firstLower(Strings::after($name, "render"));
115 115
       $menuName = Arrays::get($args, 0, "default");
116 116
       $this->baseRender($menuName, $render);
Please login to merge, or discard this patch.
src/ConditionCallback.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
    * @throws \UnexpectedValueException
29 29
    */
30 30
   function isAllowed($parameter = NULL): bool {
31
-    if(!is_callable($parameter)) {
31
+    if (!is_callable($parameter)) {
32 32
       throw new \InvalidArgumentException("Method " . static::class . "::isAllowed expects callback as parameter.");
33 33
     }
34 34
     $result = call_user_func($parameter);
35
-    if(!is_bool($result)) {
35
+    if (!is_bool($result)) {
36 36
       throw new \UnexpectedValueException("The callback for method " . static::class . "::isAllowed has to return boolean, " . gettype($result) . " returned.");
37 37
     }
38 38
     return $result;
Please login to merge, or discard this patch.
src/MenuItem.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
    * @return bool
68 68
    */
69 69
   function isAllowed(): bool {
70
-    foreach($this->conditions as $condition) {
71
-      if(!$condition[0]->isAllowed($condition[1])) {
70
+    foreach ($this->conditions as $condition) {
71
+      if (!$condition[0]->isAllowed($condition[1])) {
72 72
         return false;
73 73
       }
74 74
     }
Please login to merge, or discard this patch.
src/MenuTypeNotSupportedException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
Please login to merge, or discard this patch.
src/InvalidMenuItemDefinitionException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Menu;
5 5
 
Please login to merge, or discard this patch.