From 7336bd4fd7d2069127bf6a35e07c85394d406501 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 25 Jan 2024 02:42:24 -0400 Subject: [PATCH 1/7] Apply code formatting in root files --- composer.json | 4 ++-- flight.sublime-project | 12 +++++++++--- phpcs.xml | 18 +++++++++-------- phpunit.xml | 44 ++++++++++++++++++++++-------------------- 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 60b0ed7..e6731e4 100644 --- a/composer.json +++ b/composer.json @@ -49,8 +49,8 @@ "test": "phpunit", "test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage --coverage-clover=clover.xml && vendor/bin/coverage-check clover.xml 100", "lint": "phpstan --no-progress -cphpstan.neon", - "beautify": "phpcbf --standard=phpcs.xml", - "phpcs": "phpcs --standard=phpcs.xml" + "beautify": "phpcbf --standard=phpcs.xml", + "phpcs": "phpcs --standard=phpcs.xml" }, "suggest": { "latte/latte": "Latte template engine", diff --git a/flight.sublime-project b/flight.sublime-project index 9d1a3da..5f2628e 100644 --- a/flight.sublime-project +++ b/flight.sublime-project @@ -19,9 +19,15 @@ "source.json.sublime": "LSP-json", }, "LSP-html": { - "enabled": false + "enabled": false, }, "LSP-tailwindcss": { + "enabled": false, + }, + "ltex-ls": { + "enabled": false, + }, + "marksman": { "enabled": false }, }, @@ -30,12 +36,12 @@ { "name": "Linter - HARD", "quiet": true, - "shell_cmd": "composer lint -- --no-ansi -lmax" + "shell_cmd": "composer lint -- --no-ansi -lmax", }, { "name": "Linter - Default", "quiet": true, - "shell_cmd": "composer lint -- --no-ansi" + "shell_cmd": "composer lint -- --no-ansi", } ], } diff --git a/phpcs.xml b/phpcs.xml index 771f60e..1d75995 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,10 +1,12 @@ - Created with the PHP Coding Standard Generator. http://edorian.github.io/php-coding-standard-generator/ - - - - - flight/ - tests/ - \ No newline at end of file + + Created with the PHP Coding Standard Generator. + http://edorian.github.io/php-coding-standard-generator/ + + + + + flight/ + tests/ + diff --git a/phpunit.xml b/phpunit.xml index 1577ac2..2fedaf9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,23 +1,25 @@ - - - - flight/ - - - - - tests/ - - - + + + + flight/ + + + + + tests/ + + + From eadca18a5ae52d17a769292465ac538ce2668717 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 25 Jan 2024 03:35:06 -0400 Subject: [PATCH 2/7] Added phpcs script to SublimeText build systems --- flight.sublime-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight.sublime-project b/flight.sublime-project index 5f2628e..63e8be2 100644 --- a/flight.sublime-project +++ b/flight.sublime-project @@ -41,7 +41,7 @@ { "name": "Linter - Default", "quiet": true, - "shell_cmd": "composer lint -- --no-ansi", + "shell_cmd": "composer lint -- --no-ansi | composer phpcs -- --no-colors", } ], } From bdca41d7e15aba7de0fa6825b1dab06b0cfbdde4 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 25 Jan 2024 03:36:20 -0400 Subject: [PATCH 3/7] Added development classmap autoloader --- composer.json | 8 ++++++++ tests/LoaderTest.php | 7 ++----- tests/MapTest.php | 5 ++--- tests/RegisterTest.php | 5 ++--- tests/classes/TesterClass.php | 3 ++- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index e6731e4..e2b28ef 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,14 @@ "flight/Flight.php" ] }, + "autoload-dev": { + "classmap": [ + "tests/classes/User.php", + "tests/classes/Hello.php", + "tests/classes/Factory.php", + "tests/classes/TesterClass.php" + ] + }, "require-dev": { "ext-pdo_sqlite": "*", "phpunit/phpunit": "^9.5", diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index b4f7d4d..2ed2be9 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -8,12 +8,9 @@ */ use flight\core\Loader; +use PHPUnit\Framework\TestCase; -require_once __DIR__ . '/classes/User.php'; -require_once __DIR__ . '/classes/Factory.php'; -require_once __DIR__ . '/classes/TesterClass.php'; - -class LoaderTest extends PHPUnit\Framework\TestCase +class LoaderTest extends TestCase { private Loader $loader; diff --git a/tests/MapTest.php b/tests/MapTest.php index d147c94..dc75b56 100644 --- a/tests/MapTest.php +++ b/tests/MapTest.php @@ -8,10 +8,9 @@ */ use flight\Engine; +use PHPUnit\Framework\TestCase; -require_once __DIR__ . '/classes/Hello.php'; - -class MapTest extends PHPUnit\Framework\TestCase +class MapTest extends TestCase { private Engine $app; diff --git a/tests/RegisterTest.php b/tests/RegisterTest.php index f13629d..370b1ab 100644 --- a/tests/RegisterTest.php +++ b/tests/RegisterTest.php @@ -8,10 +8,9 @@ */ use flight\Engine; +use PHPUnit\Framework\TestCase; -require_once __DIR__ . '/classes/User.php'; - -class RegisterTest extends PHPUnit\Framework\TestCase +class RegisterTest extends TestCase { private Engine $app; diff --git a/tests/classes/TesterClass.php b/tests/classes/TesterClass.php index f3a6172..567ea37 100644 --- a/tests/classes/TesterClass.php +++ b/tests/classes/TesterClass.php @@ -8,6 +8,7 @@ class TesterClass public $param4; public $param5; public $param6; + public function __construct($param1, $param2, $param3, $param4, $param5, $param6) { $this->param1 = $param1; @@ -17,4 +18,4 @@ class TesterClass $this->param5 = $param5; $this->param6 = $param6; } -}; +} From def0e65965c3c948430365457e0c32303ee068bc Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 25 Jan 2024 03:37:11 -0400 Subject: [PATCH 4/7] Solved Engine::class phpcs problems --- flight/Engine.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/flight/Engine.php b/flight/Engine.php index 2f9aac5..af33c86 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -1,7 +1,5 @@ middleware) > 0) { foreach ($route->middleware as $middleware) { - $middleware_object = (is_callable($middleware) === true ? $middleware : (method_exists($middleware, 'before') === true ? [ $middleware, 'before' ] : false)); + $middleware_object = (is_callable($middleware) === true + ? $middleware + : (method_exists($middleware, 'before') === true + ? [$middleware, 'before'] + : false)); if ($middleware_object === false) { continue; @@ -418,7 +422,15 @@ class Engine // process the middleware in reverse order now foreach (array_reverse($route->middleware) as $middleware) { // must be an object. No functions allowed here - $middleware_object = is_object($middleware) === true && !($middleware instanceof Closure) && method_exists($middleware, 'after') === true ? [ $middleware, 'after' ] : false; + $middleware_object = false; + + if ( + is_object($middleware) === true + && !($middleware instanceof Closure) + && method_exists($middleware, 'after') === true + ) { + $middleware_object = [$middleware, 'after']; + } // has to have the after method, otherwise just skip it if ($middleware_object === false) { @@ -474,7 +486,7 @@ class Engine ->status(500) ->write($msg) ->send(); - // @codeCoverageIgnoreStart + // @codeCoverageIgnoreStart } catch (Throwable $t) { exit($msg); } @@ -608,8 +620,7 @@ class Engine ->status(404) ->write( '

