Merge pull request #531 from flightphp/code-format

PHPCS code formatting problems solved
pull/533/head
fadrian06 1 year ago committed by GitHub
commit 9291d7a004
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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",
@ -49,8 +57,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",

@ -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,17 @@
{
"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 | composer phpcs -- --no-colors",
},
{
"name": "Format",
"quiet": true,
"shell_cmd": "composer beautify -- --no-colors"
}
],
}

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight;
use Closure;
@ -390,7 +390,11 @@ class Engine
// Run any before middlewares
if (count($route->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(
'<h1>404 Not Found</h1>' .
'<h3>The page you have requested could not be found.</h3>' .
str_repeat(' ', 512)
'<h3>The page you have requested could not be found.</h3>'
)
->send();
}

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
use flight\core\Dispatcher;
use flight\Engine;
use flight\net\Request;
@ -150,7 +150,6 @@ class Flight
* Set the engine instance
*
* @param Engine $engine Vroom vroom!
* @return void
*/
public static function setEngine(Engine $engine): void
{

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
use flight\core\Loader;
require_once __DIR__ . '/core/Loader.php';

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight\core;
use Exception;

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight\core;
use Closure;

@ -111,10 +111,11 @@ class PdoWrapper extends PDO
*/
protected function processInStatementSql(string $sql, array $params = []): array
{
// Handle "IN(?)". This is to be used with a comma delimited string, but can also be used with an array.
// Remove the spaces in variations of "IN ( ? )" where the space after IN is optional, and any number of spaces before and after the question mark is optional.
// Then loop through each "IN(?)" in the query and replace the single question mark with the correct number of question marks.
/* Handle "IN(?)". This is to be used with a comma delimited string, but can also be used with an array.
Remove the spaces in variations of "IN ( ? )" where the space after IN is optional, and any number of
spaces before and after the question mark is optional.
Then loop through each "IN(?)" in the query and replace the single question mark with the correct
number of question marks. */
$sql = preg_replace('/IN\s*\(\s*\?\s*\)/i', 'IN(?)', $sql);
$current_index = 0;
while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) {

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight\net;
use flight\util\Collection;

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight\net;
use Exception;
@ -288,7 +288,10 @@ class Response
* Sets a real header. Mostly used for test mocking.
*
* @param string $header_string The header string you would pass to header()
* @param bool $replace The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type. By default it will replace, but if you pass in false as the second argument you can force multiple headers of the same type.
* @param bool $replace The optional replace parameter indicates whether the
* header should replace a previous similar header, or add a second header of
* the same type. By default it will replace, but if you pass in false as the
* second argument you can force multiple headers of the same type.
* @param int $response_code The response code to send
* @return $this
* @codeCoverageIgnore

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight\net;
/**
@ -132,11 +132,9 @@ class Route
$regex
);
// Fix trailing slash
if ('/' === $last_char) {
if ('/' === $last_char) { // Fix trailing slash
$regex .= '?';
} // Allow trailing slash
else {
} else { // Allow trailing slash
$regex .= '/?';
}

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight\net;
use Exception;
@ -166,7 +166,8 @@ class Router
*
* @param string $group_prefix group URL prefix (such as /api/v1)
* @param callable $callback The necessary calling that holds the Router class
* @param array<int,callable|object> $group_middlewares The middlewares to be applied to the group Ex: [ $middleware1, $middleware2 ]
* @param array<int, callable|object> $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
{

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight\template;
/**

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license
*/
declare(strict_types=1);
namespace flight\util;
use ArrayAccess;

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="pcsg-generated-ruleset">
<description>Created with the PHP Coding Standard Generator. http://edorian.github.io/php-coding-standard-generator/</description>
<arg name="colors"/>
<arg name="tab-width" value="4"/>
<rule ref="PSR12"/>
<!-- <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/> -->
<file>flight/</file>
<file>tests/</file>
</ruleset>
<description>
Created with the PHP Coding Standard Generator.
http://edorian.github.io/php-coding-standard-generator/
</description>
<arg name="colors" />
<arg name="tab-width" value="4" />
<rule ref="PSR12" />
<file>flight/</file>
<file>tests/</file>
</ruleset>

@ -1,23 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="tests/phpunit_autoload.php"
executionOrder="random"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
stopOnError="true"
stopOnFailure="true"
verbose="true"
colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">flight/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="default">
<directory>tests/</directory>
</testsuite>
</testsuites>
<logging/>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="tests/phpunit_autoload.php"
executionOrder="random"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
stopOnError="true"
stopOnFailure="true"
verbose="true"
colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">flight/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="default">
<directory>tests/</directory>
</testsuite>
</testsuites>
<logging />
</phpunit>

@ -1,8 +1,5 @@
<?php
use flight\Engine;
use flight\net\Response;
/**
* Flight: An extensible micro-framework.
*
@ -10,8 +7,11 @@ use flight\net\Response;
* @license MIT, http://flightphp.com/license
*/
use flight\Engine;
use flight\net\Response;
use PHPUnit\Framework\TestCase;
class EngineTest extends PHPUnit\Framework\TestCase
class EngineTest extends TestCase
{
public function setUp(): void
{
@ -22,6 +22,7 @@ class EngineTest extends PHPUnit\Framework\TestCase
{
$_SERVER = [];
}
public function testInitBeforeStart()
{
$engine = new class extends Engine {
@ -123,7 +124,7 @@ class EngineTest extends PHPUnit\Framework\TestCase
echo 'i ran';
return true;
}, true);
$this->expectOutputString('<h1>404 Not Found</h1><h3>The page you have requested could not be found.</h3> ');
$this->expectOutputString('<h1>404 Not Found</h1><h3>The page you have requested could not be found.</h3>');
$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());

@ -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;

@ -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;

@ -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;

@ -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;

@ -1,23 +1,15 @@
<?php
use flight\template\View;
use PHPUnit\Framework\TestCase;
/**
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @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);

@ -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;
}
};
}

Loading…
Cancel
Save