Skip to content

Commit 2c49919

Browse files
committed
refactor: refactoring with phpstorm to deep debugs
1 parent 87816b9 commit 2c49919

148 files changed

Lines changed: 1355 additions & 1252 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
"php": "^8.1",
1212
"bowphp/tintin": "^3.0",
1313
"filp/whoops": "^2.1",
14-
"nesbot/carbon": "^2.16",
14+
"nesbot/carbon": "3.8.4",
1515
"psy/psysh": "v0.12.*",
1616
"fakerphp/faker": "^1.20",
1717
"neitanod/forceutf8": "^2.0",
18-
"ramsey/uuid": "^4.7"
18+
"ramsey/uuid": "^4.7",
19+
"ext-ftp": "*"
1920
},
2021
"require-dev": {
21-
"pda/pheanstalk": "^4.0.5",
22-
"phpunit/phpunit": "^9",
22+
"pda/pheanstalk": "^5.0",
23+
"phpunit/phpunit": "^9.6",
2324
"monolog/monolog": "^1.22",
2425
"twig/twig": "^3",
2526
"squizlabs/php_codesniffer": "3.*",

src/Application/Application.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
use Bow\Container\Action;
1010
use Bow\Configuration\Loader;
1111
use Bow\Contracts\ResponseInterface;
12+
use Bow\Http\Exception\BadRequestException;
1213
use Bow\Http\Exception\HttpException;
1314
use Bow\Http\Request;
1415
use Bow\Http\Response;
1516
use Bow\Router\Exception\RouterException;
1617
use Bow\Router\Resource;
1718
use Bow\Router\Router;
1819
use Bow\Router\Route;
20+
use ReflectionException;
1921

2022
class Application extends Router
2123
{
@@ -24,21 +26,21 @@ class Application extends Router
2426
*
2527
* @var Capsule
2628
*/
27-
private $capsule;
29+
private Capsule $capsule;
2830

2931
/**
3032
* The booting flag
3133
*
3234
* @var bool
3335
*/
34-
private $booted = false;
36+
private bool $booted = false;
3537

3638
/**
3739
* The Application instance
3840
*
39-
* @var Application
41+
* @var ?Application
4042
*/
41-
private static $instance;
43+
private static ?Application $instance = null;
4244

4345
/**
4446
* The HTTP Request
@@ -62,7 +64,7 @@ class Application extends Router
6264
private Loader $config;
6365

6466
/**
65-
* This define if the X-powered-By header must be put in response
67+
* This defines if the X-powered-By header must be put in response
6668
*
6769
* @var bool
6870
*/
@@ -74,6 +76,7 @@ class Application extends Router
7476
* @param Request $request
7577
* @param Response $response
7678
* @return void
79+
* @throws BadRequestException
7780
*/
7881
public function __construct(Request $request, Response $response)
7982
{
@@ -87,6 +90,7 @@ public function __construct(Request $request, Response $response)
8790
$this->capsule->instance('app', $this);
8891

8992
$this->request->capture();
93+
9094
parent::__construct($request->method(), $request->get('_method'));
9195
}
9296

@@ -114,7 +118,7 @@ public function bind(Loader $config): void
114118
$this->setBaseRoute($config['app']['root']);
115119
}
116120

117-
// We active the auto csrf switcher
121+
// We activate the auto csrf switcher
118122
$this->setAutoCsrf($config['app']['auto_csrf'] ?? false);
119123

120124
$this->capsule->instance('config', $config);
@@ -144,6 +148,7 @@ private function boot(): void
144148
* @param Request $request
145149
* @param Response $response
146150
* @return Application
151+
* @throws BadRequestException
147152
*/
148153
public static function make(Request $request, Response $response): Application
149154
{
@@ -155,7 +160,7 @@ public static function make(Request $request, Response $response): Application
155160
}
156161

157162
/**
158-
* Check if is running on php cli
163+
* Check if it is running on php cli
159164
*
160165
* @return bool
161166
*/
@@ -168,7 +173,7 @@ public function isRunningOnCli(): bool
168173
* Launcher of the application
169174
*
170175
* @return ?bool
171-
* @throws RouterException
176+
* @throws RouterException|ReflectionException
172177
*/
173178
public function send(): ?bool
174179
{
@@ -244,7 +249,7 @@ public function send(): ?bool
244249
*
245250
* @param mixed $response
246251
* @param int $code
247-
* @return null
252+
* @return void
248253
*/
249254
private function sendResponse(mixed $response, int $code = 200): void
250255
{
@@ -267,7 +272,7 @@ public function disablePoweredByMention(): void
267272
}
268273

269274
/**
270-
* Make the REST API base on route and ressource controller.
275+
* Make the REST API base on route and resource controller.
271276
*
272277
* @param string $url
273278
* @param string|array $controller_name
@@ -305,7 +310,7 @@ public function rest(string $url, string|array $controller_name, array $where =
305310
}
306311
}
307312

308-
if (is_null($controller) || !is_string($controller)) {
313+
if (!is_string($controller)) {
309314
throw new ApplicationException(
310315
"[REST] No defined controller!",
311316
E_ERROR
@@ -346,7 +351,7 @@ public function abort(int $code = 500, string $message = '', array $headers = []
346351
}
347352

348353
/**
349-
* Build dependance
354+
* Build dependence
350355
*
351356
* @param ?string $name
352357
* @param ?callable $callable
@@ -378,7 +383,7 @@ public function container(?string $name = null, ?callable $callable = null): mix
378383
* This point method on the container system
379384
*
380385
* @param array $params
381-
* @return Capsule
386+
* @return mixed
382387
* @throws ApplicationException
383388
*/
384389
public function __invoke(...$params): mixed

src/Application/Exception/BaseErrorHandler.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Bow\Application\Exception;
66

7+
use JetBrains\PhpStorm\NoReturn;
78
use PDOException;
89
use Bow\View\View;
910
use Bow\Http\Exception\HttpException;
@@ -20,19 +21,19 @@ class BaseErrorHandler
2021
* @param array $data
2122
* @return string
2223
*/
23-
protected function render($view, $data = []): string
24+
protected function render(string $view, array $data = []): string
2425
{
2526
return View::parse($view, $data)->getContent();
2627
}
2728

2829
/**
2930
* Send the json as response
3031
*
31-
* @param string $data
32-
* @param mixed $code
33-
* @return mixed
32+
* @param $exception
33+
* @param mixed|null $code
34+
* @return void
3435
*/
35-
protected function json($exception, $code = null)
36+
#[NoReturn] protected function json($exception, mixed $code = null): void
3637
{
3738
if ($exception instanceof TokenInvalidException) {
3839
$code = 'TOKEN_INVALID';
@@ -50,8 +51,12 @@ protected function json($exception, $code = null)
5051
}
5152
}
5253

53-
if (app_env("APP_ENV") == "production" && $exception instanceof PDOException) {
54-
$message = 'An SQL error occurs. For security, we did not display the message.';
54+
if ($exception instanceof PDOException) {
55+
if (app_env("APP_ENV") == "production") {
56+
$message = 'An SQL error occurs. For security, we did not display the message.';
57+
} else {
58+
$message = $exception->getMessage();
59+
}
5560
} else {
5661
$message = $exception->getMessage();
5762
}
@@ -78,6 +83,6 @@ protected function json($exception, $code = null)
7883

7984
response()->status($status);
8085

81-
return die(json_encode($response));
86+
die(json_encode($response));
8287
}
8388
}

src/Auth/Auth.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Auth
1515
/**
1616
* The Auth instance
1717
*
18-
* @var GuardContract
18+
* @var ?GuardContract
1919
*/
2020
private static ?GuardContract $instance = null;
2121

@@ -29,17 +29,18 @@ class Auth
2929
/**
3030
* The current guard
3131
*
32-
* @var string
32+
* @var ?string
3333
*/
3434
private static ?string $guard = null;
3535

3636
/**
3737
* Configure Auth system
3838
*
3939
* @param array $config
40-
* @return GuardContract
40+
* @return ?GuardContract
41+
* @throws AuthenticationException
4142
*/
42-
public static function configure(array $config)
43+
public static function configure(array $config): ?GuardContract
4344
{
4445
if (!is_null(static::$instance)) {
4546
return static::$instance;
@@ -61,7 +62,7 @@ public static function getInstance(): ?GuardContract
6162
}
6263

6364
/**
64-
* Check if user is authenticate
65+
* Check if user is authenticated
6566
*
6667
* @param null|string $guard
6768
* @return GuardContract
@@ -102,6 +103,7 @@ public static function guard(?string $guard = null): GuardContract
102103
* @param string $method
103104
* @param array $params
104105
* @return ?GuardContract
106+
* @throws ErrorException
105107
*/
106108
public static function __callStatic(string $method, array $params)
107109
{

src/Auth/Authentication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class Authentication extends Model
1313
*
1414
* @return mixed
1515
*/
16-
public function getAuthenticateUserId()
16+
public function getAuthenticateUserId(): mixed
1717
{
1818
return $this->attributes[$this->primary_key];
1919
}
2020

2121
/**
22-
* Define the additionals values
22+
* Define the additional values
2323
*
2424
* @return array
2525
*/

src/Auth/Guards/GuardContract.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
use Bow\Auth\Auth;
88
use Bow\Auth\Authentication;
9+
use Bow\Auth\Exception\AuthenticationException;
910

1011
/**
11-
* @method ?\Policier\Token getToken()
12+
* @method ?\Bow\Policier\Token getToken()
1213
*/
1314
abstract class GuardContract
1415
{
@@ -27,7 +28,7 @@ abstract class GuardContract
2728
abstract public function id(): mixed;
2829

2930
/**
30-
* Check if user is authenticate
31+
* Check if user is authenticated
3132
*
3233
* @return bool
3334
*/
@@ -58,12 +59,12 @@ abstract public function login(Authentication $user): bool;
5859
/**
5960
* Get authenticated user
6061
*
61-
* @return Authentication
62+
* @return ?Authentication
6263
*/
6364
abstract public function user(): ?Authentication;
6465

6566
/**
66-
* Check if user is authenticate
67+
* Check if user is authenticated
6768
*
6869
* @param array $credentials
6970
* @return bool
@@ -81,12 +82,13 @@ public function getName(): string
8182
}
8283

8384
/**
84-
* Load the a guard
85+
* Load the guard
8586
*
86-
* @param string $guard
87+
* @param string|null $guard
8788
* @return GuardContract
89+
* @throws AuthenticationException
8890
*/
89-
public function guard($guard = null): GuardContract
91+
public function guard(string $guard = null): GuardContract
9092
{
9193
if ($guard) {
9294
$this->guard = $guard;

0 commit comments

Comments
 (0)