404 Not Found

' . - '

The page you have requested could not be found.

' . - str_repeat(' ', 512) + '

The page you have requested could not be found.

' ) ->send(); } From 44a056ca301b2ad2ed297868e4097e271d6b00da Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 25 Jan 2024 03:39:56 -0400 Subject: [PATCH 5/7] Fixed phpcs format problems in the rest of Flight modules --- flight/Flight.php | 5 ++--- flight/autoload.php | 4 ++-- flight/core/Dispatcher.php | 4 ++-- flight/core/Loader.php | 4 ++-- flight/database/PdoWrapper.php | 9 +++++---- flight/net/Request.php | 4 ++-- flight/net/Response.php | 9 ++++++--- flight/net/Route.php | 10 ++++------ flight/net/Router.php | 7 ++++--- flight/template/View.php | 4 ++-- flight/util/Collection.php | 4 ++-- 11 files changed, 33 insertions(+), 31 deletions(-) diff --git a/flight/Flight.php b/flight/Flight.php index f34c975..34b7bd5 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -1,7 +1,5 @@ $group_middlewares The middlewares to be applied to the group Ex: [ $middleware1, $middleware2 ] + * @param array $group_middlewares The middlewares to be + * applied to the group Ex: [ $middleware1, $middleware2 ] */ public function group(string $group_prefix, callable $callback, array $group_middlewares = []): void { diff --git a/flight/template/View.php b/flight/template/View.php index 7d08623..d0c5f3b 100644 --- a/flight/template/View.php +++ b/flight/template/View.php @@ -1,7 +1,5 @@ Date: Thu, 25 Jan 2024 03:40:46 -0400 Subject: [PATCH 6/7] Fixed phpcs format problems in tests --- tests/EngineTest.php | 22 ++++++++++++++-------- tests/RouterTest.php | 19 +++++++++++++++++-- tests/ViewTest.php | 27 +++++++++++++-------------- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/tests/EngineTest.php b/tests/EngineTest.php index 012c472..833cbbe 100644 --- a/tests/EngineTest.php +++ b/tests/EngineTest.php @@ -1,8 +1,5 @@ expectOutputString('

