@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function getPermission(string $controller, string $action): Permission |
48 | 48 | { |
49 | 49 | $key = sprintf('%s:%s', $controller, $action); |
50 | - if (!array_key_exists($key, $this->cache)) { |
|
50 | + if (!array_key_exists($key, $this->cache)){ |
|
51 | 51 | $this->cache[$key] = $this->generatePermission($controller, $action); |
52 | 52 | } |
53 | 53 | |
@@ -56,20 +56,20 @@ discard block |
||
56 | 56 | |
57 | 57 | private function generatePermission(string $controller, string $action): Permission |
58 | 58 | { |
59 | - try { |
|
59 | + try{ |
|
60 | 60 | $method = new \ReflectionMethod($controller, $action); |
61 | - } catch (\ReflectionException $e) { |
|
61 | + }catch (\ReflectionException $e){ |
|
62 | 62 | return Permission::failed(); |
63 | 63 | } |
64 | 64 | |
65 | 65 | $guarded = $this->reader->firstFunctionMetadata($method, Guarded::class); |
66 | - if (!$guarded instanceof Guarded) { |
|
66 | + if (!$guarded instanceof Guarded){ |
|
67 | 67 | return Permission::failed(); |
68 | 68 | } |
69 | 69 | |
70 | 70 | $namespace = $this->reader->firstClassMetadata($method->getDeclaringClass(), GuardNamespace::class); |
71 | 71 | |
72 | - if ($guarded->permission || ($namespace instanceof GuardNamespace && $namespace->namespace)) { |
|
72 | + if ($guarded->permission || ($namespace instanceof GuardNamespace && $namespace->namespace)){ |
|
73 | 73 | return Permission::ok( |
74 | 74 | $this->makePermission($guarded, $method, $namespace), |
75 | 75 | $this->mapFailureException($guarded), |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | private function makePermission(Guarded $guarded, \ReflectionMethod $method, ?GuardNamespace $ns): string |
93 | 93 | { |
94 | 94 | $permission = []; |
95 | - if ($this->namespace) { |
|
95 | + if ($this->namespace){ |
|
96 | 96 | $permission[] = $this->namespace; |
97 | 97 | } |
98 | 98 | |
99 | - if ($ns !== null && $ns->namespace) { |
|
99 | + if ($ns !== null && $ns->namespace){ |
|
100 | 100 | $permission[] = $ns->namespace; |
101 | 101 | } |
102 | 102 |
@@ -48,7 +48,7 @@ |
||
48 | 48 | ?string $permission = null, |
49 | 49 | string $else = 'forbidden', |
50 | 50 | ?string $errorMessage = null |
51 | - ) { |
|
51 | + ){ |
|
52 | 52 | $this->permission = $permission; |
53 | 53 | $this->else = $else; |
54 | 54 | $this->errorMessage = $errorMessage; |
@@ -85,7 +85,7 @@ |
||
85 | 85 | string $group = self::DEFAULT_GROUP, |
86 | 86 | array $middleware = [], |
87 | 87 | int $priority = 0 |
88 | - ) { |
|
88 | + ){ |
|
89 | 89 | $this->route = $route; |
90 | 90 | $this->name = $name; |
91 | 91 | $this->methods = $methods; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | ContainerInterface $container, |
54 | 54 | GridFactory $gridFactory, |
55 | 55 | ReaderInterface $reader = null |
56 | - ) { |
|
56 | + ){ |
|
57 | 57 | $this->response = $response; |
58 | 58 | $this->container = $container; |
59 | 59 | $this->gridFactory = $gridFactory; |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | { |
73 | 73 | $result = $core->callAction($controller, $action, $parameters); |
74 | 74 | |
75 | - if (is_iterable($result)) { |
|
75 | + if (is_iterable($result)){ |
|
76 | 76 | $schema = $this->getSchema($controller, $action); |
77 | - if ($schema !== null) { |
|
77 | + if ($schema !== null){ |
|
78 | 78 | $grid = $this->makeFactory($schema) |
79 | 79 | ->withDefaults($schema['defaults']) |
80 | 80 | ->create($result, $schema['grid']); |
81 | 81 | |
82 | - if ($schema['view'] !== null) { |
|
82 | + if ($schema['view'] !== null){ |
|
83 | 83 | $grid = $grid->withView($schema['view']); |
84 | 84 | } |
85 | 85 | |
@@ -99,20 +99,20 @@ discard block |
||
99 | 99 | private function getSchema(string $controller, string $action): ?array |
100 | 100 | { |
101 | 101 | $key = sprintf('%s:%s', $controller, $action); |
102 | - if (array_key_exists($key, $this->cache)) { |
|
102 | + if (array_key_exists($key, $this->cache)){ |
|
103 | 103 | return $this->cache[$key]; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $this->cache[$key] = null; |
107 | - try { |
|
107 | + try{ |
|
108 | 108 | $method = new \ReflectionMethod($controller, $action); |
109 | - } catch (\ReflectionException $e) { |
|
109 | + }catch (\ReflectionException $e){ |
|
110 | 110 | return null; |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** @var null|DataGrid $dataGrid */ |
114 | 114 | $dataGrid = $this->reader->firstFunctionMetadata($method, DataGrid::class); |
115 | - if ($dataGrid === null) { |
|
115 | + if ($dataGrid === null){ |
|
116 | 116 | return null; |
117 | 117 | } |
118 | 118 | |
@@ -133,19 +133,19 @@ discard block |
||
133 | 133 | 'factory' => $dataGrid->factory, |
134 | 134 | ]; |
135 | 135 | |
136 | - if (is_string($schema['view'])) { |
|
136 | + if (is_string($schema['view'])){ |
|
137 | 137 | $schema['view'] = $this->container->get($schema['view']); |
138 | 138 | } |
139 | 139 | |
140 | - if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) { |
|
140 | + if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')){ |
|
141 | 141 | $schema['defaults'] = $schema['grid']->getDefaults(); |
142 | 142 | } |
143 | 143 | |
144 | - if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) { |
|
144 | + if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')){ |
|
145 | 145 | $schema['options'] = $schema['grid']->getOptions(); |
146 | 146 | } |
147 | 147 | |
148 | - if ($schema['view'] === null && is_callable($schema['grid'])) { |
|
148 | + if ($schema['view'] === null && is_callable($schema['grid'])){ |
|
149 | 149 | $schema['view'] = $schema['grid']; |
150 | 150 | } |
151 | 151 | |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | |
155 | 155 | private function makeFactory(array $schema): GridFactoryInterface |
156 | 156 | { |
157 | - if (!empty($schema['factory']) && $this->container->has($schema['factory'])) { |
|
157 | + if (!empty($schema['factory']) && $this->container->has($schema['factory'])){ |
|
158 | 158 | $factory = $this->container->get($schema['factory']); |
159 | - if ($factory instanceof GridFactoryInterface) { |
|
159 | + if ($factory instanceof GridFactoryInterface){ |
|
160 | 160 | return $factory; |
161 | 161 | } |
162 | 162 | } |
@@ -70,7 +70,7 @@ |
||
70 | 70 | array $defaults = [], |
71 | 71 | array $options = [], |
72 | 72 | ?string $factory = null |
73 | - ) { |
|
73 | + ){ |
|
74 | 74 | $this->grid = $grid; |
75 | 75 | $this->view = $view; |
76 | 76 | $this->defaults = $defaults; |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function findClasses(string $annotation): iterable |
69 | 69 | { |
70 | - foreach ($this->getTargets() as $target) { |
|
70 | + foreach ($this->getTargets() as $target){ |
|
71 | 71 | $found = $this->reader->firstClassMetadata($target, $annotation); |
72 | - if ($found !== null) { |
|
72 | + if ($found !== null){ |
|
73 | 73 | yield new AnnotatedClass($target, $found); |
74 | 74 | } |
75 | 75 | } |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function findMethods(string $annotation): iterable |
85 | 85 | { |
86 | - foreach ($this->getTargets() as $target) { |
|
87 | - foreach ($target->getMethods() as $method) { |
|
86 | + foreach ($this->getTargets() as $target){ |
|
87 | + foreach ($target->getMethods() as $method){ |
|
88 | 88 | $found = $this->reader->firstFunctionMetadata($method, $annotation); |
89 | - if ($found !== null) { |
|
89 | + if ($found !== null){ |
|
90 | 90 | yield new AnnotatedMethod($method, $found); |
91 | 91 | } |
92 | 92 | } |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function findProperties(string $annotation): iterable |
103 | 103 | { |
104 | - foreach ($this->getTargets() as $target) { |
|
105 | - foreach ($target->getProperties() as $property) { |
|
104 | + foreach ($this->getTargets() as $target){ |
|
105 | + foreach ($target->getProperties() as $property){ |
|
106 | 106 | $found = $this->reader->firstPropertyMetadata($property, $annotation); |
107 | - if ($found !== null) { |
|
107 | + if ($found !== null){ |
|
108 | 108 | yield new AnnotatedProperty($property, $found); |
109 | 109 | } |
110 | 110 | } |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | */ |
117 | 117 | private function getTargets(): iterable |
118 | 118 | { |
119 | - if ($this->targets === []) { |
|
119 | + if ($this->targets === []){ |
|
120 | 120 | yield from $this->classLocator->getClasses(); |
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - foreach ($this->targets as $target) { |
|
124 | + foreach ($this->targets as $target){ |
|
125 | 125 | yield from $this->classLocator->getClasses($target); |
126 | 126 | } |
127 | 127 | } |
@@ -29,23 +29,23 @@ discard block |
||
29 | 29 | public function testLocateClasses() |
30 | 30 | { |
31 | 31 | // Annotations. |
32 | - $classes = $this->getAnnotationsLocator(__DIR__ . '/Fixtures')->findClasses(ClassAnnotation::class); |
|
32 | + $classes = $this->getAnnotationsLocator(__DIR__.'/Fixtures')->findClasses(ClassAnnotation::class); |
|
33 | 33 | $classes = iterator_to_array($classes); |
34 | 34 | |
35 | 35 | $this->assertCount(1, $classes); |
36 | 36 | |
37 | - foreach ($classes as $class) { |
|
37 | + foreach ($classes as $class){ |
|
38 | 38 | $this->assertSame(TestClass::class, $class->getClass()->getName()); |
39 | 39 | $this->assertSame('abc', $class->getAnnotation()->value); |
40 | 40 | } |
41 | 41 | |
42 | 42 | // Attributes. |
43 | - $classes = $this->getAttributesLocator(__DIR__ . '/Fixtures')->findClasses(ClassAnnotation::class); |
|
43 | + $classes = $this->getAttributesLocator(__DIR__.'/Fixtures')->findClasses(ClassAnnotation::class); |
|
44 | 44 | $classes = iterator_to_array($classes); |
45 | 45 | |
46 | 46 | $this->assertCount(1, $classes); |
47 | 47 | |
48 | - foreach ($classes as $class) { |
|
48 | + foreach ($classes as $class){ |
|
49 | 49 | $this->assertSame(AttributeTestClass::class, $class->getClass()->getName()); |
50 | 50 | $this->assertSame('abc', $class->getAnnotation()->value); |
51 | 51 | } |
@@ -54,24 +54,24 @@ discard block |
||
54 | 54 | public function testLocateProperties() |
55 | 55 | { |
56 | 56 | // Annotations. |
57 | - $props = $this->getAnnotationsLocator(__DIR__ . '/Fixtures')->findProperties(PropertyAnnotation::class); |
|
57 | + $props = $this->getAnnotationsLocator(__DIR__.'/Fixtures')->findProperties(PropertyAnnotation::class); |
|
58 | 58 | $props = iterator_to_array($props); |
59 | 59 | |
60 | 60 | $this->assertCount(1, $props); |
61 | 61 | |
62 | - foreach ($props as $prop) { |
|
62 | + foreach ($props as $prop){ |
|
63 | 63 | $this->assertSame(TestClass::class, $prop->getClass()->getName()); |
64 | 64 | $this->assertSame('name', $prop->getProperty()->getName()); |
65 | 65 | $this->assertSame('123', $prop->getAnnotation()->id); |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Attributes. |
69 | - $props = $this->getAttributesLocator(__DIR__ . '/Fixtures')->findProperties(PropertyAnnotation::class); |
|
69 | + $props = $this->getAttributesLocator(__DIR__.'/Fixtures')->findProperties(PropertyAnnotation::class); |
|
70 | 70 | $props = iterator_to_array($props); |
71 | 71 | |
72 | 72 | $this->assertCount(1, $props); |
73 | 73 | |
74 | - foreach ($props as $prop) { |
|
74 | + foreach ($props as $prop){ |
|
75 | 75 | $this->assertSame(AttributeTestClass::class, $prop->getClass()->getName()); |
76 | 76 | $this->assertSame('name', $prop->getProperty()->getName()); |
77 | 77 | $this->assertSame('123', $prop->getAnnotation()->id); |
@@ -81,24 +81,24 @@ discard block |
||
81 | 81 | public function testLocateMethods() |
82 | 82 | { |
83 | 83 | // Annotations. |
84 | - $methods = $this->getAnnotationsLocator(__DIR__ . '/Fixtures')->findMethods(MethodAnnotation::class); |
|
84 | + $methods = $this->getAnnotationsLocator(__DIR__.'/Fixtures')->findMethods(MethodAnnotation::class); |
|
85 | 85 | $methods = iterator_to_array($methods); |
86 | 86 | |
87 | 87 | $this->assertCount(1, $methods); |
88 | 88 | |
89 | - foreach ($methods as $m) { |
|
89 | + foreach ($methods as $m){ |
|
90 | 90 | $this->assertSame(TestClass::class, $m->getClass()->getName()); |
91 | 91 | $this->assertSame('testMethod', $m->getMethod()->getName()); |
92 | 92 | $this->assertSame('/', $m->getAnnotation()->path); |
93 | 93 | } |
94 | 94 | |
95 | 95 | // Attributes. |
96 | - $methods = $this->getAttributesLocator(__DIR__ . '/Fixtures')->findMethods(MethodAnnotation::class); |
|
96 | + $methods = $this->getAttributesLocator(__DIR__.'/Fixtures')->findMethods(MethodAnnotation::class); |
|
97 | 97 | $methods = iterator_to_array($methods); |
98 | 98 | |
99 | 99 | $this->assertCount(1, $methods); |
100 | 100 | |
101 | - foreach ($methods as $m) { |
|
101 | + foreach ($methods as $m){ |
|
102 | 102 | $this->assertSame(AttributeTestClass::class, $m->getClass()->getName()); |
103 | 103 | $this->assertSame('testMethod', $m->getMethod()->getName()); |
104 | 104 | $this->assertSame('/', $m->getAnnotation()->path); |