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" "flight/Flight.php"
] ]
}, },
"autoload-dev": {
"classmap": [
"tests/classes/User.php",
"tests/classes/Hello.php",
"tests/classes/Factory.php",
"tests/classes/TesterClass.php"
]
},
"require-dev": { "require-dev": {
"ext-pdo_sqlite": "*", "ext-pdo_sqlite": "*",
"phpunit/phpunit": "^9.5", "phpunit/phpunit": "^9.5",

@ -19,9 +19,15 @@
"source.json.sublime": "LSP-json", "source.json.sublime": "LSP-json",
}, },
"LSP-html": { "LSP-html": {
"enabled": false "enabled": false,
}, },
"LSP-tailwindcss": { "LSP-tailwindcss": {
"enabled": false,
},
"ltex-ls": {
"enabled": false,
},
"marksman": {
"enabled": false "enabled": false
}, },
}, },
@ -30,12 +36,17 @@
{ {
"name": "Linter - HARD", "name": "Linter - HARD",
"quiet": true, "quiet": true,
"shell_cmd": "composer lint -- --no-ansi -lmax" "shell_cmd": "composer lint -- --no-ansi -lmax",
}, },
{ {
"name": "Linter - Default", "name": "Linter - Default",
"quiet": true, "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 <?php
declare(strict_types=1);
/** /**
* Flight: An extensible micro-framework. * Flight: An extensible micro-framework.
* *
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license * @license MIT, http://flightphp.com/license
*/ */
declare(strict_types=1);
namespace flight; namespace flight;
use Closure; use Closure;
@ -390,7 +390,11 @@ class Engine
// Run any before middlewares // Run any before middlewares
if (count($route->middleware) > 0) { if (count($route->middleware) > 0) {
foreach ($route->middleware as $middleware) { 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) { if ($middleware_object === false) {
continue; continue;
@ -418,7 +422,15 @@ class Engine
// process the middleware in reverse order now // process the middleware in reverse order now
foreach (array_reverse($route->middleware) as $middleware) { foreach (array_reverse($route->middleware) as $middleware) {
// must be an object. No functions allowed here // 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 // has to have the after method, otherwise just skip it
if ($middleware_object === false) { if ($middleware_object === false) {
@ -608,8 +620,7 @@ class Engine
->status(404) ->status(404)
->write( ->write(
'<h1>404 Not Found</h1>' . '<h1>404 Not Found</h1>' .
'<h3>The page you have requested could not be found.</h3>' . '<h3>The page you have requested could not be found.</h3>'
str_repeat(' ', 512)
) )
->send(); ->send();
} }

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

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

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

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

@ -111,10 +111,11 @@ class PdoWrapper extends PDO
*/ */
protected function processInStatementSql(string $sql, array $params = []): array 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.
// 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
// 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. 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. 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); $sql = preg_replace('/IN\s*\(\s*\?\s*\)/i', 'IN(?)', $sql);
$current_index = 0; $current_index = 0;
while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) { while (($current_index = strpos($sql, 'IN(?)', $current_index)) !== false) {

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

@ -1,7 +1,5 @@
<?php <?php
declare(strict_types=1);
/** /**
* Flight: An extensible micro-framework. * Flight: An extensible micro-framework.
* *
@ -9,6 +7,8 @@ declare(strict_types=1);
* @license MIT, http://flightphp.com/license * @license MIT, http://flightphp.com/license
*/ */
declare(strict_types=1);
namespace flight\net; namespace flight\net;
use Exception; use Exception;
@ -288,7 +288,10 @@ class Response
* Sets a real header. Mostly used for test mocking. * Sets a real header. Mostly used for test mocking.
* *
* @param string $header_string The header string you would pass to header() * @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 * @param int $response_code The response code to send
* @return $this * @return $this
* @codeCoverageIgnore * @codeCoverageIgnore

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

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

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

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

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

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?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" <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" bootstrap="tests/phpunit_autoload.php"
executionOrder="random" executionOrder="random"
beStrictAboutOutputDuringTests="true" beStrictAboutOutputDuringTests="true"
@ -19,5 +21,5 @@
<directory>tests/</directory> <directory>tests/</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<logging/> <logging />
</phpunit> </phpunit>

@ -1,8 +1,5 @@
<?php <?php
use flight\Engine;
use flight\net\Response;
/** /**
* Flight: An extensible micro-framework. * Flight: An extensible micro-framework.
* *
@ -10,8 +7,11 @@ use flight\net\Response;
* @license MIT, http://flightphp.com/license * @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 public function setUp(): void
{ {
@ -22,6 +22,7 @@ class EngineTest extends PHPUnit\Framework\TestCase
{ {
$_SERVER = []; $_SERVER = [];
} }
public function testInitBeforeStart() public function testInitBeforeStart()
{ {
$engine = new class extends Engine { $engine = new class extends Engine {
@ -123,7 +124,7 @@ class EngineTest extends PHPUnit\Framework\TestCase
echo 'i ran'; echo 'i ran';
return true; return true;
}, 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(); $engine->start();
} }
@ -206,16 +207,21 @@ class EngineTest extends PHPUnit\Framework\TestCase
}; };
// doing this so we can overwrite some parts of the response // doing this so we can overwrite some parts of the response
$engine->getLoader()->register('response', function () { $engine->getLoader()->register('response', function () {
return new class extends \flight\net\Response { return new class extends Response {
public function __construct() 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; return $this;
} }
}; };
}); });
$this->expectOutputString('skip---exit'); $this->expectOutputString('skip---exit');
$engine->halt(500, 'skip---exit'); $engine->halt(500, 'skip---exit');
$this->assertEquals(500, $engine->response()->status()); $this->assertEquals(500, $engine->response()->status());

@ -8,12 +8,9 @@
*/ */
use flight\core\Loader; use flight\core\Loader;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/classes/User.php'; class LoaderTest extends TestCase
require_once __DIR__ . '/classes/Factory.php';
require_once __DIR__ . '/classes/TesterClass.php';
class LoaderTest extends PHPUnit\Framework\TestCase
{ {
private Loader $loader; private Loader $loader;

@ -8,10 +8,9 @@
*/ */
use flight\Engine; use flight\Engine;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/classes/Hello.php'; class MapTest extends TestCase
class MapTest extends PHPUnit\Framework\TestCase
{ {
private Engine $app; private Engine $app;

@ -8,10 +8,9 @@
*/ */
use flight\Engine; use flight\Engine;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/classes/User.php'; class RegisterTest extends TestCase
class RegisterTest extends PHPUnit\Framework\TestCase
{ {
private Engine $app; private Engine $app;

@ -264,7 +264,21 @@ class RouterTest extends PHPUnit\Framework\TestCase
public function testRouteWithLongQueryParamWithMultilineEncoded() public function testRouteWithLongQueryParamWithMultilineEncoded()
{ {
$this->router->map('GET /api/intune/hey', [$this, 'ok']); $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'); $this->check('OK');
} }
@ -406,7 +420,8 @@ class RouterTest extends PHPUnit\Framework\TestCase
public function testResetRoutes() public function testResetRoutes()
{ {
$router = new class extends Router { $router = new class extends Router
{
public function getIndex() public function getIndex()
{ {
return $this->index; return $this->index;

@ -1,23 +1,15 @@
<?php <?php
use flight\template\View; use flight\template\View;
use PHPUnit\Framework\TestCase;
/** class ViewTest extends 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
{ {
/** private View $view;
* @var \flight\template\View
*/
private $view;
protected function setUp(): void protected function setUp(): void
{ {
$this->view = new \flight\template\View(); $this->view = new View();
$this->view->path = __DIR__ . '/views'; $this->view->path = __DIR__ . '/views';
} }
@ -70,7 +62,13 @@ class ViewTest extends PHPUnit\Framework\TestCase
public function testRenderBadFilePath() public function testRenderBadFilePath()
{ {
$this->expectException(Exception::class); $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'); $this->view->render('badfile');
} }
@ -128,7 +126,8 @@ class ViewTest extends PHPUnit\Framework\TestCase
public function testNormalizePath(): void 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 public static function normalizePath(string $path, string $separator = DIRECTORY_SEPARATOR): string
{ {
return parent::normalizePath($path, $separator); return parent::normalizePath($path, $separator);

@ -8,6 +8,7 @@ class TesterClass
public $param4; public $param4;
public $param5; public $param5;
public $param6; public $param6;
public function __construct($param1, $param2, $param3, $param4, $param5, $param6) public function __construct($param1, $param2, $param3, $param4, $param5, $param6)
{ {
$this->param1 = $param1; $this->param1 = $param1;
@ -17,4 +18,4 @@ class TesterClass
$this->param5 = $param5; $this->param5 = $param5;
$this->param6 = $param6; $this->param6 = $param6;
} }
}; }

Loading…
Cancel
Save