From 29595ef9e18528b07520c64546e4da1e23fb4b77 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Mon, 16 Mar 2026 23:03:29 -0400 Subject: [PATCH] composer exec phpcbf -- --standard=PSR2 --- flight/commands/RouteCommand.php | 8 +--- flight/core/Dispatcher.php | 10 +---- flight/net/Request.php | 10 +---- phpcs.xml.dist | 3 ++ tests/DispatcherTest.php | 18 +++++--- tests/EventSystemTest.php | 40 ++++++++++++----- tests/RouterTest.php | 8 +++- tests/classes/Factory.php | 5 ++- tests/groupcompactsyntax/PostsController.php | 47 ++++++++++++++------ tests/groupcompactsyntax/TodosController.php | 10 ++++- 10 files changed, 102 insertions(+), 57 deletions(-) diff --git a/flight/commands/RouteCommand.php b/flight/commands/RouteCommand.php index 1667934..4273c2c 100644 --- a/flight/commands/RouteCommand.php +++ b/flight/commands/RouteCommand.php @@ -118,13 +118,7 @@ class RouteCommand extends AbstractBaseCommand $methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']; foreach ($methods as $method) { $lowercaseMethod = strtolower($method); - if ( - $this->{$lowercaseMethod} === true && - ( - $route->methods[0] === '*' || - in_array($method, $route->methods, true) === true - ) - ) { + if ($this->{$lowercaseMethod} === true && ($route->methods[0] === '*' || in_array($method, $route->methods, true) === true)) { $boolval = true; break; } diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index 2d45a49..00565e9 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -64,10 +64,7 @@ class Dispatcher { $containerInterfaceNS = '\Psr\Container\ContainerInterface'; - if ( - is_a($containerHandler, $containerInterfaceNS) - || is_callable($containerHandler) - ) { + if (is_a($containerHandler, $containerInterfaceNS) || is_callable($containerHandler)) { $this->containerHandler = $containerHandler; return; @@ -289,10 +286,7 @@ class Dispatcher */ public function execute($callback, array &$params = []) { - if ( - is_string($callback) === true - && (strpos($callback, '->') !== false || strpos($callback, '::') !== false) - ) { + if (is_string($callback) === true && (strpos($callback, '->') !== false || strpos($callback, '::') !== false)) { $callback = $this->parseStringClassAndMethod($callback); } diff --git a/flight/net/Request.php b/flight/net/Request.php index 845b55c..2e0a193 100644 --- a/flight/net/Request.php +++ b/flight/net/Request.php @@ -439,15 +439,7 @@ class Request */ public static function getScheme(): string { - if ( - (strtolower(self::getVar('HTTPS')) === 'on') - || - (self::getVar('HTTP_X_FORWARDED_PROTO') === 'https') - || - (self::getVar('HTTP_FRONT_END_HTTPS') === 'on') - || - (self::getVar('REQUEST_SCHEME') === 'https') - ) { + if ((strtolower(self::getVar('HTTPS')) === 'on') || (self::getVar('HTTP_X_FORWARDED_PROTO') === 'https') || (self::getVar('HTTP_FRONT_END_HTTPS') === 'on') || (self::getVar('REQUEST_SCHEME') === 'https')) { return 'https'; } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e21e213..118cf85 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -14,6 +14,9 @@ + + + index.php flight tests diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index e70b9e9..7935765 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -45,14 +45,18 @@ class DispatcherTest extends TestCase public function testHasEvent(): void { - $this->dispatcher->set('map-event', function (): void {}); + $this->dispatcher->set('map-event', function (): void { + // + }); $this->assertTrue($this->dispatcher->has('map-event')); } public function testClearAllRegisteredEvents(): void { - $customFunction = $anotherFunction = function (): void {}; + $customFunction = $anotherFunction = function (): void { + // + }; $this->dispatcher ->set('map-event', $customFunction) @@ -69,7 +73,9 @@ class DispatcherTest extends TestCase public function testClearDeclaredRegisteredEvent(): void { - $customFunction = $anotherFunction = function (): void {}; + $customFunction = $anotherFunction = function (): void { + // + }; $this->dispatcher ->set('map-event', $customFunction) @@ -243,7 +249,9 @@ class DispatcherTest extends TestCase $output = ''; $invalidCallable = 'invalidGlobalFunction'; - $validCallable = function (): void {}; + $validCallable = function (): void { + // + }; $this->dispatcher->filter([$validCallable, $invalidCallable], $params, $output); } @@ -324,7 +332,7 @@ class DispatcherTest extends TestCase { $this->expectException(TypeError::class); $this->expectExceptionMessageMatches('#tests\\\\classes\\\\ContainerDefault::__construct\(\).+flight\\\\Engine, null given#'); - $result = $this->dispatcher->execute([ContainerDefault::class, 'testTheContainer']); + $this->dispatcher->execute([ContainerDefault::class, 'testTheContainer']); } public function testContainerDicePdoWrapperTestBadParams(): void diff --git a/tests/EventSystemTest.php b/tests/EventSystemTest.php index 1e42194..ac03e5e 100644 --- a/tests/EventSystemTest.php +++ b/tests/EventSystemTest.php @@ -122,7 +122,9 @@ class EventSystemTest extends TestCase Flight::map('onEvent', function ($event, $callback) use (&$called) { $called = true; }); - Flight::onEvent('test.event', function () {}); + Flight::onEvent('test.event', function () { + // + }); $this->assertTrue($called, 'Overridden onEvent method should be called.'); } @@ -232,7 +234,9 @@ class EventSystemTest extends TestCase { $this->assertFalse(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should not have listeners before registration'); - Flight::onEvent('test.event', function () {}); + Flight::onEvent('test.event', function () { + // + }); $this->assertTrue(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should have listeners after registration'); } @@ -242,8 +246,12 @@ class EventSystemTest extends TestCase */ public function testGetListeners(): void { - $callback1 = function () {}; - $callback2 = function () {}; + $callback1 = function () { + // + }; + $callback2 = function () { + // + }; $this->assertEmpty(Flight::eventDispatcher()->getListeners('test.event'), 'Event should have no listeners before registration'); @@ -273,8 +281,12 @@ class EventSystemTest extends TestCase { $this->assertEmpty(Flight::eventDispatcher()->getAllRegisteredEvents(), 'No events should be registered initially'); - Flight::onEvent('test.event1', function () {}); - Flight::onEvent('test.event2', function () {}); + Flight::onEvent('test.event1', function () { + // + }); + Flight::onEvent('test.event2', function () { + // + }); $events = Flight::eventDispatcher()->getAllRegisteredEvents(); $this->assertCount(2, $events, 'Should return all registered event names'); @@ -311,9 +323,15 @@ class EventSystemTest extends TestCase */ public function testRemoveAllListeners(): void { - Flight::onEvent('test.event', function () {}); - Flight::onEvent('test.event', function () {}); - Flight::onEvent('another.event', function () {}); + Flight::onEvent('test.event', function () { + // + }); + Flight::onEvent('test.event', function () { + // + }); + Flight::onEvent('another.event', function () { + // + }); $this->assertTrue(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should have listeners before removal'); $this->assertTrue(Flight::eventDispatcher()->hasListeners('another.event'), 'Another event should have listeners'); @@ -330,7 +348,9 @@ class EventSystemTest extends TestCase public function testRemoveListenersForNonexistentEvent(): void { // Should not throw any errors - Flight::eventDispatcher()->removeListener('nonexistent.event', function () {}); + Flight::eventDispatcher()->removeListener('nonexistent.event', function () { + // + }); Flight::eventDispatcher()->removeAllListeners('nonexistent.event'); $this->assertTrue(true, 'Removing listeners for nonexistent events should not throw errors'); diff --git a/tests/RouterTest.php b/tests/RouterTest.php index dabb8ef..fb62958 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -411,14 +411,18 @@ class RouterTest extends TestCase public function testRouteBeingReturned(): void { - $route = $this->router->map('/hi', function () {}); + $route = $this->router->map('/hi', function () { + // + }); $route_in_router = $this->router->getRoutes()[0]; $this->assertSame($route, $route_in_router); } public function testRouteSetAlias(): void { - $route = $this->router->map('/hi', function () {}); + $route = $this->router->map('/hi', function () { + // + }); $route->setAlias('hello'); $this->assertEquals('hello', $route->alias); } diff --git a/tests/classes/Factory.php b/tests/classes/Factory.php index 13ccc39..3c1c30e 100644 --- a/tests/classes/Factory.php +++ b/tests/classes/Factory.php @@ -7,7 +7,10 @@ namespace tests\classes; class Factory { // Cannot be instantiated - private function __construct() {} + private function __construct() + { + // + } public static function create(): self { diff --git a/tests/groupcompactsyntax/PostsController.php b/tests/groupcompactsyntax/PostsController.php index 6339387..f95f60d 100644 --- a/tests/groupcompactsyntax/PostsController.php +++ b/tests/groupcompactsyntax/PostsController.php @@ -6,17 +6,38 @@ namespace tests\groupcompactsyntax; final class PostsController { - public function index(): void {} - - public function show(string $id): void {} - - public function create(): void {} - - public function store(): void {} - - public function edit(string $id): void {} - - public function update(string $id): void {} - - public function destroy(string $id): void {} + public function index(): void + { + // + } + + public function show(string $id): void + { + // + } + + public function create(): void + { + // + } + + public function store(): void + { + // + } + + public function edit(string $id): void + { + // + } + + public function update(string $id): void + { + // + } + + public function destroy(string $id): void + { + // + } } diff --git a/tests/groupcompactsyntax/TodosController.php b/tests/groupcompactsyntax/TodosController.php index 56b536f..91c30cf 100644 --- a/tests/groupcompactsyntax/TodosController.php +++ b/tests/groupcompactsyntax/TodosController.php @@ -6,7 +6,13 @@ namespace tests\groupcompactsyntax; final class TodosController { - public function index(): void {} + public function index(): void + { + // + } - public function show(string $id): void {} + public function show(string $id): void + { + // + } }