@@ -53,8 +53,7 @@ discard block |
||
53 | 53 | * @class CsvReader |
54 | 54 | * @package Platine\Framework\Helper |
55 | 55 | */ |
56 | -class CsvReader |
|
57 | -{ |
|
56 | +class CsvReader { |
|
58 | 57 | /** |
59 | 58 | * The valid delimiters list |
60 | 59 | * @var array<string> |
@@ -168,7 +167,7 @@ discard block |
||
168 | 167 | */ |
169 | 168 | public function setDelimiter(string $delimiter): self |
170 | 169 | { |
171 | - if (!in_array($delimiter, $this->validDelimiters)) { |
|
170 | + if (!in_array($delimiter, $this->validDelimiters)) { |
|
172 | 171 | throw new InvalidArgumentException(sprintf( |
173 | 172 | 'Invalid delimiter [%s], must be one of [%s]', |
174 | 173 | $delimiter, |
@@ -187,7 +186,7 @@ discard block |
||
187 | 186 | public function parse(): self |
188 | 187 | { |
189 | 188 | $fp = fopen($this->file, 'r'); |
190 | - if ($fp === false) { |
|
189 | + if ($fp === false) { |
|
191 | 190 | throw new InvalidArgumentException(sprintf( |
192 | 191 | 'The file [%s] does not exist or readable', |
193 | 192 | $this->file |
@@ -195,14 +194,14 @@ discard block |
||
195 | 194 | } |
196 | 195 | |
197 | 196 | $i = 0; |
198 | - while (($data = fgetcsv($fp, $this->limit, $this->delimiter)) !== false) { |
|
197 | + while (($data = fgetcsv($fp, $this->limit, $this->delimiter)) !== false) { |
|
199 | 198 | // skip all empty lines |
200 | - if ($data[0] !== null) { |
|
201 | - if ($i === 0) { |
|
199 | + if ($data[0] !== null) { |
|
200 | + if ($i === 0) { |
|
202 | 201 | $this->headers = array_map([$this, 'sanitize'], $data); |
203 | - } else { |
|
202 | + } else { |
|
204 | 203 | $result = array_combine($this->headers, $data); |
205 | - if ($result !== false) { |
|
204 | + if ($result !== false) { |
|
206 | 205 | $this->data[] = $result; |
207 | 206 | } |
208 | 207 | } |
@@ -223,7 +222,7 @@ discard block |
||
223 | 222 | */ |
224 | 223 | protected function checkFile(string $file): void |
225 | 224 | { |
226 | - if (file_exists($file) === false) { |
|
225 | + if (file_exists($file) === false) { |
|
227 | 226 | throw new InvalidArgumentException(sprintf( |
228 | 227 | 'The file [%s] does not exist', |
229 | 228 | $file |
@@ -54,8 +54,7 @@ discard block |
||
54 | 54 | * @class Timer |
55 | 55 | * @package Platine\Framework\Helper\Timer |
56 | 56 | */ |
57 | -class Timer |
|
58 | -{ |
|
57 | +class Timer { |
|
59 | 58 | public const NOT_STARTED = 0; |
60 | 59 | public const STARTED = 1; |
61 | 60 | public const PAUSED = 2; |
@@ -89,8 +88,7 @@ discard block |
||
89 | 88 | * Create new timer instance |
90 | 89 | * @param string $name |
91 | 90 | */ |
92 | - public function __construct(string $name) |
|
93 | - { |
|
91 | + public function __construct(string $name) { |
|
94 | 92 | $this->name = $name; |
95 | 93 | } |
96 | 94 | |
@@ -101,7 +99,7 @@ discard block |
||
101 | 99 | public function getTime(): float |
102 | 100 | { |
103 | 101 | $currentRuntime = 0; |
104 | - if ($this->state === self::STARTED) { |
|
102 | + if ($this->state === self::STARTED) { |
|
105 | 103 | $time = microtime(true); |
106 | 104 | $currentRuntime = $time - $this->startTime; |
107 | 105 | } |
@@ -115,11 +113,11 @@ discard block |
||
115 | 113 | */ |
116 | 114 | public function stop(): bool |
117 | 115 | { |
118 | - if ($this->state === self::STARTED) { |
|
116 | + if ($this->state === self::STARTED) { |
|
119 | 117 | $this->pause(); |
120 | 118 | } |
121 | 119 | |
122 | - if ($this->state === self::PAUSED) { |
|
120 | + if ($this->state === self::PAUSED) { |
|
123 | 121 | $this->state = self::STOPPED; |
124 | 122 | |
125 | 123 | return true; |
@@ -134,7 +132,7 @@ discard block |
||
134 | 132 | */ |
135 | 133 | public function pause(): bool |
136 | 134 | { |
137 | - if ($this->state !== self::STARTED) { |
|
135 | + if ($this->state !== self::STARTED) { |
|
138 | 136 | return false; |
139 | 137 | } |
140 | 138 | $time = microtime(true); |
@@ -153,7 +151,7 @@ discard block |
||
153 | 151 | */ |
154 | 152 | public function start(): bool |
155 | 153 | { |
156 | - if ($this->canStart() === false) { |
|
154 | + if ($this->canStart() === false) { |
|
157 | 155 | return false; |
158 | 156 | } |
159 | 157 | |
@@ -174,7 +172,7 @@ discard block |
||
174 | 172 | */ |
175 | 173 | public function canStart(): bool |
176 | 174 | { |
177 | - if (in_array($this->state, [self::NOT_STARTED, self::PAUSED])) { |
|
175 | + if (in_array($this->state, [self::NOT_STARTED, self::PAUSED])) { |
|
178 | 176 | return true; |
179 | 177 | } |
180 | 178 | |
@@ -207,7 +205,7 @@ discard block |
||
207 | 205 | */ |
208 | 206 | protected function setState(int $state): self |
209 | 207 | { |
210 | - if ($state < 0 || $state > 3) { |
|
208 | + if ($state < 0 || $state > 3) { |
|
211 | 209 | throw new InvalidArgumentException(sprintf( |
212 | 210 | 'Invalid state [%d] must be between [0-3]', |
213 | 211 | $state |
@@ -142,10 +142,10 @@ |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | - * Get watch |
|
146 | - * @param string $name |
|
147 | - * @return Timer |
|
148 | - */ |
|
145 | + * Get watch |
|
146 | + * @param string $name |
|
147 | + * @return Timer |
|
148 | + */ |
|
149 | 149 | public function getWatch(string $name): Timer |
150 | 150 | { |
151 | 151 | if (array_key_exists($name, $this->timers) === false) { |
@@ -54,8 +54,7 @@ discard block |
||
54 | 54 | * @class Watch |
55 | 55 | * @package Platine\Framework\Helper\Timer |
56 | 56 | */ |
57 | -class Watch |
|
58 | -{ |
|
57 | +class Watch { |
|
59 | 58 | /** |
60 | 59 | * The default name to use if none is provided |
61 | 60 | */ |
@@ -86,7 +85,7 @@ discard block |
||
86 | 85 | */ |
87 | 86 | public function pause(string $name = self::WATCH_DEFAULT_NAME): bool |
88 | 87 | { |
89 | - if ($this->exists($name) === false) { |
|
88 | + if ($this->exists($name) === false) { |
|
90 | 89 | return false; |
91 | 90 | } |
92 | 91 | |
@@ -100,7 +99,7 @@ discard block |
||
100 | 99 | */ |
101 | 100 | public function stop(string $name = self::WATCH_DEFAULT_NAME): bool |
102 | 101 | { |
103 | - if ($this->exists($name) === false) { |
|
102 | + if ($this->exists($name) === false) { |
|
104 | 103 | return false; |
105 | 104 | } |
106 | 105 | |
@@ -114,7 +113,7 @@ discard block |
||
114 | 113 | */ |
115 | 114 | public function getTime(string $name = self::WATCH_DEFAULT_NAME): float |
116 | 115 | { |
117 | - if ($this->exists($name) === false) { |
|
116 | + if ($this->exists($name) === false) { |
|
118 | 117 | return -1; |
119 | 118 | } |
120 | 119 | |
@@ -128,7 +127,7 @@ discard block |
||
128 | 127 | */ |
129 | 128 | public function addWatch(string $name): self |
130 | 129 | { |
131 | - if (array_key_exists($name, $this->timers)) { |
|
130 | + if (array_key_exists($name, $this->timers)) { |
|
132 | 131 | throw new InvalidArgumentException(sprintf( |
133 | 132 | 'Watch with the name [%s] already exist', |
134 | 133 | $name |
@@ -148,7 +147,7 @@ discard block |
||
148 | 147 | */ |
149 | 148 | public function getWatch(string $name): Timer |
150 | 149 | { |
151 | - if (array_key_exists($name, $this->timers) === false) { |
|
150 | + if (array_key_exists($name, $this->timers) === false) { |
|
152 | 151 | throw new InvalidArgumentException(sprintf( |
153 | 152 | 'Watch with the name [%s] does not exist', |
154 | 153 | $name |
@@ -185,7 +184,7 @@ discard block |
||
185 | 184 | public function info(int $decimal = 6): array |
186 | 185 | { |
187 | 186 | $result = []; |
188 | - foreach ($this->timers as $name => /** @var Timer $timer */ $timer) { |
|
187 | + foreach ($this->timers as $name => /** @var Timer $timer */ $timer) { |
|
189 | 188 | $result[$name] = number_format($timer->getTime(), $decimal); |
190 | 189 | } |
191 | 190 | return $result; |
@@ -53,8 +53,7 @@ discard block |
||
53 | 53 | * @class Flash |
54 | 54 | * @package Platine\Framework\Helper |
55 | 55 | */ |
56 | -class Flash |
|
57 | -{ |
|
56 | +class Flash { |
|
58 | 57 | /** |
59 | 58 | * The session instance |
60 | 59 | * @var Session |
@@ -65,8 +64,7 @@ discard block |
||
65 | 64 | * Create new instance |
66 | 65 | * @param Session $session |
67 | 66 | */ |
68 | - public function __construct(Session $session) |
|
69 | - { |
|
67 | + public function __construct(Session $session) { |
|
70 | 68 | $this->session = $session; |
71 | 69 | } |
72 | 70 |
@@ -51,8 +51,7 @@ |
||
51 | 51 | * @class IdentityInterface |
52 | 52 | * @package Platine\Framework\Auth |
53 | 53 | */ |
54 | -interface IdentityInterface |
|
55 | -{ |
|
54 | +interface IdentityInterface { |
|
56 | 55 | /** |
57 | 56 | * Return the id of the current user |
58 | 57 | * @return mixed |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | * @package Platine\Framework\Auth\Middleware |
63 | 63 | * @template T |
64 | 64 | */ |
65 | -class AuthorizationMiddleware implements MiddlewareInterface |
|
66 | -{ |
|
65 | +class AuthorizationMiddleware implements MiddlewareInterface { |
|
67 | 66 | /** |
68 | 67 | * The Authorization instance |
69 | 68 | * @var AuthorizationInterface |
@@ -92,7 +91,7 @@ discard block |
||
92 | 91 | AuthorizationInterface $authorization, |
93 | 92 | Config $config, |
94 | 93 | RouteHelper $routeHelper |
95 | - ) { |
|
94 | + ) { |
|
96 | 95 | $this->authorization = $authorization; |
97 | 96 | $this->config = $config; |
98 | 97 | $this->routeHelper = $routeHelper; |
@@ -108,17 +107,17 @@ discard block |
||
108 | 107 | //If no route has been match no need check for authorization |
109 | 108 | /** @var ?Route $route */ |
110 | 109 | $route = $request->getAttribute(Route::class); |
111 | - if (!$route) { |
|
110 | + if (!$route) { |
|
112 | 111 | return $handler->handle($request); |
113 | 112 | } |
114 | 113 | |
115 | 114 | $permission = $route->getAttribute('permission'); |
116 | 115 | |
117 | - if (empty($permission)) { |
|
116 | + if (empty($permission)) { |
|
118 | 117 | return $handler->handle($request); |
119 | 118 | } |
120 | 119 | |
121 | - if (!$this->authorization->isGranted($permission)) { |
|
120 | + if (!$this->authorization->isGranted($permission)) { |
|
122 | 121 | $unauthorizedRoute = $this->config->get( |
123 | 122 | 'auth.authorization.unauthorized_route' |
124 | 123 | ); |
@@ -61,8 +61,7 @@ discard block |
||
61 | 61 | * @package Platine\Framework\Auth\Middleware |
62 | 62 | * @template T |
63 | 63 | */ |
64 | -class ApiAuthenticationMiddleware implements MiddlewareInterface |
|
65 | -{ |
|
64 | +class ApiAuthenticationMiddleware implements MiddlewareInterface { |
|
66 | 65 | /** |
67 | 66 | * The Authentication instance |
68 | 67 | * @var ApiAuthenticationInterface |
@@ -83,7 +82,7 @@ discard block |
||
83 | 82 | public function __construct( |
84 | 83 | ApiAuthenticationInterface $authentication, |
85 | 84 | Config $config |
86 | - ) { |
|
85 | + ) { |
|
87 | 86 | $this->authentication = $authentication; |
88 | 87 | $this->config = $config; |
89 | 88 | } |
@@ -95,11 +94,11 @@ discard block |
||
95 | 94 | ServerRequestInterface $request, |
96 | 95 | RequestHandlerInterface $handler |
97 | 96 | ): ResponseInterface { |
98 | - if (!$this->shouldBeProcessed($request)) { |
|
97 | + if (!$this->shouldBeProcessed($request)) { |
|
99 | 98 | return $handler->handle($request); |
100 | 99 | } |
101 | 100 | |
102 | - if (!$this->authentication->isAuthenticated($request)) { |
|
101 | + if (!$this->authentication->isAuthenticated($request)) { |
|
103 | 102 | return $this->unauthorizedResponse(); |
104 | 103 | } |
105 | 104 | |
@@ -116,19 +115,19 @@ discard block |
||
116 | 115 | //If no route has been match no need check for authentication |
117 | 116 | /** @var ?Route $route */ |
118 | 117 | $route = $request->getAttribute(Route::class); |
119 | - if (!$route) { |
|
118 | + if (!$route) { |
|
120 | 119 | return false; |
121 | 120 | } |
122 | 121 | |
123 | 122 | //Check if the path match |
124 | 123 | $path = $this->config->get('api.auth.path', '/'); |
125 | - if (!preg_match('~^' . $path . '~', $route->getPattern())) { |
|
124 | + if (!preg_match('~^' . $path . '~', $route->getPattern())) { |
|
126 | 125 | return false; |
127 | 126 | } |
128 | 127 | |
129 | 128 | //check if is url whitelist |
130 | 129 | $urls = $this->config->get('api.auth.url_whitelist', []); |
131 | - if (in_array($route->getName(), $urls)) { |
|
130 | + if (in_array($route->getName(), $urls)) { |
|
132 | 131 | return false; |
133 | 132 | } |
134 | 133 |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | * @package Platine\Framework\Auth\Middleware |
63 | 63 | * @template T |
64 | 64 | */ |
65 | -class AuthenticationMiddleware implements MiddlewareInterface |
|
66 | -{ |
|
65 | +class AuthenticationMiddleware implements MiddlewareInterface { |
|
67 | 66 | /** |
68 | 67 | * The Authentication instance |
69 | 68 | * @var AuthenticationInterface |
@@ -92,7 +91,7 @@ discard block |
||
92 | 91 | AuthenticationInterface $authentication, |
93 | 92 | Config $config, |
94 | 93 | RouteHelper $routeHelper |
95 | - ) { |
|
94 | + ) { |
|
96 | 95 | $this->authentication = $authentication; |
97 | 96 | $this->config = $config; |
98 | 97 | $this->routeHelper = $routeHelper; |
@@ -105,11 +104,11 @@ discard block |
||
105 | 104 | ServerRequestInterface $request, |
106 | 105 | RequestHandlerInterface $handler |
107 | 106 | ): ResponseInterface { |
108 | - if (!$this->shouldBeProcessed($request)) { |
|
107 | + if (!$this->shouldBeProcessed($request)) { |
|
109 | 108 | return $handler->handle($request); |
110 | 109 | } |
111 | 110 | |
112 | - if (!$this->authentication->isLogged()) { |
|
111 | + if (!$this->authentication->isLogged()) { |
|
113 | 112 | $authRoute = $this->config->get('auth.authentication.login_route'); |
114 | 113 | $next = $request->getUri()->getPath(); |
115 | 114 | return new RedirectResponse( |
@@ -130,13 +129,13 @@ discard block |
||
130 | 129 | //If no route has been match no need check for authentication |
131 | 130 | /** @var ?Route $route */ |
132 | 131 | $route = $request->getAttribute(Route::class); |
133 | - if (!$route) { |
|
132 | + if (!$route) { |
|
134 | 133 | return false; |
135 | 134 | } |
136 | 135 | |
137 | 136 | //check if is url whitelist |
138 | 137 | $urls = $this->config->get('auth.authentication.url_whitelist', []); |
139 | - if (in_array($route->getName(), $urls)) { |
|
138 | + if (in_array($route->getName(), $urls)) { |
|
140 | 139 | return false; |
141 | 140 | } |
142 | 141 |
@@ -37,6 +37,5 @@ |
||
37 | 37 | * @class AccountLockedException |
38 | 38 | * @package Platine\Framework\Auth\Exception |
39 | 39 | */ |
40 | -class AccountLockedException extends AuthenticationException |
|
41 | -{ |
|
40 | +class AccountLockedException extends AuthenticationException { |
|
42 | 41 | } |