404 Not Found

The page you have requested could not be found.

'); + $this->expectOutputString('

404 Not Found

The page you have requested could not be found.

'); $engine->start(); } @@ -206,16 +207,21 @@ class EngineTest extends PHPUnit\Framework\TestCase }; // doing this so we can overwrite some parts of the response $engine->getLoader()->register('response', function () { - return new class extends \flight\net\Response { + return new class extends Response { public function __construct() { } - public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): Response - { + + public function setRealHeader( + string $header_string, + bool $replace = true, + int $response_code = 0 + ): self { return $this; } }; }); + $this->expectOutputString('skip---exit'); $engine->halt(500, 'skip---exit'); $this->assertEquals(500, $engine->response()->status()); diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 8697a91..12f1543 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -264,7 +264,21 @@ class RouterTest extends PHPUnit\Framework\TestCase public function testRouteWithLongQueryParamWithMultilineEncoded() { $this->router->map('GET /api/intune/hey', [$this, 'ok']); - $this->request->url = '/api/intune/hey?error=access_denied&error_description=AADSTS65004%3a+User+declined+to+consent+to+access+the+app.%0d%0aTrace+ID%3a+747c0cc1-ccbd-4e53-8e2f-48812eb24100%0d%0aCorrelation+ID%3a+362e3cb3-20ef-400b-904e-9983bd989184%0d%0aTimestamp%3a+2022-09-08+09%3a58%3a12Z&error_uri=https%3a%2f%2flogin.microsoftonline.com%2ferror%3fcode%3d65004&admin_consent=True&state=x2EUE0fcSj#'; + + $query_params = [ + 'error=access_denied', + 'error_description=AADSTS65004%3a+User+declined+to+consent+to+access+the' + . '+app.%0d%0aTrace+ID%3a+747c0cc1-ccbd-4e53-8e2f-48812eb24100%0d%0a' + . 'Correlation+ID%3a+362e3cb3-20ef-400b-904e-9983bd989184%0d%0a' + . 'Timestamp%3a+2022-09-08+09%3a58%3a12Z', + 'error_uri=https%3a%2f%2flogin.microsoftonline.com%2ferror%3fcode%3d65004', + 'admin_consent=True', + 'state=x2EUE0fcSj#' + ]; + + $query_params = join('&', $query_params); + + $this->request->url = "/api/intune/hey?$query_params"; $this->check('OK'); } @@ -406,7 +420,8 @@ class RouterTest extends PHPUnit\Framework\TestCase public function testResetRoutes() { - $router = new class extends Router { + $router = new class extends Router + { public function getIndex() { return $this->index; diff --git a/tests/ViewTest.php b/tests/ViewTest.php index 4299822..7bd1dd4 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -1,23 +1,15 @@ - * @license MIT, http://flightphp.com/license - */ -class ViewTest extends PHPUnit\Framework\TestCase +class ViewTest extends TestCase { - /** - * @var \flight\template\View - */ - private $view; + private View $view; protected function setUp(): void { - $this->view = new \flight\template\View(); + $this->view = new View(); $this->view->path = __DIR__ . '/views'; } @@ -70,7 +62,13 @@ class ViewTest extends PHPUnit\Framework\TestCase public function testRenderBadFilePath() { $this->expectException(Exception::class); - $this->expectExceptionMessage('Template file not found: ' . __DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'badfile.php'); + $exception_message = sprintf( + 'Template file not found: %s%sviews%sbadfile.php', + __DIR__, + DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR + ); + $this->expectExceptionMessage($exception_message); $this->view->render('badfile'); } @@ -128,7 +126,8 @@ class ViewTest extends PHPUnit\Framework\TestCase public function testNormalizePath(): void { - $viewMock = new class extends View { + $viewMock = new class extends View + { public static function normalizePath(string $path, string $separator = DIRECTORY_SEPARATOR): string { return parent::normalizePath($path, $separator); From 51c5d7bca22aafe895df7f915b1377c9fc291418 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 25 Jan 2024 03:47:26 -0400 Subject: [PATCH 7/7] Added SublimeText format build system --- flight.sublime-project | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flight.sublime-project b/flight.sublime-project index 63e8be2..e507ffa 100644 --- a/flight.sublime-project +++ b/flight.sublime-project @@ -42,6 +42,11 @@ "name": "Linter - Default", "quiet": true, "shell_cmd": "composer lint -- --no-ansi | composer phpcs -- --no-colors", + }, + { + "name": "Format", + "quiet": true, + "shell_cmd": "composer beautify -- --no-colors" } ], }