From f7610f883c12800949529e046056bb5a290f41db Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 02:49:51 -0400 Subject: [PATCH 01/30] add trim_trailing_whitespace and insert_final_newline to .editorconfig --- .editorconfig | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 19ae126f..e8d15f4f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,9 +5,8 @@ indent_style = space indent_size = 4 end_of_line = lf charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true [*.md] indent_size = 2 - -[tests/views/*.php] -insert_final_newline = false From b312f611fc3aaa3a55fed38213e81bdecaf5e667 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 02:50:38 -0400 Subject: [PATCH 02/30] set indent_size 4 in phpunit-watcher.yml --- phpunit-watcher.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/phpunit-watcher.yml b/phpunit-watcher.yml index d31e9129..6b158dfc 100644 --- a/phpunit-watcher.yml +++ b/phpunit-watcher.yml @@ -1,13 +1,13 @@ hideManual: true watch: - directories: - - tests - - flight - fileMask: '*.php' + directories: + - tests + - flight + fileMask: '*.php' notifications: - passingTests: false - failingTests: false + passingTests: false + failingTests: false phpunit: - binaryPath: ./vendor/bin/phpunit - arguments: '--stop-on-failure' - timeout: 180 \ No newline at end of file + binaryPath: ./vendor/bin/phpunit + arguments: '--stop-on-failure' + timeout: 180 From f9b7c6b5979399147fd61cf50639e0d9663605b1 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 02:59:09 -0400 Subject: [PATCH 03/30] delete index.php --- .gitattributes | 1 - index.php | 12 ------------ phpcs.xml.dist | 1 - 3 files changed, 14 deletions(-) delete mode 100644 index.php diff --git a/.gitattributes b/.gitattributes index c01e0897..cd88ff95 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,7 +5,6 @@ /.gitattributes export-ignore /.gitignore export-ignore /CONTRIBUTING.md export-ignore -/index.php export-ignore /phpcs.xml.dist export-ignore /phpstan-baseline.neon export-ignore /phpstan.dist.neon export-ignore diff --git a/index.php b/index.php deleted file mode 100644 index 0db24be2..00000000 --- a/index.php +++ /dev/null @@ -1,12 +0,0 @@ - - index.php flight tests From cc5d162bb754e87816c31a7b3b93dc156eb593c3 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:04:16 -0400 Subject: [PATCH 04/30] ignore README.md from composer install --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index cd88ff95..edcce414 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,3 +10,4 @@ /phpstan.dist.neon export-ignore /phpunit-watcher.yml export-ignore /phpunit.xml.dist export-ignore +/README.md export-ignore From 6ece1edb3810281e489e8edad3e5b93c9a192ccf Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:04:55 -0400 Subject: [PATCH 05/30] allow !is_array() in contributions (cleaner and readable code) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b1af6db..d6a5accf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ Flight aims to be simple and fast. Anything that compromises either of those two * **Coding Standards** - We use PSR1 coding standards enforced by PHPCS. Some standards that either need additional configuration or need to be manually done are: * PHPStan is at level 6. - * `===` instead of truthy or falsey statements like `==` or `!is_array()`. + * `===` instead of truthy or falsey statements like `==`. * **PHP 7.4 Focused** - We do not make PHP 8+ focused enhancements on the framework as the focus is maintaining PHP 7.4. From f1a8c8104b235e1764db4da0bfac3126a48b094a Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:05:15 -0400 Subject: [PATCH 06/30] reset default phpcs psr12 rules --- phpcs.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 327abfea..ba1c395e 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -18,7 +18,6 @@ - flight From 6cd027e620a6db4433fbb292557a875187e8e32d Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:08:16 -0400 Subject: [PATCH 07/30] clean .gitignore --- .gitignore | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index cb308cff..a15f603d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,3 @@ -.idea/ -.vscode/ -vendor/ -composer.phar -composer.lock -.phpunit.result.cache -coverage/ *.sublime* -clover.xml -phpcs.xml -phpstan.neon -phpunit.xml -.runway-config.json -.runway-creds.json -.DS_Store +/vendor/ +composer.lock From 7f20704cd228a0e04fa4c135c83ca607436b05e7 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:09:25 -0400 Subject: [PATCH 08/30] update broken packagist homepage --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 33d2951b..8f521d6f 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "flightphp/core", "description": "Flight is a fast, simple, extensible framework for PHP. Flight enables you to quickly and easily build RESTful web applications. This is the maintained fork of mikecao/flight", - "homepage": "http://flightphp.com", + "homepage": "https://docs.flightphp.com/", "license": "MIT", "authors": [ { From eac46dbf395281183a45f80197aaf8c476ad026c Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:10:58 -0400 Subject: [PATCH 09/30] update contributors homepages --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8f521d6f..e99527b1 100644 --- a/composer.json +++ b/composer.json @@ -7,13 +7,13 @@ { "name": "Mike Cao", "email": "mike@mikecao.com", - "homepage": "http://www.mikecao.com/", + "homepage": "https://mikecao.com/", "role": "Original Developer" }, { "name": "Franyer Sánchez", "email": "franyeradriansanchez@gmail.com", - "homepage": "https://faslatam.42web.io", + "homepage": "https://faslatam.42web.io/", "role": "Maintainer" }, { From 42e8166984472b5cb69f858cfc904e641f88db38 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:15:25 -0400 Subject: [PATCH 10/30] ignore .phpunit.result.cache, phpcs.xml, phpstan.neon and phpunit.xml --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index a15f603d..2cae83d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *.sublime* +.phpunit.result.cache /vendor/ composer.lock +phpcs.xml +phpstan.neon +phpunit.xml From c8e7855fa82a4f6eeaf06ccce51fb50c73dfff74 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:16:48 -0400 Subject: [PATCH 11/30] rename flight -> src --- {flight => src}/Engine.php | 0 {flight => src}/Flight.php | 0 {flight => src}/autoload.php | 0 {flight => src}/commands/AiGenerateInstructionsCommand.php | 0 {flight => src}/commands/AiInitCommand.php | 0 {flight => src}/commands/ControllerCommand.php | 0 {flight => src}/commands/RouteCommand.php | 0 {flight => src}/core/Dispatcher.php | 0 {flight => src}/core/EventDispatcher.php | 0 {flight => src}/core/Loader.php | 0 {flight => src}/database/PdoWrapper.php | 0 {flight => src}/database/SimplePdo.php | 0 {flight => src}/net/Request.php | 0 {flight => src}/net/Response.php | 0 {flight => src}/net/Route.php | 0 {flight => src}/net/Router.php | 0 {flight => src}/net/UploadedFile.php | 0 {flight => src}/template/View.php | 0 {flight => src}/util/Collection.php | 0 {flight => src}/util/Json.php | 0 {flight => src}/util/ReturnTypeWillChange.php | 0 21 files changed, 0 insertions(+), 0 deletions(-) rename {flight => src}/Engine.php (100%) rename {flight => src}/Flight.php (100%) rename {flight => src}/autoload.php (100%) rename {flight => src}/commands/AiGenerateInstructionsCommand.php (100%) rename {flight => src}/commands/AiInitCommand.php (100%) rename {flight => src}/commands/ControllerCommand.php (100%) rename {flight => src}/commands/RouteCommand.php (100%) rename {flight => src}/core/Dispatcher.php (100%) rename {flight => src}/core/EventDispatcher.php (100%) rename {flight => src}/core/Loader.php (100%) rename {flight => src}/database/PdoWrapper.php (100%) rename {flight => src}/database/SimplePdo.php (100%) rename {flight => src}/net/Request.php (100%) rename {flight => src}/net/Response.php (100%) rename {flight => src}/net/Route.php (100%) rename {flight => src}/net/Router.php (100%) rename {flight => src}/net/UploadedFile.php (100%) rename {flight => src}/template/View.php (100%) rename {flight => src}/util/Collection.php (100%) rename {flight => src}/util/Json.php (100%) rename {flight => src}/util/ReturnTypeWillChange.php (100%) diff --git a/flight/Engine.php b/src/Engine.php similarity index 100% rename from flight/Engine.php rename to src/Engine.php diff --git a/flight/Flight.php b/src/Flight.php similarity index 100% rename from flight/Flight.php rename to src/Flight.php diff --git a/flight/autoload.php b/src/autoload.php similarity index 100% rename from flight/autoload.php rename to src/autoload.php diff --git a/flight/commands/AiGenerateInstructionsCommand.php b/src/commands/AiGenerateInstructionsCommand.php similarity index 100% rename from flight/commands/AiGenerateInstructionsCommand.php rename to src/commands/AiGenerateInstructionsCommand.php diff --git a/flight/commands/AiInitCommand.php b/src/commands/AiInitCommand.php similarity index 100% rename from flight/commands/AiInitCommand.php rename to src/commands/AiInitCommand.php diff --git a/flight/commands/ControllerCommand.php b/src/commands/ControllerCommand.php similarity index 100% rename from flight/commands/ControllerCommand.php rename to src/commands/ControllerCommand.php diff --git a/flight/commands/RouteCommand.php b/src/commands/RouteCommand.php similarity index 100% rename from flight/commands/RouteCommand.php rename to src/commands/RouteCommand.php diff --git a/flight/core/Dispatcher.php b/src/core/Dispatcher.php similarity index 100% rename from flight/core/Dispatcher.php rename to src/core/Dispatcher.php diff --git a/flight/core/EventDispatcher.php b/src/core/EventDispatcher.php similarity index 100% rename from flight/core/EventDispatcher.php rename to src/core/EventDispatcher.php diff --git a/flight/core/Loader.php b/src/core/Loader.php similarity index 100% rename from flight/core/Loader.php rename to src/core/Loader.php diff --git a/flight/database/PdoWrapper.php b/src/database/PdoWrapper.php similarity index 100% rename from flight/database/PdoWrapper.php rename to src/database/PdoWrapper.php diff --git a/flight/database/SimplePdo.php b/src/database/SimplePdo.php similarity index 100% rename from flight/database/SimplePdo.php rename to src/database/SimplePdo.php diff --git a/flight/net/Request.php b/src/net/Request.php similarity index 100% rename from flight/net/Request.php rename to src/net/Request.php diff --git a/flight/net/Response.php b/src/net/Response.php similarity index 100% rename from flight/net/Response.php rename to src/net/Response.php diff --git a/flight/net/Route.php b/src/net/Route.php similarity index 100% rename from flight/net/Route.php rename to src/net/Route.php diff --git a/flight/net/Router.php b/src/net/Router.php similarity index 100% rename from flight/net/Router.php rename to src/net/Router.php diff --git a/flight/net/UploadedFile.php b/src/net/UploadedFile.php similarity index 100% rename from flight/net/UploadedFile.php rename to src/net/UploadedFile.php diff --git a/flight/template/View.php b/src/template/View.php similarity index 100% rename from flight/template/View.php rename to src/template/View.php diff --git a/flight/util/Collection.php b/src/util/Collection.php similarity index 100% rename from flight/util/Collection.php rename to src/util/Collection.php diff --git a/flight/util/Json.php b/src/util/Json.php similarity index 100% rename from flight/util/Json.php rename to src/util/Json.php diff --git a/flight/util/ReturnTypeWillChange.php b/src/util/ReturnTypeWillChange.php similarity index 100% rename from flight/util/ReturnTypeWillChange.php rename to src/util/ReturnTypeWillChange.php From 4f6080f6f4788335c6468c2a866317a4e1e062d1 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:16:53 -0400 Subject: [PATCH 12/30] add psr-4 --- composer.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e99527b1..edcb7038 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,11 @@ }, "autoload": { "files": [ - "flight/autoload.php" - ] + "src/autoload.php" + ], + "psr-4": { + "flight\\": "src" + } }, "autoload-dev": { "classmap": [ From 450eea84eab521080e832a55e7bf9c36ec50c356 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:36:25 -0400 Subject: [PATCH 13/30] simplify autoload-dev to a single psr-4 autoload --- composer.json | 12 ++---------- phpunit.xml.dist | 2 +- .../FlightRouteCompactSyntaxTest.php | 5 +---- .../PostsController.php | 2 +- .../TodosController.php | 2 +- .../UsersController.php | 2 +- .../ExampleClass.php | 2 ++ .../FlightTest.php | 3 +-- tests/server/AuthCheck.php | 2 +- tests/server/LayoutMiddleware.php | 2 +- tests/server/OverwriteBodyMiddleware.php | 2 +- tests/server/Pascal_Snake_Case.php | 2 +- tests/server/index.php | 8 ++++---- tests/{server-v2 => server_v2}/index.php | 4 ++-- tests/{server-v2 => server_v2}/template.phtml | 0 15 files changed, 20 insertions(+), 30 deletions(-) rename tests/{groupcompactsyntax => group_compact_syntax}/FlightRouteCompactSyntaxTest.php (96%) rename tests/{groupcompactsyntax => group_compact_syntax}/PostsController.php (93%) rename tests/{groupcompactsyntax => group_compact_syntax}/TodosController.php (83%) rename tests/{groupcompactsyntax => group_compact_syntax}/UsersController.php (84%) rename tests/{named-arguments => named_arguments}/ExampleClass.php (78%) rename tests/{named-arguments => named_arguments}/FlightTest.php (98%) rename tests/{server-v2 => server_v2}/index.php (99%) rename tests/{server-v2 => server_v2}/template.phtml (100%) diff --git a/composer.json b/composer.json index edcb7038..5e72dd7d 100644 --- a/composer.json +++ b/composer.json @@ -35,16 +35,8 @@ } }, "autoload-dev": { - "classmap": [ - "tests/classes/" - ], "psr-4": { - "Tests\\PHP8\\": [ - "tests/named-arguments" - ], - "Tests\\Server\\": "tests/server", - "Tests\\ServerV2\\": "tests/server-v2", - "tests\\groupcompactsyntax\\": "tests/groupcompactsyntax" + "tests\\": "tests" } }, "require-dev": { @@ -84,7 +76,7 @@ ], "test-server-v2": [ "echo \"Running Test Server\"", - "@php -S localhost:8000 -t tests/server-v2" + "@php -S localhost:8000 -t tests/server_v2" ], "test-coverage:win": [ "del clover.xml", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b890bb7f..b2055979 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -22,7 +22,7 @@ tests/ - tests/named-arguments/ + tests/named_arguments/ diff --git a/tests/groupcompactsyntax/FlightRouteCompactSyntaxTest.php b/tests/group_compact_syntax/FlightRouteCompactSyntaxTest.php similarity index 96% rename from tests/groupcompactsyntax/FlightRouteCompactSyntaxTest.php rename to tests/group_compact_syntax/FlightRouteCompactSyntaxTest.php index 84d168f5..2c8d3a16 100644 --- a/tests/groupcompactsyntax/FlightRouteCompactSyntaxTest.php +++ b/tests/group_compact_syntax/FlightRouteCompactSyntaxTest.php @@ -2,13 +2,10 @@ declare(strict_types=1); -namespace tests\groupcompactsyntax; +namespace tests\group_compact_syntax; use Flight; use PHPUnit\Framework\TestCase; -use tests\groupcompactsyntax\PostsController; -use tests\groupcompactsyntax\TodosController; -use tests\groupcompactsyntax\UsersController; final class FlightRouteCompactSyntaxTest extends TestCase { diff --git a/tests/groupcompactsyntax/PostsController.php b/tests/group_compact_syntax/PostsController.php similarity index 93% rename from tests/groupcompactsyntax/PostsController.php rename to tests/group_compact_syntax/PostsController.php index f95f60d4..5e693fbc 100644 --- a/tests/groupcompactsyntax/PostsController.php +++ b/tests/group_compact_syntax/PostsController.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\groupcompactsyntax; +namespace tests\group_compact_syntax; final class PostsController { diff --git a/tests/groupcompactsyntax/TodosController.php b/tests/group_compact_syntax/TodosController.php similarity index 83% rename from tests/groupcompactsyntax/TodosController.php rename to tests/group_compact_syntax/TodosController.php index 91c30cf7..744f6b75 100644 --- a/tests/groupcompactsyntax/TodosController.php +++ b/tests/group_compact_syntax/TodosController.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\groupcompactsyntax; +namespace tests\group_compact_syntax; final class TodosController { diff --git a/tests/groupcompactsyntax/UsersController.php b/tests/group_compact_syntax/UsersController.php similarity index 84% rename from tests/groupcompactsyntax/UsersController.php rename to tests/group_compact_syntax/UsersController.php index d6372b56..7323771b 100644 --- a/tests/groupcompactsyntax/UsersController.php +++ b/tests/group_compact_syntax/UsersController.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace tests\groupcompactsyntax; +namespace tests\group_compact_syntax; final class UsersController { diff --git a/tests/named-arguments/ExampleClass.php b/tests/named_arguments/ExampleClass.php similarity index 78% rename from tests/named-arguments/ExampleClass.php rename to tests/named_arguments/ExampleClass.php index 508068c1..95550476 100644 --- a/tests/named-arguments/ExampleClass.php +++ b/tests/named_arguments/ExampleClass.php @@ -2,6 +2,8 @@ declare(strict_types=1); +namespace tests\named_arguments; + // phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace class ExampleClass { diff --git a/tests/named-arguments/FlightTest.php b/tests/named_arguments/FlightTest.php similarity index 98% rename from tests/named-arguments/FlightTest.php rename to tests/named_arguments/FlightTest.php index 6593450d..9053b02f 100644 --- a/tests/named-arguments/FlightTest.php +++ b/tests/named_arguments/FlightTest.php @@ -2,10 +2,9 @@ declare(strict_types=1); -namespace Tests\PHP8; +namespace tests\named_arguments; use DateTimeImmutable; -use ExampleClass; use Flight; use flight\Container; use flight\Engine; diff --git a/tests/server/AuthCheck.php b/tests/server/AuthCheck.php index 79e8f677..c042c1b3 100644 --- a/tests/server/AuthCheck.php +++ b/tests/server/AuthCheck.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Server; +namespace tests\server; class AuthCheck { diff --git a/tests/server/LayoutMiddleware.php b/tests/server/LayoutMiddleware.php index 150985bd..01058c0b 100644 --- a/tests/server/LayoutMiddleware.php +++ b/tests/server/LayoutMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Server; +namespace tests\server; use Flight; diff --git a/tests/server/OverwriteBodyMiddleware.php b/tests/server/OverwriteBodyMiddleware.php index 98e84685..6a3dfa8a 100644 --- a/tests/server/OverwriteBodyMiddleware.php +++ b/tests/server/OverwriteBodyMiddleware.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Server; +namespace tests\server; use Flight; diff --git a/tests/server/Pascal_Snake_Case.php b/tests/server/Pascal_Snake_Case.php index d80ed416..df9a66ff 100644 --- a/tests/server/Pascal_Snake_Case.php +++ b/tests/server/Pascal_Snake_Case.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Server; +namespace tests\server; class Pascal_Snake_Case // phpcs:ignore { diff --git a/tests/server/index.php b/tests/server/index.php index 6bb9dcac..f4193e86 100644 --- a/tests/server/index.php +++ b/tests/server/index.php @@ -7,10 +7,10 @@ use flight\database\PdoWrapper; use tests\classes\Container; use tests\classes\ContainerDefault; -use Tests\Server\AuthCheck; -use Tests\Server\LayoutMiddleware; -use Tests\Server\OverwriteBodyMiddleware; -use Tests\Server\Pascal_Snake_Case; +use tests\server\AuthCheck; +use tests\server\LayoutMiddleware; +use tests\server\OverwriteBodyMiddleware; +use tests\server\Pascal_Snake_Case; /* * This is the test file where we can open up a quick test server and make diff --git a/tests/server-v2/index.php b/tests/server_v2/index.php similarity index 99% rename from tests/server-v2/index.php rename to tests/server_v2/index.php index 4f45d995..1aadcc1a 100644 --- a/tests/server-v2/index.php +++ b/tests/server_v2/index.php @@ -9,7 +9,7 @@ * @author Kristaps Muižnieks https://github.com/krmu */ -namespace Tests\ServerV2 { +namespace tests\server_v2 { class AuthCheck { public function before(): void @@ -23,7 +23,7 @@ public function before(): void namespace { - use Tests\ServerV2\AuthCheck; + use tests\server_v2\AuthCheck; require_once __DIR__ . '/../phpunit_autoload.php'; diff --git a/tests/server-v2/template.phtml b/tests/server_v2/template.phtml similarity index 100% rename from tests/server-v2/template.phtml rename to tests/server_v2/template.phtml From a19a627dae58941822b9658aba1b861d005a4b02 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:50:53 -0400 Subject: [PATCH 14/30] allow to set phpunit-watcher options per contributor --- .gitignore | 1 + composer.json | 9 ++++----- phpunit-watcher.yml => phpunit-watcher.yml.dist | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename phpunit-watcher.yml => phpunit-watcher.yml.dist (93%) diff --git a/.gitignore b/.gitignore index 2cae83d9..baf87939 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ composer.lock phpcs.xml phpstan.neon +phpunit-watcher.yml phpunit.xml diff --git a/composer.json b/composer.json index 5e72dd7d..4b492797 100644 --- a/composer.json +++ b/composer.json @@ -49,6 +49,7 @@ "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^9.6", "rregeer/phpunit-coverage-check": "^0.3.1", + "spatie/phpunit-watcher": "^1.23", "squizlabs/php_codesniffer": "^4.0" }, "config": { @@ -60,10 +61,7 @@ }, "scripts": { "test": "phpunit", - "test-watcher": [ - "phpunit-watcher || composer global require spatie/phpunit-watcher --dev", - "phpunit-watcher watch" - ], + "test-watcher": "phpunit-watcher watch", "test-coverage": [ "rm -f clover.xml", "@putenv XDEBUG_MODE=coverage", @@ -98,7 +96,8 @@ "post-install-cmd": [ "@php -r \"if (!file_exists('phpcs.xml')) copy('phpcs.xml.dist', 'phpcs.xml');\"", "@php -r \"if (!file_exists('phpstan.neon')) copy('phpstan.dist.neon', 'phpstan.neon');\"", - "@php -r \"if (!file_exists('phpunit.xml')) copy('phpunit.xml.dist', 'phpunit.xml');\"" + "@php -r \"if (!file_exists('phpunit.xml')) copy('phpunit.xml.dist', 'phpunit.xml');\"", + "@php -r \"if (!file_exists('phpunit-watcher.yml')) copy('phpunit-watcher.yml.dist', 'phpunit-watcher.yml');\"" ] }, "suggest": { diff --git a/phpunit-watcher.yml b/phpunit-watcher.yml.dist similarity index 93% rename from phpunit-watcher.yml rename to phpunit-watcher.yml.dist index 6b158dfc..86c39791 100644 --- a/phpunit-watcher.yml +++ b/phpunit-watcher.yml.dist @@ -2,7 +2,7 @@ hideManual: true watch: directories: - tests - - flight + - src fileMask: '*.php' notifications: passingTests: false From 3046bf770e0f3e6fec0bd8538b8bb4264c14ae48 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:58:35 -0400 Subject: [PATCH 15/30] fix coverage generation --- .gitignore | 1 + composer.json | 6 +++--- phpunit.xml.dist | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index baf87939..ac7efc8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.sublime* .phpunit.result.cache +/coverage/ /vendor/ composer.lock phpcs.xml diff --git a/composer.json b/composer.json index 4b492797..e811cfd3 100644 --- a/composer.json +++ b/composer.json @@ -63,10 +63,10 @@ "test": "phpunit", "test-watcher": "phpunit-watcher watch", "test-coverage": [ - "rm -f clover.xml", + "rm -rf coverage", "@putenv XDEBUG_MODE=coverage", - "phpunit --coverage-html=coverage --coverage-clover=clover.xml", - "coverage-check clover.xml 100" + "phpunit --coverage-html coverage --coverage-clover coverage/clover.xml", + "coverage-check coverage/clover.xml 100" ], "test-server": [ "echo \"Running Test Server\"", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b2055979..c1a85f74 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,10 +13,10 @@ colors="true"> - flight/ + src/ - flight/autoload.php + src/autoload.php From b0b3e096ca1ea3189ae3948763bed19b15dfa046 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 03:59:15 -0400 Subject: [PATCH 16/30] remove test-coverage:win --- composer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/composer.json b/composer.json index e811cfd3..dce7b8e9 100644 --- a/composer.json +++ b/composer.json @@ -76,11 +76,6 @@ "echo \"Running Test Server\"", "@php -S localhost:8000 -t tests/server_v2" ], - "test-coverage:win": [ - "del clover.xml", - "phpunit --coverage-html=coverage --coverage-clover=clover.xml", - "coverage-check clover.xml 100" - ], "test-performance": [ "echo \"Running Performance Tests...\"", "@php -S localhost:8077 -t tests/performance/ > /dev/null 2>&1 & echo $! > server.pid", From 17e0224a55776a34b82c3786629967bada49917e Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 04:01:41 -0400 Subject: [PATCH 17/30] simplify lint and beautify scripts --- composer.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index dce7b8e9..426f7f3a 100644 --- a/composer.json +++ b/composer.json @@ -85,9 +85,13 @@ "rm server.pid", "echo \"Performance Tests Completed.\"" ], - "lint": "phpstan --no-progress --memory-limit=256M", - "beautify": "phpcbf", - "phpcs": "phpcs", + "lint": [ + "phpstan --no-progress --memory-limit=256M", + "phpcs" + ], + "format": [ + "phpcbf" + ], "post-install-cmd": [ "@php -r \"if (!file_exists('phpcs.xml')) copy('phpcs.xml.dist', 'phpcs.xml');\"", "@php -r \"if (!file_exists('phpstan.neon')) copy('phpstan.dist.neon', 'phpstan.neon');\"", From d2d1d0505de24b35c513adc677748ec125324762 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 04:04:00 -0400 Subject: [PATCH 18/30] update GEMINI.md and copilot-instructions.md --- .gemini/GEMINI.md | 5 ++--- .github/copilot-instructions.md | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.gemini/GEMINI.md b/.gemini/GEMINI.md index 59a33e44..03cc3ba4 100644 --- a/.gemini/GEMINI.md +++ b/.gemini/GEMINI.md @@ -16,12 +16,11 @@ This is the main FlightPHP core library for building fast, simple, and extensibl - Run tests: `composer test` (uses phpunit/phpunit and spatie/phpunit-watcher) - Run test server: `composer test-server` or `composer test-server-v2` - Lint code: `composer lint` (uses phpstan/phpstan, level 6) -- Beautify code: `composer beautify` (uses squizlabs/php_codesniffer, PSR1) -- Check code style: `composer phpcs` +- Format code: `composer format` (uses squizlabs/php_codesniffer, PSR12) - Test coverage: `composer test-coverage` ## Coding Standards -- Follow PSR1 coding standards (enforced by PHPCS) +- Follow PSR12 coding standards (enforced by PHPCS) - Use strict comparisons (`===`, `!==`) - PHPStan level 6 compliance - Focus on PHP 7.4 compatibility (avoid PHP 8+ only features) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 59a33e44..03cc3ba4 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -16,12 +16,11 @@ This is the main FlightPHP core library for building fast, simple, and extensibl - Run tests: `composer test` (uses phpunit/phpunit and spatie/phpunit-watcher) - Run test server: `composer test-server` or `composer test-server-v2` - Lint code: `composer lint` (uses phpstan/phpstan, level 6) -- Beautify code: `composer beautify` (uses squizlabs/php_codesniffer, PSR1) -- Check code style: `composer phpcs` +- Format code: `composer format` (uses squizlabs/php_codesniffer, PSR12) - Test coverage: `composer test-coverage` ## Coding Standards -- Follow PSR1 coding standards (enforced by PHPCS) +- Follow PSR12 coding standards (enforced by PHPCS) - Use strict comparisons (`===`, `!==`) - PHPStan level 6 compliance - Focus on PHP 7.4 compatibility (avoid PHP 8+ only features) From 26ce749db99d9846e8231051eeeef7b94f6f490f Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 04:05:48 -0400 Subject: [PATCH 19/30] remove ignored required_once __DIR__ . '/core/Loader.php' --- src/autoload.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/autoload.php b/src/autoload.php index 0a31c864..b5f84ab4 100644 --- a/src/autoload.php +++ b/src/autoload.php @@ -5,6 +5,5 @@ use flight\core\Loader; require_once __DIR__ . '/Flight.php'; -require_once __DIR__ . '/core/Loader.php'; Loader::autoload(true, [dirname(__DIR__)]); From 7b1e414717d8238b117dec71acade323578db8e8 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 04:07:50 -0400 Subject: [PATCH 20/30] update Loader docblock --- src/core/Loader.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/Loader.php b/src/core/Loader.php index 1824b9c7..bed0f0f9 100644 --- a/src/core/Loader.php +++ b/src/core/Loader.php @@ -8,12 +8,11 @@ use Exception; /** - * The Loader class is responsible for loading objects. It maintains - * a list of reusable class instances and can generate a new class - * instances with custom initialization parameters. It also performs - * class autoloading. + * The Loader class is responsible for loading objects. It maintains a list of + * reusable class instances and can generate a new class instances with custom + * initialization parameters. It also performs class autoloading. * - * @license MIT, http://flightphp.com/license + * @license MIT, https://docs.flightphp.com/license/ * @copyright Copyright (c) 2011, Mike Cao */ class Loader From 6784507bf8cf082750e5eb7f4218887248170251 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 11:11:25 -0400 Subject: [PATCH 21/30] refactor step 1 of Loader --- phpstan.dist.neon | 3 +- src/core/Loader.php | 107 +++++++++++++++----------------------------- 2 files changed, 38 insertions(+), 72 deletions(-) diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 57ab298b..d104bd58 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -5,6 +5,5 @@ includes: parameters: level: 6 paths: - - flight - - index.php + - src treatPhpDocTypesAsCertain: false diff --git a/src/core/Loader.php b/src/core/Loader.php index bed0f0f9..491af656 100644 --- a/src/core/Loader.php +++ b/src/core/Loader.php @@ -4,14 +4,12 @@ namespace flight\core; -use Closure; use Exception; /** * The Loader class is responsible for loading objects. It maintains a list of * reusable class instances and can generate a new class instances with custom * initialization parameters. It also performs class autoloading. - * * @license MIT, https://docs.flightphp.com/license/ * @copyright Copyright (c) 2011, Mike Cao */ @@ -19,50 +17,39 @@ class Loader { /** * Registered classes. - * - * @var array, ?callable}> $classes + * @var array, ?callable(object): void}> */ protected array $classes = []; - /** - * If this is disabled, classes can load with underscores - */ + /** If this is disabled, classes can load with underscores */ protected static bool $v2ClassLoading = true; - /** - * Class instances. - * - * @var array - */ + /** @var array Class instances */ protected array $instances = []; - /** - * Autoload directories. - * - * @var array - */ + /** @var array Autoload directories */ protected static array $dirs = []; /** * Registers a class. - * + * @template T of object * @param string $name Registry name - * @param class-string|Closure(): T $class Class name or function to instantiate class + * @param class-string|callable(): T $class Class name or function to instantiate class * @param array $params Class initialization parameters - * @param ?Closure(T $instance): void $callback $callback Function to call after object instantiation - * - * @template T of object + * @param ?callable(T): void $callback $callback Function to call after object instantiation */ - public function register(string $name, $class, array $params = [], ?callable $callback = null): void - { + public function register( + string $name, + $class, + array $params = [], + ?callable $callback = null + ): void { unset($this->instances[$name]); - $this->classes[$name] = [$class, $params, $callback]; } /** * Unregisters a class. - * * @param string $name Registry name */ public function unregister(string $name): void @@ -72,12 +59,9 @@ public function unregister(string $name): void /** * Loads a registered class. - * - * @param string $name Method name - * @param bool $shared Shared instance - * + * @param string $name Method name + * @param bool $shared Shared instance * @throws Exception - * * @return ?object Class instance */ public function load(string $name, bool $shared = true): ?object @@ -85,14 +69,13 @@ public function load(string $name, bool $shared = true): ?object $obj = null; if (isset($this->classes[$name])) { - [0 => $class, 1 => $params, 2 => $callback] = $this->classes[$name]; - + [$class, $params, $callback] = $this->classes[$name]; $exists = isset($this->instances[$name]); if ($shared) { - $obj = ($exists) ? - $this->getInstance($name) : - $this->newInstance($class, $params); + $obj = $exists + ? $this->getInstance($name) + : $this->newInstance($class, $params); if (!$exists) { $this->instances[$name] = $obj; @@ -103,7 +86,7 @@ public function load(string $name, bool $shared = true): ?object if ($callback && (!$shared || !$exists)) { $ref = [&$obj]; - \call_user_func_array($callback, $ref); + call_user_func_array($callback, $ref); } } @@ -112,9 +95,7 @@ public function load(string $name, bool $shared = true): ?object /** * Gets a single instance of a class. - * * @param string $name Instance name - * * @return ?object Class instance */ public function getInstance(string $name): ?object @@ -124,53 +105,43 @@ public function getInstance(string $name): ?object /** * Gets a new instance of a class. - * - * @param class-string|Closure(): class-string $class Class name or callback function to instantiate class - * @param array $params Class initialization parameters - * * @template T of object - * + * @param class-string|callable(): T $class Class name or callback function to instantiate class + * @param array $params Class initialization parameters * @throws Exception - * * @return T Class instance */ - public function newInstance($class, array $params = []) + public function newInstance($class, array $params = []): object { - if (\is_callable($class)) { - return \call_user_func_array($class, $params); + if (is_callable($class)) { + return call_user_func_array($class, $params); } return new $class(...$params); } /** - * Gets a registered callable - * + * Gets a registered callable. * @param string $name Registry name - * - * @return mixed Class information or null if not registered + * @return ?array{class-string|callable(): object, array, ?callable(object): void} + * Class information or null if not registered */ - public function get(string $name) + public function get(string $name): ?array { return $this->classes[$name] ?? null; } - /** - * Resets the object to the initial state. - */ + /** Resets the object to the initial state */ public function reset(): void { $this->classes = []; $this->instances = []; } - // Autoloading Functions - /** * Starts/stops autoloader. - * - * @param bool $enabled Enable/disable autoloading - * @param string|iterable $dirs Autoload directories + * @param bool $enabled Enable/disable autoloading + * @param string|iterable $dirs Autoload directories */ public static function autoload(bool $enabled = true, $dirs = []): void { @@ -187,14 +158,13 @@ public static function autoload(bool $enabled = true, $dirs = []): void /** * Autoloads classes. - * * Classes are not allowed to have underscores in their names. * * @param string $class Class name */ public static function loadClass(string $class): void { - $replace_chars = self::$v2ClassLoading === true ? ['\\', '_'] : ['\\']; + $replace_chars = self::$v2ClassLoading ? ['\\', '_'] : ['\\']; $classFile = str_replace($replace_chars, '/', $class) . '.php'; foreach (self::$dirs as $dir) { @@ -202,6 +172,7 @@ public static function loadClass(string $class): void if (file_exists($filePath)) { require_once $filePath; + return; } } @@ -209,17 +180,16 @@ public static function loadClass(string $class): void /** * Adds a directory for autoloading classes. - * * @param string|iterable $dir Directory path */ public static function addDirectory($dir): void { - if (\is_array($dir) || \is_object($dir)) { + if (is_array($dir) || is_object($dir)) { foreach ($dir as $value) { self::addDirectory($value); } - } elseif (\is_string($dir)) { - if (!\in_array($dir, self::$dirs, true)) { + } elseif (is_string($dir)) { + if (!in_array($dir, self::$dirs, true)) { self::$dirs[] = $dir; } } @@ -228,10 +198,7 @@ public static function addDirectory($dir): void /** * Sets the value for V2 class loading. - * * @param bool $value The value to set for V2 class loading. - * - * @return void */ public static function setV2ClassLoading(bool $value): void { From 886e58442957cc58ef25bec1b022b154068e3060 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 11:30:25 -0400 Subject: [PATCH 22/30] remove v2 loader in favor of psr-4 --- src/core/Loader.php | 20 ++------------------ tests/LoaderTest.php | 15 ++------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/core/Loader.php b/src/core/Loader.php index 491af656..167b6fda 100644 --- a/src/core/Loader.php +++ b/src/core/Loader.php @@ -15,15 +15,9 @@ */ class Loader { - /** - * Registered classes. - * @var array, ?callable(object): void}> - */ + /** @var array, ?callable(object): void}> */ protected array $classes = []; - /** If this is disabled, classes can load with underscores */ - protected static bool $v2ClassLoading = true; - /** @var array Class instances */ protected array $instances = []; @@ -164,7 +158,7 @@ public static function autoload(bool $enabled = true, $dirs = []): void */ public static function loadClass(string $class): void { - $replace_chars = self::$v2ClassLoading ? ['\\', '_'] : ['\\']; + $replace_chars = ['\\']; $classFile = str_replace($replace_chars, '/', $class) . '.php'; foreach (self::$dirs as $dir) { @@ -194,14 +188,4 @@ public static function addDirectory($dir): void } } } - - - /** - * Sets the value for V2 class loading. - * @param bool $value The value to set for V2 class loading. - */ - public static function setV2ClassLoading(bool $value): void - { - self::$v2ClassLoading = $value; - } } diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index de37efa8..2ab19b34 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -146,23 +146,12 @@ public function getDirectories() return self::$dirs; } }; + $loader->addDirectory([__DIR__ . '/classes']); + self::assertEquals([ dirname(__DIR__), __DIR__ . '/classes' ], $loader->getDirectories()); } - - public function testV2ClassLoading(): void - { - $loader = new class extends Loader { - public static function getV2ClassLoading() - { - return self::$v2ClassLoading; - } - }; - $this->assertTrue($loader::getV2ClassLoading()); - $loader::setV2ClassLoading(false); - $this->assertFalse($loader::getV2ClassLoading()); - } } From 07d72d24ef2888474da0230a2d316708ac8c8af6 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 11:38:29 -0400 Subject: [PATCH 23/30] remove Loader::autoload in favor of psr-4 --- composer.json | 4 ++-- src/Flight.php | 2 -- src/autoload.php | 9 --------- src/core/Loader.php | 18 ------------------ tests/LoaderTest.php | 22 ++-------------------- 5 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 src/autoload.php diff --git a/composer.json b/composer.json index 426f7f3a..e08f86ab 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,8 @@ "ext-json": "*" }, "autoload": { - "files": [ - "src/autoload.php" + "classmap": [ + "src/Flight.php" ], "psr-4": { "flight\\": "src" diff --git a/src/Flight.php b/src/Flight.php index c2e9a012..ddb536f3 100644 --- a/src/Flight.php +++ b/src/Flight.php @@ -11,8 +11,6 @@ use flight\core\EventDispatcher; use Psr\Container\ContainerInterface; -require_once __DIR__ . '/autoload.php'; - /** * The Flight class is a static representation of the framework. * diff --git a/src/autoload.php b/src/autoload.php deleted file mode 100644 index b5f84ab4..00000000 --- a/src/autoload.php +++ /dev/null @@ -1,9 +0,0 @@ -instances = []; } - /** - * Starts/stops autoloader. - * @param bool $enabled Enable/disable autoloading - * @param string|iterable $dirs Autoload directories - */ - public static function autoload(bool $enabled = true, $dirs = []): void - { - if ($enabled) { - spl_autoload_register([__CLASS__, 'loadClass']); - } else { - spl_autoload_unregister([__CLASS__, 'loadClass']); // @codeCoverageIgnore - } - - if (!empty($dirs)) { - self::addDirectory($dirs); - } - } - /** * Autoloads classes. * Classes are not allowed to have underscores in their names. diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index 2ab19b34..af4a1a84 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -5,9 +5,9 @@ namespace tests; use flight\core\Loader; -use tests\classes\Factory; -use tests\classes\User; use PHPUnit\Framework\TestCase; +use tests\classes\User; +use tests\classes\Factory; use tests\classes\TesterClass; class LoaderTest extends TestCase @@ -17,7 +17,6 @@ class LoaderTest extends TestCase protected function setUp(): void { $this->loader = new Loader(); - $this->loader->autoload(true, __DIR__ . '/classes'); } // Autoload a class @@ -137,21 +136,4 @@ public function testNewInstance6Params(): void $this->assertEquals('Sally', $TesterClass->param5); $this->assertEquals('Suzie', $TesterClass->param6); } - - public function testAddDirectoryAsArray(): void - { - $loader = new class extends Loader { - public function getDirectories() - { - return self::$dirs; - } - }; - - $loader->addDirectory([__DIR__ . '/classes']); - - self::assertEquals([ - dirname(__DIR__), - __DIR__ . '/classes' - ], $loader->getDirectories()); - } } From 78b8c4be60aaba5f1a1daf22613782a35f706a10 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 11:41:16 -0400 Subject: [PATCH 24/30] remove directory loading in favor of psr-4 --- src/core/Loader.php | 42 ------------------------------------------ tests/AutoloadTest.php | 1 - tests/FlightTest.php | 2 -- 3 files changed, 45 deletions(-) diff --git a/src/core/Loader.php b/src/core/Loader.php index c9ae5fcd..6d971b88 100644 --- a/src/core/Loader.php +++ b/src/core/Loader.php @@ -21,9 +21,6 @@ class Loader /** @var array Class instances */ protected array $instances = []; - /** @var array Autoload directories */ - protected static array $dirs = []; - /** * Registers a class. * @template T of object @@ -131,43 +128,4 @@ public function reset(): void $this->classes = []; $this->instances = []; } - - /** - * Autoloads classes. - * Classes are not allowed to have underscores in their names. - * - * @param string $class Class name - */ - public static function loadClass(string $class): void - { - $replace_chars = ['\\']; - $classFile = str_replace($replace_chars, '/', $class) . '.php'; - - foreach (self::$dirs as $dir) { - $filePath = "$dir/$classFile"; - - if (file_exists($filePath)) { - require_once $filePath; - - return; - } - } - } - - /** - * Adds a directory for autoloading classes. - * @param string|iterable $dir Directory path - */ - public static function addDirectory($dir): void - { - if (is_array($dir) || is_object($dir)) { - foreach ($dir as $value) { - self::addDirectory($value); - } - } elseif (is_string($dir)) { - if (!in_array($dir, self::$dirs, true)) { - self::$dirs[] = $dir; - } - } - } } diff --git a/tests/AutoloadTest.php b/tests/AutoloadTest.php index 97ee31aa..77fb0143 100644 --- a/tests/AutoloadTest.php +++ b/tests/AutoloadTest.php @@ -15,7 +15,6 @@ class AutoloadTest extends TestCase protected function setUp(): void { $this->app = new Engine(); - $this->app->path(__DIR__ . '/classes'); } // Autoload a class diff --git a/tests/FlightTest.php b/tests/FlightTest.php index 5b0b516f..c74feaaf 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -71,8 +71,6 @@ public function testGetAndSet(): void // Register a class public function testRegister(): void { - Flight::path(__DIR__ . '/classes'); - Flight::register('user', User::class); $user = Flight::user(); From 7a73e0e725ce0c273207b0e5233baeb298658a22 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 11:55:20 -0400 Subject: [PATCH 25/30] simplify ref object --- composer.json | 3 ++- src/core/Loader.php | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index e08f86ab..0d4817c2 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,8 @@ "phpunit/phpunit": "^9.6", "rregeer/phpunit-coverage-check": "^0.3.1", "spatie/phpunit-watcher": "^1.23", - "squizlabs/php_codesniffer": "^4.0" + "squizlabs/php_codesniffer": "^4.0", + "symfony/var-dumper": "^5.4" }, "config": { "allow-plugins": { diff --git a/src/core/Loader.php b/src/core/Loader.php index 6d971b88..4ee1a165 100644 --- a/src/core/Loader.php +++ b/src/core/Loader.php @@ -18,7 +18,7 @@ class Loader /** @var array, ?callable(object): void}> */ protected array $classes = []; - /** @var array Class instances */ + /** @var array */ protected array $instances = []; /** @@ -76,8 +76,7 @@ public function load(string $name, bool $shared = true): ?object } if ($callback && (!$shared || !$exists)) { - $ref = [&$obj]; - call_user_func_array($callback, $ref); + call_user_func_array($callback, [$obj]); } } From a9ce5967b97f49758082634c199d2b46ca2652e4 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 11:55:44 -0400 Subject: [PATCH 26/30] refactor LoaderTest --- tests/LoaderTest.php | 60 ++++++++++------------------------- tests/classes/TesterClass.php | 24 ++++++++------ tests/classes/User.php | 2 +- 3 files changed, 32 insertions(+), 54 deletions(-) diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index af4a1a84..7016130f 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -19,60 +19,39 @@ protected function setUp(): void $this->loader = new Loader(); } - // Autoload a class - public function testAutoload(): void - { - $this->loader->register('tests', User::class); - - $test = $this->loader->load('tests'); - - self::assertIsObject($test); - self::assertInstanceOf(User::class, $test); - } - - // Register a class public function testRegister(): void { $this->loader->register('a', User::class); - $user = $this->loader->load('a'); - self::assertIsObject($user); self::assertInstanceOf(User::class, $user); - self::assertEquals('', $user->name); + self::assertSame('', $user->name); } - // Register a class with constructor parameters public function testRegisterWithConstructor(): void { $this->loader->register('b', User::class, ['Bob']); - $user = $this->loader->load('b'); - self::assertIsObject($user); self::assertInstanceOf(User::class, $user); - self::assertEquals('Bob', $user->name); + self::assertSame('Bob', $user->name); } - // Register a class with initialization public function testRegisterWithInitialization(): void { - $this->loader->register('c', User::class, ['Bob'], function ($user) { + $this->loader->register('c', User::class, ['Bob'], static function (User $user): void { $user->name = 'Fred'; }); $user = $this->loader->load('c'); - self::assertIsObject($user); self::assertInstanceOf(User::class, $user); self::assertEquals('Fred', $user->name); } - // Get a non-shared instance of a class public function testSharedInstance(): void { $this->loader->register('d', User::class); - $user1 = $this->loader->load('d'); $user2 = $this->loader->load('d'); $user3 = $this->loader->load('d', false); @@ -81,38 +60,24 @@ public function testSharedInstance(): void self::assertNotSame($user1, $user3); } - // Gets an object from a factory method public function testRegisterUsingCallable(): void { - $this->loader->register('e', ['\tests\classes\Factory', 'create']); - + $this->loader->register('e', [Factory::class, 'create']); $obj = $this->loader->load('e'); - - self::assertIsObject($obj); - self::assertInstanceOf(Factory::class, $obj); - $obj2 = $this->loader->load('e'); + $obj3 = $this->loader->load('e', false); - self::assertIsObject($obj2); - self::assertInstanceOf(Factory::class, $obj2); + self::assertInstanceOf(Factory::class, $obj); self::assertSame($obj, $obj2); - - $obj3 = $this->loader->load('e', false); - self::assertIsObject($obj3); self::assertInstanceOf(Factory::class, $obj3); self::assertNotSame($obj, $obj3); } - // Gets an object from a callback function public function testRegisterUsingCallback(): void { - $this->loader->register('f', function () { - return Factory::create(); - }); - + $this->loader->register('f', static fn(): Factory => Factory::create()); $obj = $this->loader->load('f'); - self::assertIsObject($obj); self::assertInstanceOf(Factory::class, $obj); } @@ -120,15 +85,22 @@ public function testUnregisterClass(): void { $this->loader->register('g', User::class); $current_class = $this->loader->get('g'); - $this->assertEquals([User::class, [], null], $current_class); + + $this->assertSame([User::class, [], null], $current_class); + $this->loader->unregister('g'); $unregistered_class_result = $this->loader->get('g'); + $this->assertNull($unregistered_class_result); } public function testNewInstance6Params(): void { - $TesterClass = $this->loader->newInstance(TesterClass::class, ['Bob', 'Fred', 'Joe', 'Jane', 'Sally', 'Suzie']); + $TesterClass = $this->loader->newInstance( + TesterClass::class, + ['Bob', 'Fred', 'Joe', 'Jane', 'Sally', 'Suzie'] + ); + $this->assertEquals('Bob', $TesterClass->param1); $this->assertEquals('Fred', $TesterClass->param2); $this->assertEquals('Joe', $TesterClass->param3); diff --git a/tests/classes/TesterClass.php b/tests/classes/TesterClass.php index 289ee04c..2d9bf125 100644 --- a/tests/classes/TesterClass.php +++ b/tests/classes/TesterClass.php @@ -4,17 +4,23 @@ namespace tests\classes; -class TesterClass +final class TesterClass { - public $param1; - public $param2; - public $param3; - public $param4; - public $param5; - public $param6; + public string $param1; + public string $param2; + public string $param3; + public string $param4; + public string $param5; + public string $param6; - public function __construct($param1, $param2, $param3, $param4, $param5, $param6) - { + public function __construct( + string $param1, + string $param2, + string $param3, + string $param4, + string $param5, + string $param6 + ) { $this->param1 = $param1; $this->param2 = $param2; $this->param3 = $param3; diff --git a/tests/classes/User.php b/tests/classes/User.php index 0d141025..1a6c30b5 100644 --- a/tests/classes/User.php +++ b/tests/classes/User.php @@ -4,7 +4,7 @@ namespace tests\classes; -class User +final class User { public string $name; From 701e0e73cef8622074214883febeb95e052af1a4 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 11:59:42 -0400 Subject: [PATCH 27/30] fix TypeError --- tests/classes/TesterClass.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/classes/TesterClass.php b/tests/classes/TesterClass.php index 2d9bf125..a0066f41 100644 --- a/tests/classes/TesterClass.php +++ b/tests/classes/TesterClass.php @@ -6,20 +6,20 @@ final class TesterClass { - public string $param1; - public string $param2; - public string $param3; - public string $param4; - public string $param5; - public string $param6; + public ?string $param1; + public ?string $param2; + public ?string $param3; + public ?string $param4; + public ?string $param5; + public ?string $param6; public function __construct( - string $param1, - string $param2, - string $param3, - string $param4, - string $param5, - string $param6 + ?string $param1, + ?string $param2, + ?string $param3, + ?string $param4, + ?string $param5, + ?string $param6 ) { $this->param1 = $param1; $this->param2 = $param2; From dd201d1e8488e58cd3d3d6d7c51fcc4d41cccf49 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 18:12:12 -0400 Subject: [PATCH 28/30] replace Exception for Throwable --- src/core/Loader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/Loader.php b/src/core/Loader.php index 4ee1a165..c9656f14 100644 --- a/src/core/Loader.php +++ b/src/core/Loader.php @@ -4,7 +4,7 @@ namespace flight\core; -use Exception; +use Throwable; /** * The Loader class is responsible for loading objects. It maintains a list of @@ -52,7 +52,7 @@ public function unregister(string $name): void * Loads a registered class. * @param string $name Method name * @param bool $shared Shared instance - * @throws Exception + * @throws Throwable * @return ?object Class instance */ public function load(string $name, bool $shared = true): ?object @@ -98,7 +98,7 @@ public function getInstance(string $name): ?object * @template T of object * @param class-string|callable(): T $class Class name or callback function to instantiate class * @param array $params Class initialization parameters - * @throws Exception + * @throws Throwable * @return T Class instance */ public function newInstance($class, array $params = []): object From 95262bd39ecec905956ba621e33b548b72ab1896 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 18:22:50 -0400 Subject: [PATCH 29/30] refactor EventDispatcher --- src/core/EventDispatcher.php | 63 ++++++++++++------------------------ 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/src/core/EventDispatcher.php b/src/core/EventDispatcher.php index 8e60d1a6..251217c2 100644 --- a/src/core/EventDispatcher.php +++ b/src/core/EventDispatcher.php @@ -6,51 +6,44 @@ class EventDispatcher { - /** @var self|null Singleton instance of the EventDispatcher */ + /** Singleton instance of the EventDispatcher */ private static ?self $instance = null; - /** @var array> */ + /** @var array> */ protected array $listeners = []; - /** - * Singleton instance of the EventDispatcher. - * - * @return self - */ + /** Singleton instance of the EventDispatcher. */ public static function getInstance(): self { - if (self::$instance === null) { + if (!self::$instance) { self::$instance = new self(); } + return self::$instance; } /** * Register a callback for an event. - * * @param string $event Event name - * @param callable $callback Callback function + * @param callable(): mixed $callback Callback function */ public function on(string $event, callable $callback): void { - if (isset($this->listeners[$event]) === false) { - $this->listeners[$event] = []; - } + $this->listeners[$event] ??= []; $this->listeners[$event][] = $callback; } /** * Trigger an event with optional arguments. - * * @param string $event Event name * @param mixed ...$args Arguments to pass to the callbacks - * * @return mixed */ public function trigger(string $event, ...$args) { $result = null; - if (isset($this->listeners[$event]) === true) { + + if (isset($this->listeners[$event])) { foreach ($this->listeners[$event] as $callback) { $result = call_user_func_array($callback, $args); @@ -60,27 +53,24 @@ public function trigger(string $event, ...$args) } } } + return $result; } /** * Check if an event has any registered listeners. - * * @param string $event Event name - * * @return bool True if the event has listeners, false otherwise */ public function hasListeners(string $event): bool { - return isset($this->listeners[$event]) === true && count($this->listeners[$event]) > 0; + return isset($this->listeners[$event]) && count($this->listeners[$event]) > 0; } /** * Get all listeners registered for a specific event. - * * @param string $event Event name - * - * @return array Array of callbacks registered for the event + * @return array Array of callbacks registered for the event */ public function getListeners(string $event): array { @@ -89,7 +79,6 @@ public function getListeners(string $event): array /** * Get a list of all events that have registered listeners. - * * @return array Array of event names */ public function getAllRegisteredEvents(): array @@ -99,41 +88,31 @@ public function getAllRegisteredEvents(): array /** * Remove a specific listener for an event. - * * @param string $event the event name - * @param callable $callback the exact callback to remove - * - * @return void + * @param callable(): mixed $callback the exact callback to remove */ public function removeListener(string $event, callable $callback): void { - if (isset($this->listeners[$event]) === true && count($this->listeners[$event]) > 0) { - $this->listeners[$event] = array_filter($this->listeners[$event], function ($listener) use ($callback) { - return $listener !== $callback; - }); + if ($this->hasListeners($event)) { + $this->listeners[$event] = array_filter( + $this->listeners[$event], + static fn(callable $listener): bool => $listener !== $callback, + ); + $this->listeners[$event] = array_values($this->listeners[$event]); // Re-index the array } } /** * Remove all listeners for a specific event. - * * @param string $event the event name - * - * @return void */ public function removeAllListeners(string $event): void { - if (isset($this->listeners[$event]) === true) { - unset($this->listeners[$event]); - } + unset($this->listeners[$event]); } - /** - * Remove the current singleton instance of the EventDispatcher. - * - * @return void - */ + /** Remove the current singleton instance of the EventDispatcher. */ public static function resetInstance(): void { self::$instance = null; From 9dca6fb8365e4b1cc166ad87f9e1f4b8b1d8c5e5 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 26 Mar 2026 18:49:36 -0400 Subject: [PATCH 30/30] ignore phpunit-watcher.yml.dist from composer install --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index edcce414..72af06c1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,6 +8,6 @@ /phpcs.xml.dist export-ignore /phpstan-baseline.neon export-ignore /phpstan.dist.neon export-ignore -/phpunit-watcher.yml export-ignore +/phpunit-watcher.yml.dist export-ignore /phpunit.xml.dist export-ignore /README.md export-ignore