composer exec phpcbf -- --standard=PSR2

pull/685/head
fadrian06 2 days ago
parent 85c4b38858
commit 29595ef9e1

@ -118,13 +118,7 @@ class RouteCommand extends AbstractBaseCommand
$methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']; $methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'];
foreach ($methods as $method) { foreach ($methods as $method) {
$lowercaseMethod = strtolower($method); $lowercaseMethod = strtolower($method);
if ( if ($this->{$lowercaseMethod} === true && ($route->methods[0] === '*' || in_array($method, $route->methods, true) === true)) {
$this->{$lowercaseMethod} === true &&
(
$route->methods[0] === '*' ||
in_array($method, $route->methods, true) === true
)
) {
$boolval = true; $boolval = true;
break; break;
} }

@ -64,10 +64,7 @@ class Dispatcher
{ {
$containerInterfaceNS = '\Psr\Container\ContainerInterface'; $containerInterfaceNS = '\Psr\Container\ContainerInterface';
if ( if (is_a($containerHandler, $containerInterfaceNS) || is_callable($containerHandler)) {
is_a($containerHandler, $containerInterfaceNS)
|| is_callable($containerHandler)
) {
$this->containerHandler = $containerHandler; $this->containerHandler = $containerHandler;
return; return;
@ -289,10 +286,7 @@ class Dispatcher
*/ */
public function execute($callback, array &$params = []) public function execute($callback, array &$params = [])
{ {
if ( if (is_string($callback) === true && (strpos($callback, '->') !== false || strpos($callback, '::') !== false)) {
is_string($callback) === true
&& (strpos($callback, '->') !== false || strpos($callback, '::') !== false)
) {
$callback = $this->parseStringClassAndMethod($callback); $callback = $this->parseStringClassAndMethod($callback);
} }

@ -439,15 +439,7 @@ class Request
*/ */
public static function getScheme(): string public static function getScheme(): string
{ {
if ( 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')) {
(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'; return 'https';
} }

@ -14,6 +14,9 @@
<rule ref="PSR1"> <rule ref="PSR1">
</rule> </rule>
<rule ref="PSR2">
</rule>
<file>index.php</file> <file>index.php</file>
<file>flight</file> <file>flight</file>
<file>tests</file> <file>tests</file>

@ -45,14 +45,18 @@ class DispatcherTest extends TestCase
public function testHasEvent(): void 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')); $this->assertTrue($this->dispatcher->has('map-event'));
} }
public function testClearAllRegisteredEvents(): void public function testClearAllRegisteredEvents(): void
{ {
$customFunction = $anotherFunction = function (): void {}; $customFunction = $anotherFunction = function (): void {
//
};
$this->dispatcher $this->dispatcher
->set('map-event', $customFunction) ->set('map-event', $customFunction)
@ -69,7 +73,9 @@ class DispatcherTest extends TestCase
public function testClearDeclaredRegisteredEvent(): void public function testClearDeclaredRegisteredEvent(): void
{ {
$customFunction = $anotherFunction = function (): void {}; $customFunction = $anotherFunction = function (): void {
//
};
$this->dispatcher $this->dispatcher
->set('map-event', $customFunction) ->set('map-event', $customFunction)
@ -243,7 +249,9 @@ class DispatcherTest extends TestCase
$output = ''; $output = '';
$invalidCallable = 'invalidGlobalFunction'; $invalidCallable = 'invalidGlobalFunction';
$validCallable = function (): void {}; $validCallable = function (): void {
//
};
$this->dispatcher->filter([$validCallable, $invalidCallable], $params, $output); $this->dispatcher->filter([$validCallable, $invalidCallable], $params, $output);
} }
@ -324,7 +332,7 @@ class DispatcherTest extends TestCase
{ {
$this->expectException(TypeError::class); $this->expectException(TypeError::class);
$this->expectExceptionMessageMatches('#tests\\\\classes\\\\ContainerDefault::__construct\(\).+flight\\\\Engine, null given#'); $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 public function testContainerDicePdoWrapperTestBadParams(): void

@ -122,7 +122,9 @@ class EventSystemTest extends TestCase
Flight::map('onEvent', function ($event, $callback) use (&$called) { Flight::map('onEvent', function ($event, $callback) use (&$called) {
$called = true; $called = true;
}); });
Flight::onEvent('test.event', function () {}); Flight::onEvent('test.event', function () {
//
});
$this->assertTrue($called, 'Overridden onEvent method should be called.'); $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'); $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'); $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 public function testGetListeners(): void
{ {
$callback1 = function () {}; $callback1 = function () {
$callback2 = function () {}; //
};
$callback2 = function () {
//
};
$this->assertEmpty(Flight::eventDispatcher()->getListeners('test.event'), 'Event should have no listeners before registration'); $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'); $this->assertEmpty(Flight::eventDispatcher()->getAllRegisteredEvents(), 'No events should be registered initially');
Flight::onEvent('test.event1', function () {}); Flight::onEvent('test.event1', function () {
Flight::onEvent('test.event2', function () {}); //
});
Flight::onEvent('test.event2', function () {
//
});
$events = Flight::eventDispatcher()->getAllRegisteredEvents(); $events = Flight::eventDispatcher()->getAllRegisteredEvents();
$this->assertCount(2, $events, 'Should return all registered event names'); $this->assertCount(2, $events, 'Should return all registered event names');
@ -311,9 +323,15 @@ class EventSystemTest extends TestCase
*/ */
public function testRemoveAllListeners(): void public function testRemoveAllListeners(): void
{ {
Flight::onEvent('test.event', function () {}); Flight::onEvent('test.event', function () {
Flight::onEvent('test.event', function () {}); //
Flight::onEvent('another.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('test.event'), 'Event should have listeners before removal');
$this->assertTrue(Flight::eventDispatcher()->hasListeners('another.event'), 'Another event should have listeners'); $this->assertTrue(Flight::eventDispatcher()->hasListeners('another.event'), 'Another event should have listeners');
@ -330,7 +348,9 @@ class EventSystemTest extends TestCase
public function testRemoveListenersForNonexistentEvent(): void public function testRemoveListenersForNonexistentEvent(): void
{ {
// Should not throw any errors // Should not throw any errors
Flight::eventDispatcher()->removeListener('nonexistent.event', function () {}); Flight::eventDispatcher()->removeListener('nonexistent.event', function () {
//
});
Flight::eventDispatcher()->removeAllListeners('nonexistent.event'); Flight::eventDispatcher()->removeAllListeners('nonexistent.event');
$this->assertTrue(true, 'Removing listeners for nonexistent events should not throw errors'); $this->assertTrue(true, 'Removing listeners for nonexistent events should not throw errors');

@ -411,14 +411,18 @@ class RouterTest extends TestCase
public function testRouteBeingReturned(): void public function testRouteBeingReturned(): void
{ {
$route = $this->router->map('/hi', function () {}); $route = $this->router->map('/hi', function () {
//
});
$route_in_router = $this->router->getRoutes()[0]; $route_in_router = $this->router->getRoutes()[0];
$this->assertSame($route, $route_in_router); $this->assertSame($route, $route_in_router);
} }
public function testRouteSetAlias(): void public function testRouteSetAlias(): void
{ {
$route = $this->router->map('/hi', function () {}); $route = $this->router->map('/hi', function () {
//
});
$route->setAlias('hello'); $route->setAlias('hello');
$this->assertEquals('hello', $route->alias); $this->assertEquals('hello', $route->alias);
} }

@ -7,7 +7,10 @@ namespace tests\classes;
class Factory class Factory
{ {
// Cannot be instantiated // Cannot be instantiated
private function __construct() {} private function __construct()
{
//
}
public static function create(): self public static function create(): self
{ {

@ -6,17 +6,38 @@ namespace tests\groupcompactsyntax;
final class PostsController final class PostsController
{ {
public function index(): void {} public function index(): void
{
//
}
public function show(string $id): void {} public function show(string $id): void
{
//
}
public function create(): void {} public function create(): void
{
//
}
public function store(): void {} public function store(): void
{
//
}
public function edit(string $id): void {} public function edit(string $id): void
{
//
}
public function update(string $id): void {} public function update(string $id): void
{
//
}
public function destroy(string $id): void {} public function destroy(string $id): void
{
//
}
} }

@ -6,7 +6,13 @@ namespace tests\groupcompactsyntax;
final class TodosController final class TodosController
{ {
public function index(): void {} public function index(): void
{
//
}
public function show(string $id): void {} public function show(string $id): void
{
//
}
} }

Loading…
Cancel
Save