@@ -58,8 +58,7 @@ discard block |
||
58 | 58 | * @class HttpStatus |
59 | 59 | * @package Platine\Framework\Http\Client |
60 | 60 | */ |
61 | -class HttpStatus |
|
62 | -{ |
|
61 | +class HttpStatus { |
|
63 | 62 | // Informational 1xx: |
64 | 63 | public const INFORMATIONAL = 100; |
65 | 64 | public const CONTINUE = 100; |
@@ -232,7 +231,7 @@ discard block |
||
232 | 231 | */ |
233 | 232 | public static function getReasonPhrase(int $statusCode): string |
234 | 233 | { |
235 | - if (array_key_exists($statusCode, self::REASON_PHRASES)) { |
|
234 | + if (array_key_exists($statusCode, self::REASON_PHRASES)) { |
|
236 | 235 | return self::REASON_PHRASES[$statusCode]; |
237 | 236 | } |
238 | 237 | throw new InvalidArgumentException('Invalid status code'); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | // Informational 1xx: |
64 | 64 | public const INFORMATIONAL = 100; |
65 | - public const CONTINUE = 100; |
|
65 | + public const continue = 100; |
|
66 | 66 | public const SWITCHING_PROTOCOLS = 101; |
67 | 67 | |
68 | 68 | // Successful 2xx: |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | public const SERVER_ERROR_END = 600; |
119 | 119 | |
120 | 120 | public const REASON_PHRASES = [ |
121 | - self::CONTINUE => 'Continue', |
|
121 | + self::continue => 'Continue', |
|
122 | 122 | self::SWITCHING_PROTOCOLS => 'Switching Protocols', |
123 | 123 | |
124 | 124 | self::OK => 'OK', |
@@ -52,8 +52,7 @@ |
||
52 | 52 | * @class HttpMethod |
53 | 53 | * @package Platine\Framework\Http\Client |
54 | 54 | */ |
55 | -class HttpMethod |
|
56 | -{ |
|
55 | +class HttpMethod { |
|
57 | 56 | public const HEAD = 'HEAD'; |
58 | 57 | public const GET = 'GET'; |
59 | 58 | public const PUT = 'PUT'; |
@@ -52,8 +52,7 @@ discard block |
||
52 | 52 | * @class HttpCookie |
53 | 53 | * @package Platine\Framework\Http\Client |
54 | 54 | */ |
55 | -class HttpCookie |
|
56 | -{ |
|
55 | +class HttpCookie { |
|
57 | 56 | /** |
58 | 57 | * The name of cookie |
59 | 58 | * @var string |
@@ -113,28 +112,27 @@ discard block |
||
113 | 112 | * Create new instance |
114 | 113 | * @param string $cookieString |
115 | 114 | */ |
116 | - public function __construct(string $cookieString) |
|
117 | - { |
|
115 | + public function __construct(string $cookieString) { |
|
118 | 116 | $parts = array_map('trim', explode(';', $cookieString)); |
119 | - foreach ($parts as $partStr) { |
|
117 | + foreach ($parts as $partStr) { |
|
120 | 118 | $part = array_map('trim', explode('=', $partStr)); |
121 | 119 | $name = $part[0]; |
122 | 120 | $value = $part[1] ?? ''; |
123 | - if (stripos($name, 'Expires') !== false) { |
|
121 | + if (stripos($name, 'Expires') !== false) { |
|
124 | 122 | $this->expires = (int) strtotime($value); |
125 | - } elseif (stripos($name, 'Max-Age') !== false) { |
|
123 | + } elseif (stripos($name, 'Max-Age') !== false) { |
|
126 | 124 | $this->maxAge = intval($value); |
127 | - } elseif (stripos($name, 'Domain') !== false) { |
|
125 | + } elseif (stripos($name, 'Domain') !== false) { |
|
128 | 126 | $this->domain = $value; |
129 | - } elseif (stripos($name, 'Path') !== false) { |
|
127 | + } elseif (stripos($name, 'Path') !== false) { |
|
130 | 128 | $this->path = $value; |
131 | - } elseif (stripos($name, 'Secure') !== false) { |
|
129 | + } elseif (stripos($name, 'Secure') !== false) { |
|
132 | 130 | $this->secure = true; |
133 | - } elseif (stripos($name, 'HttpOnly') !== false) { |
|
131 | + } elseif (stripos($name, 'HttpOnly') !== false) { |
|
134 | 132 | $this->httpOnly = true; |
135 | - } elseif (stripos($name, 'SameSite') !== false) { |
|
133 | + } elseif (stripos($name, 'SameSite') !== false) { |
|
136 | 134 | $this->sameSite = $value; |
137 | - } else { |
|
135 | + } else { |
|
138 | 136 | $this->name = $name; |
139 | 137 | $this->value = $value; |
140 | 138 | } |
@@ -55,8 +55,7 @@ discard block |
||
55 | 55 | * @class HttpResponse |
56 | 56 | * @package Platine\Framework\Http\Client |
57 | 57 | */ |
58 | -class HttpResponse |
|
59 | -{ |
|
58 | +class HttpResponse { |
|
60 | 59 | /** |
61 | 60 | * The request URL |
62 | 61 | * @var string |
@@ -123,13 +122,13 @@ discard block |
||
123 | 122 | array $headers, |
124 | 123 | $response, |
125 | 124 | string $error |
126 | - ) { |
|
125 | + ) { |
|
127 | 126 | $this->url = $requestInfo['url']; |
128 | 127 | $this->statusCode = (int) $requestInfo['http_code']; |
129 | 128 | $this->headers = $headers; |
130 | 129 | $this->cookies = $this->processCookies($headers); |
131 | 130 | |
132 | - if ($response !== false) { |
|
131 | + if ($response !== false) { |
|
133 | 132 | $this->contentType = $requestInfo['content_type']; |
134 | 133 | $this->headerSize = (int) $requestInfo['header_size']; |
135 | 134 | $this->contentLength = (int) ($requestInfo['content_length'] ?? (strlen($response) - $this->headerSize)); |
@@ -190,8 +189,7 @@ discard block |
||
190 | 189 | * @param string $name |
191 | 190 | * @return mixed|null |
192 | 191 | */ |
193 | - public function getHeader(string $name) |
|
194 | - { |
|
192 | + public function getHeader(string $name) { |
|
195 | 193 | return $this->headers[$name] ?? null; |
196 | 194 | } |
197 | 195 | |
@@ -252,7 +250,7 @@ discard block |
||
252 | 250 | bool $assoc = false, |
253 | 251 | int $depth = 512, |
254 | 252 | int $options = 0 |
255 | - ) { |
|
253 | + ) { |
|
256 | 254 | return Json::decode($this->content, $assoc, $depth, $options); |
257 | 255 | } |
258 | 256 | |
@@ -260,8 +258,7 @@ discard block |
||
260 | 258 | * Return the response as XML |
261 | 259 | * @return mixed |
262 | 260 | */ |
263 | - public function xml() |
|
264 | - { |
|
261 | + public function xml() { |
|
265 | 262 | return Xml::decode($this->content); |
266 | 263 | } |
267 | 264 | |
@@ -283,9 +280,9 @@ discard block |
||
283 | 280 | protected function processCookies(array $headers): array |
284 | 281 | { |
285 | 282 | $cookies = []; |
286 | - foreach ($headers as $header => $value) { |
|
287 | - if (stripos($header, 'Set-Cookie') !== false) { |
|
288 | - foreach ($value as $cookieString) { |
|
283 | + foreach ($headers as $header => $value) { |
|
284 | + if (stripos($header, 'Set-Cookie') !== false) { |
|
285 | + foreach ($value as $cookieString) { |
|
289 | 286 | $cookie = new HttpCookie($cookieString); |
290 | 287 | $cookies[$cookie->getName()] = $cookie; |
291 | 288 | } |
@@ -40,6 +40,5 @@ |
||
40 | 40 | * @class HttpClientException |
41 | 41 | * @package Platine\Framework\Http\Client |
42 | 42 | */ |
43 | -class HttpClientException extends Exception |
|
44 | -{ |
|
43 | +class HttpClientException extends Exception { |
|
45 | 44 | } |
@@ -59,14 +59,12 @@ discard block |
||
59 | 59 | * @package Platine\Framework\Form\Param |
60 | 60 | * @template TEntity as Entity |
61 | 61 | */ |
62 | -class BaseParam implements JsonSerializable |
|
63 | -{ |
|
62 | +class BaseParam implements JsonSerializable { |
|
64 | 63 | /** |
65 | 64 | * Create new instance |
66 | 65 | * @param array<string, mixed> $data |
67 | 66 | */ |
68 | - public function __construct(array $data = []) |
|
69 | - { |
|
67 | + public function __construct(array $data = []) { |
|
70 | 68 | // Load default values |
71 | 69 | $this->loadDefaultValues(); |
72 | 70 | |
@@ -81,14 +79,14 @@ discard block |
||
81 | 79 | */ |
82 | 80 | public function load(array $data): void |
83 | 81 | { |
84 | - foreach ($data as $name => $value) { |
|
82 | + foreach ($data as $name => $value) { |
|
85 | 83 | $key = Str::camel($name, true); |
86 | 84 | $typedValue = $this->getPropertyValue($key, $value); |
87 | 85 | |
88 | 86 | $setterMethod = 'set' . ucfirst($key); |
89 | - if (method_exists($this, $setterMethod)) { |
|
87 | + if (method_exists($this, $setterMethod)) { |
|
90 | 88 | $this->{$setterMethod}($typedValue); |
91 | - } elseif (property_exists($this, $key)) { |
|
89 | + } elseif (property_exists($this, $key)) { |
|
92 | 90 | $this->{$key} = $typedValue; |
93 | 91 | } |
94 | 92 | } |
@@ -126,8 +124,7 @@ discard block |
||
126 | 124 | * Convert parameter to JSON array |
127 | 125 | * @return array<string, mixed> |
128 | 126 | */ |
129 | - public function jsonSerialize() |
|
130 | - { |
|
127 | + public function jsonSerialize() { |
|
131 | 128 | return $this->data(); |
132 | 129 | } |
133 | 130 | |
@@ -136,15 +133,14 @@ discard block |
||
136 | 133 | * @param string $name |
137 | 134 | * @return mixed|null |
138 | 135 | */ |
139 | - public function __get($name) |
|
140 | - { |
|
141 | - if (property_exists($this, $name)) { |
|
136 | + public function __get($name) { |
|
137 | + if (property_exists($this, $name)) { |
|
142 | 138 | return $this->{$name}; |
143 | 139 | } |
144 | 140 | |
145 | 141 | //convert to camel |
146 | 142 | $key = Str::camel($name, true); |
147 | - if (property_exists($this, $key)) { |
|
143 | + if (property_exists($this, $key)) { |
|
148 | 144 | return $this->{$key}; |
149 | 145 | } |
150 | 146 | |
@@ -157,11 +153,10 @@ discard block |
||
157 | 153 | * @param mixed $value |
158 | 154 | * @return mixed |
159 | 155 | */ |
160 | - protected function getPropertyValue(string $attribute, $value) |
|
161 | - { |
|
156 | + protected function getPropertyValue(string $attribute, $value) { |
|
162 | 157 | $types = $this->getPropertyTypes(); |
163 | 158 | $property = $types[$attribute] ?? null; |
164 | - if ($property === null) { |
|
159 | + if ($property === null) { |
|
165 | 160 | return $value; |
166 | 161 | } |
167 | 162 | |
@@ -171,13 +166,13 @@ discard block |
||
171 | 166 | if ( |
172 | 167 | in_array($type, ['array', 'object']) === false && |
173 | 168 | strlen((string) $value) === 0 && $allowNull |
174 | - ) { |
|
169 | + ) { |
|
175 | 170 | return null; |
176 | 171 | } |
177 | 172 | |
178 | 173 | $maps = $this->getPropertiesCastMaps(); |
179 | 174 | $map = $maps[$type] ?? []; |
180 | - if (count($map) === 0) { |
|
175 | + if (count($map) === 0) { |
|
181 | 176 | return $value; |
182 | 177 | } |
183 | 178 | |
@@ -197,10 +192,10 @@ discard block |
||
197 | 192 | $reflectionClass = new ReflectionClass($this); |
198 | 193 | /** @var ReflectionProperty[] $properties */ |
199 | 194 | $properties = $reflectionClass->getProperties(ReflectionProperty::IS_PROTECTED); |
200 | - foreach ($properties as $property) { |
|
195 | + foreach ($properties as $property) { |
|
201 | 196 | /** @var ReflectionNamedType|null $type */ |
202 | 197 | $type = $property->getType(); |
203 | - if ($type !== null && $type->isBuiltin()) { |
|
198 | + if ($type !== null && $type->isBuiltin()) { |
|
204 | 199 | $props[$property->getName()] = [$type->getName(), $type->allowsNull(), $property]; |
205 | 200 | } |
206 | 201 | } |
@@ -234,11 +229,11 @@ discard block |
||
234 | 229 | $types = $this->getPropertyTypes(); |
235 | 230 | $maps = $this->getPropertiesCastMaps(); |
236 | 231 | |
237 | - foreach ($types as $attr => $val) { |
|
232 | + foreach ($types as $attr => $val) { |
|
238 | 233 | /** @var ReflectionProperty $property */ |
239 | 234 | $property = $val[2]; |
240 | 235 | $property->setAccessible(true); |
241 | - if (isset($maps[$val[0]]) && $property->isInitialized($this) === false) { |
|
236 | + if (isset($maps[$val[0]]) && $property->isInitialized($this) === false) { |
|
242 | 237 | $data[$attr] = $maps[$val[0]][1]; |
243 | 238 | } |
244 | 239 | } |
@@ -54,14 +54,12 @@ |
||
54 | 54 | * @class AbstractValidator |
55 | 55 | * @package Platine\Framework\Form\Validator |
56 | 56 | */ |
57 | -abstract class AbstractValidator extends Validator |
|
58 | -{ |
|
57 | +abstract class AbstractValidator extends Validator { |
|
59 | 58 | /** |
60 | 59 | * Create new instance |
61 | 60 | * @param Lang $lang |
62 | 61 | */ |
63 | - public function __construct(Lang $lang) |
|
64 | - { |
|
62 | + public function __construct(Lang $lang) { |
|
65 | 63 | parent::__construct($lang); |
66 | 64 | } |
67 | 65 |
@@ -53,8 +53,7 @@ discard block |
||
53 | 53 | * @class BaseKernel |
54 | 54 | * @package Platine\Framework\Kernel |
55 | 55 | */ |
56 | -class BaseKernel |
|
57 | -{ |
|
56 | +class BaseKernel { |
|
58 | 57 | /** |
59 | 58 | * Application instance |
60 | 59 | * @var Application |
@@ -65,8 +64,7 @@ discard block |
||
65 | 64 | * Create new instance |
66 | 65 | * @param Application $app |
67 | 66 | */ |
68 | - public function __construct(Application $app) |
|
69 | - { |
|
67 | + public function __construct(Application $app) { |
|
70 | 68 | $this->app = $app; |
71 | 69 | } |
72 | 70 |
@@ -66,8 +66,7 @@ discard block |
||
66 | 66 | * @package Platine\Framework\Kernel |
67 | 67 | * @template T |
68 | 68 | */ |
69 | -class HttpKernel extends BaseKernel implements RequestHandlerInterface |
|
70 | -{ |
|
69 | +class HttpKernel extends BaseKernel implements RequestHandlerInterface { |
|
71 | 70 | /** |
72 | 71 | * The router instance |
73 | 72 | * @var Router |
@@ -96,7 +95,7 @@ discard block |
||
96 | 95 | Application $app, |
97 | 96 | Router $router, |
98 | 97 | MiddlewareResolverInterface $middlewareResolver |
99 | - ) { |
|
98 | + ) { |
|
100 | 99 | parent::__construct($app); |
101 | 100 | $this->router = $router; |
102 | 101 | $this->middlewareResolver = $middlewareResolver; |
@@ -167,7 +166,7 @@ discard block |
||
167 | 166 | { |
168 | 167 | $handler = clone $this; |
169 | 168 | $middleware = current($handler->middlewares); |
170 | - if ($middleware === false) { |
|
169 | + if ($middleware === false) { |
|
171 | 170 | throw new HttpNotFoundException($request); |
172 | 171 | } |
173 | 172 | next($handler->middlewares); |
@@ -198,7 +197,7 @@ discard block |
||
198 | 197 | //Load providers routes |
199 | 198 | /** @var ServiceProvider[] $providers */ |
200 | 199 | $providers = $this->app->getProviders(); |
201 | - foreach ($providers as $provider) { |
|
200 | + foreach ($providers as $provider) { |
|
202 | 201 | $provider->addRoutes($this->router); |
203 | 202 | } |
204 | 203 | |
@@ -217,7 +216,7 @@ discard block |
||
217 | 216 | /** @var string[] $middlewares */ |
218 | 217 | $middlewares = $config->get('middlewares', []); |
219 | 218 | $this->app->watch()->start('register-middlewares'); |
220 | - foreach ($middlewares as $middleware) { |
|
219 | + foreach ($middlewares as $middleware) { |
|
221 | 220 | $this->use($middleware); |
222 | 221 | } |
223 | 222 | $this->app->watch()->stop('register-middlewares'); |
@@ -233,7 +232,7 @@ discard block |
||
233 | 232 | protected function determineBasePath(): string |
234 | 233 | { |
235 | 234 | $appBasePath = $this->app->getBasePath(); |
236 | - if (!empty($appBasePath)) { |
|
235 | + if (!empty($appBasePath)) { |
|
237 | 236 | return $appBasePath; |
238 | 237 | } |
239 | 238 | |
@@ -241,7 +240,7 @@ discard block |
||
241 | 240 | $config = $this->app->get(Config::class); |
242 | 241 | $configBasePath = $config->get('app.base_path'); |
243 | 242 | |
244 | - if (!empty($configBasePath)) { |
|
243 | + if (!empty($configBasePath)) { |
|
245 | 244 | $this->app->setBasePath($configBasePath); |
246 | 245 | return $configBasePath; |
247 | 246 | } |
@@ -255,7 +254,7 @@ discard block |
||
255 | 254 | $server['SCRIPT_NAME'] ?? '' |
256 | 255 | ), 0, -1)); |
257 | 256 | $this->app->setBasePath($autoBasePath); |
258 | - if (!empty($autoBasePath)) { |
|
257 | + if (!empty($autoBasePath)) { |
|
259 | 258 | return $autoBasePath; |
260 | 259 | } |
261 | 260 |