Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
},
"require-dev": {
"ext-pdo_sqlite": "*",
"flightphp/container": "^1.0",
"flightphp/container": "^1.3",
"flightphp/runway": "^1.2",
"league/container": "^4.2",
"level-2/dice": "^4.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^9.6",
"rregeer/phpunit-coverage-check": "^0.3.1",
"squizlabs/php_codesniffer": "^3.11"
"squizlabs/php_codesniffer": "^4.0"
},
"config": {
"allow-plugins": {
Expand Down Expand Up @@ -97,4 +97,4 @@
"replace": {
"mikecao/flight": "2.0.2"
}
}
}
8 changes: 1 addition & 7 deletions flight/commands/RouteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,7 @@ public function shouldAddRoute(Route $route)
$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;
}
Expand Down
10 changes: 2 additions & 8 deletions flight/core/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ public function setContainerHandler($containerHandler): void
{
$containerInterfaceNS = '\Psr\Container\ContainerInterface';

if (
is_a($containerHandler, $containerInterfaceNS)
|| is_callable($containerHandler)
) {
if (is_a($containerHandler, $containerInterfaceNS) || is_callable($containerHandler)) {
$this->containerHandler = $containerHandler;

return;
Expand Down Expand Up @@ -289,10 +286,7 @@ public function filter(array $filters, array &$params, &$output): void
*/
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);
}

Expand Down
10 changes: 1 addition & 9 deletions flight/net/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,7 @@ public static function parseQuery(string $url): array
*/
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';
}

Expand Down
2 changes: 1 addition & 1 deletion flight/net/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function moveTo(string $targetPath): void
$uploadFunctionToCall = $isUploadedFile === true ?
// Standard POST upload - use move_uploaded_file for security
'move_uploaded_file' :
// Handle non-POST uploads (PATCH, PUT, DELETE) or other valid temp files
// Handle non-POST uploads (PATCH, PUT, DELETE) or other valid temp files
'rename';

$result = $uploadFunctionToCall($this->tmpName, $targetPath);
Expand Down
61 changes: 17 additions & 44 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,54 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd"
name="pcsg-generated-ruleset">
<description>
Created with the PHP Coding Standard Generator.
http://edorian.github.io/php-coding-standard-generator/
</description>
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<!-- <arg name="report" value="source" /> -->
<!-- <arg name="report" value="summary" /> -->
<arg name="report" value="diff" />
<!-- <arg name="report" value="full" /> -->
<arg name="report-width" value="80" />
<arg name="colors" />
<arg name="encoding" value="utf-8" />
<arg name="tab-width" value="4" />

<rule ref="PSR1">
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
</rule>
<rule ref="PSR12" />
<rule ref="Generic">
<exclude name="Generic.PHP.ClosingPHPTag.NotFound" />
<exclude name="Generic.PHP.UpperCaseConstant.Found" />
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found" />
<exclude name="Generic.Files.EndFileNoNewline.Found" />
<exclude name="Generic.Files.LowercasedFilename.NotFound" />
<exclude name="Generic.Commenting.DocComment.TagValueIndent" />
<exclude name="Generic.Classes.OpeningBraceSameLine.BraceOnNewLine" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed" />
<exclude name="Generic.Commenting.DocComment.ContentAfterOpen" />
<exclude name="Generic.Commenting.DocComment.ContentBeforeClose" />
<exclude name="Generic.Commenting.DocComment.MissingShort" />
<exclude name="Generic.Commenting.DocComment.SpacingBeforeShort" />
<exclude name="Generic.Formatting.NoSpaceAfterCast.SpaceFound" />
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine" />
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
<exclude name="Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine" />
<exclude name="Generic.PHP.DisallowRequestSuperglobal.Found" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsedHeredocCloser" />

<rule ref="PSR2">
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="ignoreComments" value="true" />
</properties>

<rule ref="PSR12">
<exclude name="PSR12.Classes.AnonClassDeclaration.SpaceAfterKeyword"/>
</rule>
<rule ref="Generic.Formatting.SpaceAfterNot">
<properties>
<property name="spacing" value="0" />
</properties>
</rule>
<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing">
<properties>
<property name="ignoreNewlines" value="true" />
</properties>
</rule>
<file>flight/</file>
<file>tests/</file>
<exclude-pattern>tests/views/*</exclude-pattern>

<file>index.php</file>
<file>flight</file>
<file>tests</file>
</ruleset>
14 changes: 9 additions & 5 deletions tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public function testClosureMapping(): void

public function testFunctionMapping(): void
{
$this->dispatcher->set('map2', fn (): string => 'hello');
$this->dispatcher->set('map2', fn(): string => 'hello');

$this->assertSame('hello', $this->dispatcher->run('map2'));
}

public function testHasEvent(): void
{
$this->dispatcher->set('map-event', function (): void {
//
});

$this->assertTrue($this->dispatcher->has('map-event'));
Expand All @@ -54,6 +55,7 @@ public function testHasEvent(): void
public function testClearAllRegisteredEvents(): void
{
$customFunction = $anotherFunction = function (): void {
//
};

$this->dispatcher
Expand All @@ -72,6 +74,7 @@ public function testClearAllRegisteredEvents(): void
public function testClearDeclaredRegisteredEvent(): void
{
$customFunction = $anotherFunction = function (): void {
//
};

$this->dispatcher
Expand Down Expand Up @@ -110,7 +113,7 @@ public function testStaticClassMethodMapping(): void

public function testBeforeAndAfter(): void
{
$this->dispatcher->set('hello', fn (string $name): string => "Hello, $name!");
$this->dispatcher->set('hello', fn(string $name): string => "Hello, $name!");

$this->dispatcher
->hook('hello', Dispatcher::FILTER_BEFORE, function (array &$params): void {
Expand All @@ -129,7 +132,7 @@ public function testBeforeAndAfter(): void

public function testBeforeAndAfterWithShortAfterFilterSyntax(): void
{
$this->dispatcher->set('hello', fn (string $name): string => "Hello, $name!");
$this->dispatcher->set('hello', fn(string $name): string => "Hello, $name!");

$this->dispatcher
->hook('hello', Dispatcher::FILTER_BEFORE, function (array &$params): void {
Expand Down Expand Up @@ -247,6 +250,7 @@ public function testItThrowsAnExceptionForInvalidFilters(): void
$invalidCallable = 'invalidGlobalFunction';

$validCallable = function (): void {
//
};

$this->dispatcher->filter([$validCallable, $invalidCallable], $params, $output);
Expand Down Expand Up @@ -328,7 +332,7 @@ public function testExecuteStringClassDefaultContainerButForgotInjectingEngine()
{
$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
Expand All @@ -341,6 +345,6 @@ public function testContainerDicePdoWrapperTestBadParams(): void
$this->expectException(Exception::class);
$this->expectExceptionMessage('This is an exception in the constructor');

$this->dispatcher->invokeCallable([ ClassWithExceptionInConstruct::class, '__construct' ]);
$this->dispatcher->invokeCallable([ClassWithExceptionInConstruct::class, '__construct']);
}
}
Loading
Loading