Passed
Push — master ( 43eb1d...5d3e0a )
by Anton
02:39
created
tests/app/src/Controller/TestController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
 
49 49
     public function input(InputScope $i)
50 50
     {
51
-        return 'value: ' . $i->withPrefix('section')->getValue('query', 'value');
51
+        return 'value: '.$i->withPrefix('section')->getValue('query', 'value');
52 52
     }
53 53
 
54 54
     public function error(): void
Please login to merge, or discard this patch.
src/Auth/Cycle/TokenStorage.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function load(string $id): ?TokenInterface
45 45
     {
46
-        if (strpos($id, ':') === false) {
46
+        if (strpos($id, ':') === false){
47 47
             return null;
48 48
         }
49 49
 
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
         /** @var Token $token */
53 53
         $token = $this->orm->getRepository(Token::class)->findByPK($pk);
54 54
 
55
-        if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) {
55
+        if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))){
56 56
             // hijacked or deleted
57 57
             return null;
58 58
         }
59 59
 
60 60
         $token->setSecretValue($hash);
61 61
 
62
-        if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) {
62
+        if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()){
63 63
             $this->delete($token);
64 64
             return null;
65 65
         }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface
74 74
     {
75
-        try {
75
+        try{
76 76
             $token = new Token(
77 77
                 $this->issueID(),
78 78
                 $this->randomHash(128),
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
             $this->em->persist($token)->run();
85 85
 
86 86
             return $token;
87
-        } catch (\Throwable $e) {
87
+        }catch (\Throwable $e){
88 88
             throw new TokenStorageException('Unable to create token', $e->getCode(), $e);
89 89
         }
90 90
     }
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
      */
95 95
     public function delete(TokenInterface $token): void
96 96
     {
97
-        try {
97
+        try{
98 98
             $this->em->delete($token)->run();
99
-        } catch (\Throwable $e) {
99
+        }catch (\Throwable $e){
100 100
             throw new TokenStorageException('Unable to delete token', $e->getCode(), $e);
101 101
         }
102 102
     }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             $this->orm->getSource(Token::class)->getTable()
116 116
         );
117 117
 
118
-        while ((clone $query)->where('id', $id)->count('id') !== 0) {
118
+        while ((clone $query)->where('id', $id)->count('id') !== 0){
119 119
             $id = $this->randomHash(64);
120 120
         }
121 121
 
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -43,7 +43,8 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function load(string $id): ?TokenInterface
45 45
     {
46
-        if (strpos($id, ':') === false) {
46
+        if (strpos($id, ':') === false)
47
+        {
47 48
             return null;
48 49
         }
49 50
 
@@ -52,14 +53,16 @@  discard block
 block discarded – undo
52 53
         /** @var Token $token */
53 54
         $token = $this->orm->getRepository(Token::class)->findByPK($pk);
54 55
 
55
-        if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) {
56
+        if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash)))
57
+        {
56 58
             // hijacked or deleted
57 59
             return null;
58 60
         }
59 61
 
60 62
         $token->setSecretValue($hash);
61 63
 
62
-        if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) {
64
+        if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime())
65
+        {
63 66
             $this->delete($token);
64 67
             return null;
65 68
         }
@@ -72,7 +75,8 @@  discard block
 block discarded – undo
72 75
      */
73 76
     public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface
74 77
     {
75
-        try {
78
+        try
79
+        {
76 80
             $token = new Token(
77 81
                 $this->issueID(),
78 82
                 $this->randomHash(128),
@@ -84,7 +88,9 @@  discard block
 block discarded – undo
84 88
             $this->em->persist($token)->run();
85 89
 
86 90
             return $token;
87
-        } catch (\Throwable $e) {
91
+        }
92
+        catch (\Throwable $e)
93
+        {
88 94
             throw new TokenStorageException('Unable to create token', $e->getCode(), $e);
89 95
         }
90 96
     }
@@ -94,9 +100,12 @@  discard block
 block discarded – undo
94 100
      */
95 101
     public function delete(TokenInterface $token): void
96 102
     {
97
-        try {
103
+        try
104
+        {
98 105
             $this->em->delete($token)->run();
99
-        } catch (\Throwable $e) {
106
+        }
107
+        catch (\Throwable $e)
108
+        {
100 109
             throw new TokenStorageException('Unable to delete token', $e->getCode(), $e);
101 110
         }
102 111
     }
@@ -115,7 +124,8 @@  discard block
 block discarded – undo
115 124
             $this->orm->getSource(Token::class)->getTable()
116 125
         );
117 126
 
118
-        while ((clone $query)->where('id', $id)->count('id') !== 0) {
127
+        while ((clone $query)->where('id', $id)->count('id') !== 0)
128
+        {
119 129
             $id = $this->randomHash(64);
120 130
         }
121 131
 
Please login to merge, or discard this patch.
src/Domain/FilterInterceptor.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function process(string $controller, string $action, array $parameters, CoreInterface $core)
51 51
     {
52
-        foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) {
53
-            if (isset($parameters[$parameter])) {
52
+        foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass){
53
+            if (isset($parameters[$parameter])){
54 54
                 continue;
55 55
             }
56 56
 
57 57
             /** @var FilterInterface $filter */
58 58
             $filter = $this->container->get($filterClass);
59 59
 
60
-            if (!$filter->isValid()) {
60
+            if (!$filter->isValid()){
61 61
                 return $this->renderInvalid($filter);
62 62
             }
63 63
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      */
76 76
     protected function renderInvalid(FilterInterface $filter)
77 77
     {
78
-        switch ($this->strategy) {
78
+        switch ($this->strategy){
79 79
             case self::STRATEGY_JSON_RESPONSE:
80 80
                 return [
81 81
                     'status' => 400,
@@ -94,23 +94,23 @@  discard block
 block discarded – undo
94 94
     private function getDeclaredFilters(string $controller, string $action): array
95 95
     {
96 96
         $key = sprintf('%s:%s', $controller, $action);
97
-        if (array_key_exists($key, $this->cache)) {
97
+        if (array_key_exists($key, $this->cache)){
98 98
             return $this->cache[$key];
99 99
         }
100 100
 
101 101
         $this->cache[$key] = [];
102
-        try {
102
+        try{
103 103
             $method = new \ReflectionMethod($controller, $action);
104
-        } catch (\ReflectionException $e) {
104
+        }catch (\ReflectionException $e){
105 105
             return [];
106 106
         }
107 107
 
108
-        foreach ($method->getParameters() as $parameter) {
109
-            if ($parameter->getClass() === null) {
108
+        foreach ($method->getParameters() as $parameter){
109
+            if ($parameter->getClass() === null){
110 110
                 continue;
111 111
             }
112 112
 
113
-            if ($parameter->getClass()->implementsInterface(FilterInterface::class)) {
113
+            if ($parameter->getClass()->implementsInterface(FilterInterface::class)){
114 114
                 $this->cache[$key][$parameter->getName()] = $parameter->getClass()->getName();
115 115
             }
116 116
         }
Please login to merge, or discard this patch.
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -49,15 +49,18 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function process(string $controller, string $action, array $parameters, CoreInterface $core)
51 51
     {
52
-        foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) {
53
-            if (isset($parameters[$parameter])) {
52
+        foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass)
53
+        {
54
+            if (isset($parameters[$parameter]))
55
+            {
54 56
                 continue;
55 57
             }
56 58
 
57 59
             /** @var FilterInterface $filter */
58 60
             $filter = $this->container->get($filterClass);
59 61
 
60
-            if (!$filter->isValid()) {
62
+            if (!$filter->isValid())
63
+            {
61 64
                 return $this->renderInvalid($filter);
62 65
             }
63 66
 
@@ -75,7 +78,8 @@  discard block
 block discarded – undo
75 78
      */
76 79
     protected function renderInvalid(FilterInterface $filter)
77 80
     {
78
-        switch ($this->strategy) {
81
+        switch ($this->strategy)
82
+        {
79 83
             case self::STRATEGY_JSON_RESPONSE:
80 84
                 return [
81 85
                     'status' => 400,
@@ -94,23 +98,30 @@  discard block
 block discarded – undo
94 98
     private function getDeclaredFilters(string $controller, string $action): array
95 99
     {
96 100
         $key = sprintf('%s:%s', $controller, $action);
97
-        if (array_key_exists($key, $this->cache)) {
101
+        if (array_key_exists($key, $this->cache))
102
+        {
98 103
             return $this->cache[$key];
99 104
         }
100 105
 
101 106
         $this->cache[$key] = [];
102
-        try {
107
+        try
108
+        {
103 109
             $method = new \ReflectionMethod($controller, $action);
104
-        } catch (\ReflectionException $e) {
110
+        }
111
+        catch (\ReflectionException $e)
112
+        {
105 113
             return [];
106 114
         }
107 115
 
108
-        foreach ($method->getParameters() as $parameter) {
109
-            if ($parameter->getClass() === null) {
116
+        foreach ($method->getParameters() as $parameter)
117
+        {
118
+            if ($parameter->getClass() === null)
119
+            {
110 120
                 continue;
111 121
             }
112 122
 
113
-            if ($parameter->getClass()->implementsInterface(FilterInterface::class)) {
123
+            if ($parameter->getClass()->implementsInterface(FilterInterface::class))
124
+            {
114 125
                 $this->cache[$key][$parameter->getName()] = $parameter->getClass()->getName();
115 126
             }
116 127
         }
Please login to merge, or discard this patch.
src/Domain/CycleInterceptor.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
     {
46 46
         $entities = $this->getDeclaredEntities($controller, $action);
47 47
 
48
-        foreach ($entities as $parameter => $role) {
48
+        foreach ($entities as $parameter => $role){
49 49
             $value = $this->getParameter($role, $parameters, count($entities) === 1);
50
-            if ($value === null) {
50
+            if ($value === null){
51 51
                 throw new ControllerException(
52 52
                     "Entity `{$role}` can not be found",
53 53
                     ControllerException::NOT_FOUND
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
             }
56 56
 
57 57
             $entity = $this->resolveEntity($role, $value);
58
-            if ($entity === null) {
58
+            if ($entity === null){
59 59
                 throw new ControllerException(
60 60
                     "Entity `{$role}` can not be found",
61 61
                     ControllerException::NOT_FOUND
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     protected function getParameter(string $role, array $parameters, bool $useDefault = false)
78 78
     {
79
-        if (!$useDefault) {
79
+        if (!$useDefault){
80 80
             return $parameters[$role] ?? null;
81 81
         }
82 82
 
@@ -101,23 +101,23 @@  discard block
 block discarded – undo
101 101
     private function getDeclaredEntities(string $controller, string $action): array
102 102
     {
103 103
         $key = sprintf('%s:%s', $controller, $action);
104
-        if (array_key_exists($key, $this->cache)) {
104
+        if (array_key_exists($key, $this->cache)){
105 105
             return $this->cache[$key];
106 106
         }
107 107
 
108 108
         $this->cache[$key] = [];
109
-        try {
109
+        try{
110 110
             $method = new \ReflectionMethod($controller, $action);
111
-        } catch (\ReflectionException $e) {
111
+        }catch (\ReflectionException $e){
112 112
             return [];
113 113
         }
114 114
 
115
-        foreach ($method->getParameters() as $parameter) {
116
-            if ($parameter->getClass() === null) {
115
+        foreach ($method->getParameters() as $parameter){
116
+            if ($parameter->getClass() === null){
117 117
                 continue;
118 118
             }
119 119
 
120
-            if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) {
120
+            if ($this->orm->getSchema()->defines($parameter->getClass()->getName())){
121 121
                 $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName());
122 122
             }
123 123
         }
Please login to merge, or discard this patch.
Braces   +21 added lines, -10 removed lines patch added patch discarded remove patch
@@ -45,9 +45,11 @@  discard block
 block discarded – undo
45 45
     {
46 46
         $entities = $this->getDeclaredEntities($controller, $action);
47 47
 
48
-        foreach ($entities as $parameter => $role) {
48
+        foreach ($entities as $parameter => $role)
49
+        {
49 50
             $value = $this->getParameter($role, $parameters, count($entities) === 1);
50
-            if ($value === null) {
51
+            if ($value === null)
52
+            {
51 53
                 throw new ControllerException(
52 54
                     "Entity `{$role}` can not be found",
53 55
                     ControllerException::NOT_FOUND
@@ -55,7 +57,8 @@  discard block
 block discarded – undo
55 57
             }
56 58
 
57 59
             $entity = $this->resolveEntity($role, $value);
58
-            if ($entity === null) {
60
+            if ($entity === null)
61
+            {
59 62
                 throw new ControllerException(
60 63
                     "Entity `{$role}` can not be found",
61 64
                     ControllerException::NOT_FOUND
@@ -76,7 +79,8 @@  discard block
 block discarded – undo
76 79
      */
77 80
     protected function getParameter(string $role, array $parameters, bool $useDefault = false)
78 81
     {
79
-        if (!$useDefault) {
82
+        if (!$useDefault)
83
+        {
80 84
             return $parameters[$role] ?? null;
81 85
         }
82 86
 
@@ -101,23 +105,30 @@  discard block
 block discarded – undo
101 105
     private function getDeclaredEntities(string $controller, string $action): array
102 106
     {
103 107
         $key = sprintf('%s:%s', $controller, $action);
104
-        if (array_key_exists($key, $this->cache)) {
108
+        if (array_key_exists($key, $this->cache))
109
+        {
105 110
             return $this->cache[$key];
106 111
         }
107 112
 
108 113
         $this->cache[$key] = [];
109
-        try {
114
+        try
115
+        {
110 116
             $method = new \ReflectionMethod($controller, $action);
111
-        } catch (\ReflectionException $e) {
117
+        }
118
+        catch (\ReflectionException $e)
119
+        {
112 120
             return [];
113 121
         }
114 122
 
115
-        foreach ($method->getParameters() as $parameter) {
116
-            if ($parameter->getClass() === null) {
123
+        foreach ($method->getParameters() as $parameter)
124
+        {
125
+            if ($parameter->getClass() === null)
126
+            {
117 127
                 continue;
118 128
             }
119 129
 
120
-            if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) {
130
+            if ($this->orm->getSchema()->defines($parameter->getClass()->getName()))
131
+            {
121 132
                 $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName());
122 133
             }
123 134
         }
Please login to merge, or discard this patch.
src/Bootloader/DomainBootloader.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
     {
39 39
         $core = new InterceptableCore($core);
40 40
 
41
-        foreach (static::INTERCEPTORS as $interceptor) {
41
+        foreach (static::INTERCEPTORS as $interceptor){
42 42
             $core->addInterceptor($container->get($interceptor));
43 43
         }
44 44
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,8 @@
 block discarded – undo
38 38
     {
39 39
         $core = new InterceptableCore($core);
40 40
 
41
-        foreach (static::INTERCEPTORS as $interceptor) {
41
+        foreach (static::INTERCEPTORS as $interceptor)
42
+        {
42 43
             $core->addInterceptor($container->get($interceptor));
43 44
         }
44 45
 
Please login to merge, or discard this patch.
src/Domain/GuardInterceptor.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     {
48 48
         $permission = $this->getPermissions($controller, $action);
49 49
 
50
-        if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) {
50
+        if ($permission !== null && !$this->guard->allows($permission[0], $parameters)){
51 51
             throw new ControllerException(
52 52
                 sprintf(
53 53
                     'Unauthorized permission `%s` for action `%s`->`%s`',
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
     private function getPermissions(string $controller, string $action): ?array
75 75
     {
76 76
         $key = sprintf('%s:%s', $controller, $action);
77
-        if (array_key_exists($key, $this->cache)) {
77
+        if (array_key_exists($key, $this->cache)){
78 78
             return $this->cache[$key];
79 79
         }
80 80
 
81 81
         $this->cache[$key] = null;
82
-        try {
82
+        try{
83 83
             $method = new \ReflectionMethod($controller, $action);
84
-        } catch (\ReflectionException $e) {
84
+        }catch (\ReflectionException $e){
85 85
             return null;
86 86
         }
87 87
 
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
             Guarded::class
100 100
         );
101 101
 
102
-        if ($action === null) {
102
+        if ($action === null){
103 103
             return null;
104 104
         }
105 105
 
106
-        if ($action->permission === null && $namespace === null) {
106
+        if ($action->permission === null && $namespace === null){
107 107
             throw new InterceptorException(
108 108
                 'Unable to apply @Guarded annotation without specified permission name or @GuardNamespace'
109 109
             );
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
             ControllerException::FORBIDDEN
130 130
         ];
131 131
 
132
-        if ($guarded->permission === null && $ns === null) {
132
+        if ($guarded->permission === null && $ns === null){
133 133
             throw new InterceptorException(sprintf(
134 134
                 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
135 135
                 $method->getDeclaringClass()->getName(),
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
             ));
138 138
         }
139 139
 
140
-        if ($ns !== null) {
140
+        if ($ns !== null){
141 141
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
142 142
         }
143 143
 
144
-        switch ($guarded->else) {
144
+        switch ($guarded->else){
145 145
             case 'badAction':
146 146
                 $permission[1] = ControllerException::BAD_ACTION;
147 147
                 break;
Please login to merge, or discard this patch.
Braces   +19 added lines, -9 removed lines patch added patch discarded remove patch
@@ -47,7 +47,8 @@  discard block
 block discarded – undo
47 47
     {
48 48
         $permission = $this->getPermissions($controller, $action);
49 49
 
50
-        if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) {
50
+        if ($permission !== null && !$this->guard->allows($permission[0], $parameters))
51
+        {
51 52
             throw new ControllerException(
52 53
                 sprintf(
53 54
                     'Unauthorized permission `%s` for action `%s`->`%s`',
@@ -74,14 +75,18 @@  discard block
 block discarded – undo
74 75
     private function getPermissions(string $controller, string $action): ?array
75 76
     {
76 77
         $key = sprintf('%s:%s', $controller, $action);
77
-        if (array_key_exists($key, $this->cache)) {
78
+        if (array_key_exists($key, $this->cache))
79
+        {
78 80
             return $this->cache[$key];
79 81
         }
80 82
 
81 83
         $this->cache[$key] = null;
82
-        try {
84
+        try
85
+        {
83 86
             $method = new \ReflectionMethod($controller, $action);
84
-        } catch (\ReflectionException $e) {
87
+        }
88
+        catch (\ReflectionException $e)
89
+        {
85 90
             return null;
86 91
         }
87 92
 
@@ -99,11 +104,13 @@  discard block
 block discarded – undo
99 104
             Guarded::class
100 105
         );
101 106
 
102
-        if ($action === null) {
107
+        if ($action === null)
108
+        {
103 109
             return null;
104 110
         }
105 111
 
106
-        if ($action->permission === null && $namespace === null) {
112
+        if ($action->permission === null && $namespace === null)
113
+        {
107 114
             throw new InterceptorException(
108 115
                 'Unable to apply @Guarded annotation without specified permission name or @GuardNamespace'
109 116
             );
@@ -129,7 +136,8 @@  discard block
 block discarded – undo
129 136
             ControllerException::FORBIDDEN
130 137
         ];
131 138
 
132
-        if ($guarded->permission === null && $ns === null) {
139
+        if ($guarded->permission === null && $ns === null)
140
+        {
133 141
             throw new InterceptorException(sprintf(
134 142
                 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
135 143
                 $method->getDeclaringClass()->getName(),
@@ -137,11 +145,13 @@  discard block
 block discarded – undo
137 145
             ));
138 146
         }
139 147
 
140
-        if ($ns !== null) {
148
+        if ($ns !== null)
149
+        {
141 150
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
142 151
         }
143 152
 
144
-        switch ($guarded->else) {
153
+        switch ($guarded->else)
154
+        {
145 155
             case 'badAction':
146 156
                 $permission[1] = ControllerException::BAD_ACTION;
147 157
                 break;
Please login to merge, or discard this patch.