Skip to content

Commit 3941d44

Browse files
authored
Merge pull request #685 from flightphp/fix-phpcs-errors
Fix phpcs errors
2 parents d50c8c9 + ce753b7 commit 3941d44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+860
-596
lines changed

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,23 @@
3838
"psr-4": {
3939
"Tests\\PHP8\\": [
4040
"tests/named-arguments"
41-
]
41+
],
42+
"Tests\\Server\\": "tests/server",
43+
"Tests\\ServerV2\\": "tests/server-v2",
44+
"tests\\groupcompactsyntax\\": "tests/groupcompactsyntax"
4245
}
4346
},
4447
"require-dev": {
4548
"ext-pdo_sqlite": "*",
46-
"flightphp/container": "^1.0",
49+
"flightphp/container": "^1.3",
4750
"flightphp/runway": "^1.2",
4851
"league/container": "^4.2",
4952
"level-2/dice": "^4.0",
5053
"phpstan/extension-installer": "^1.4",
5154
"phpstan/phpstan": "^2.1",
5255
"phpunit/phpunit": "^9.6",
5356
"rregeer/phpunit-coverage-check": "^0.3.1",
54-
"squizlabs/php_codesniffer": "^3.11"
57+
"squizlabs/php_codesniffer": "^4.0"
5558
},
5659
"config": {
5760
"allow-plugins": {
@@ -84,7 +87,7 @@
8487
],
8588
"lint": "phpstan --no-progress --memory-limit=256M",
8689
"beautify": "phpcbf --standard=phpcs.xml",
87-
"phpcs": "phpcs --standard=phpcs.xml -n",
90+
"phpcs": "phpcs",
8891
"post-install-cmd": [
8992
"php -r \"if (!file_exists('phpcs.xml')) copy('phpcs.xml.dist', 'phpcs.xml');\"",
9093
"php -r \"if (!file_exists('phpstan.neon')) copy('phpstan.dist.neon', 'phpstan.neon');\"",

flight/Engine.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ public function handleException(Throwable $e): void
267267
/**
268268
* Registers the container handler
269269
*
270-
* @param ContainerInterface|callable(class-string<T> $id, array<int|string, mixed> $params): ?T $containerHandler Callback function or PSR-11 Container object that sets the container and how it will inject classes
270+
* @param ContainerInterface|callable(class-string<T> $id, array<int|string, mixed> $params): ?T $containerHandler
271+
* Callback function or PSR-11 Container object that sets the container and how it will inject classes
271272
*
272273
* @template T of object
273274
*/
@@ -488,7 +489,14 @@ protected function processMiddleware(Route $route, string $eventName): bool
488489
// Which loosely translates to $class->$method($params)
489490
$start = microtime(true);
490491
$middlewareResult = $middlewareObject($params);
491-
$this->triggerEvent('flight.middleware.executed', $route, $middleware, $eventName, microtime(true) - $start);
492+
493+
$this->triggerEvent(
494+
'flight.middleware.executed',
495+
$route,
496+
$middleware,
497+
$eventName,
498+
microtime(true) - $start
499+
);
492500

493501
if ($useV3OutputBuffering === true) {
494502
$this->response()->write(ob_get_clean());
@@ -860,7 +868,12 @@ public function _notFound(): void
860868
public function _methodNotFound(Route $route): void
861869
{
862870
$this->response()->setHeader('Allow', implode(', ', $route->methods));
863-
$this->halt(405, 'Method Not Allowed. Allowed Methods are: ' . implode(', ', $route->methods), empty(getenv('PHPUNIT_TEST')));
871+
872+
$this->halt(
873+
405,
874+
'Method Not Allowed. Allowed Methods are: ' . implode(', ', $route->methods),
875+
empty(getenv('PHPUNIT_TEST'))
876+
);
864877
}
865878

866879
/**

flight/Flight.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@
8080
* @phpstan-method static void jsonHalt(mixed $data, int $code = 200, bool $encode = true, string $charset = 'utf-8', int $option = 0)
8181
* @phpstan-method static void jsonp(mixed $data, string $param = 'jsonp', int $code = 200, bool $encode = true, string $charset = "utf8", int $encodeOption = 0, int $encodeDepth = 512)
8282
*
83-
* Note: IDEs will use standard @method tags for autocompletion, while PHPStan will use @phpstan-* tags for advanced type checking.
83+
* Note: IDEs will use standard @method tags for autocompletion,
84+
* while PHPStan will use @phpstan-* tags for advanced type checking.
8485
*/
86+
// phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace
8587
class Flight
8688
{
8789
/**

flight/commands/AiGenerateInstructionsCommand.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ class AiGenerateInstructionsCommand extends AbstractBaseCommand
2020
public function __construct(array $config)
2121
{
2222
parent::__construct('ai:generate-instructions', 'Generate project-specific AI coding instructions', $config);
23-
$this->option('--config-file', 'Path to .runway-config.json file (deprecated, use config.php instead)', null, '');
23+
24+
$this->option(
25+
'--config-file',
26+
'Path to .runway-config.json file (deprecated, use config.php instead)',
27+
null,
28+
''
29+
);
2430
}
2531

2632
/**
@@ -40,7 +46,12 @@ public function execute(): int
4046
if (empty($this->config['runway'])) {
4147
$configFile = $this->configFile;
4248
$io = $this->app()->io();
43-
$io->warn('The --config-file option is deprecated. Move your config values to the \'runway\' key in the config.php file for configuration.', true);
49+
50+
$io->warn(
51+
'The --config-file option is deprecated. '
52+
. 'Move your config values to the \'runway\' key in the config.php file for configuration.',
53+
true
54+
);
4455
$runwayConfig = json_decode(file_get_contents($configFile), true) ?? [];
4556
} else {
4657
$runwayConfig = $this->config['runway'];
@@ -56,12 +67,30 @@ public function execute(): int
5667

5768
// Ask questions
5869
$projectDesc = $io->prompt('Please describe what your project is for?');
59-
$database = $io->prompt('What database are you planning on using? (e.g. MySQL, SQLite, PostgreSQL, none)', 'none');
60-
$templating = $io->prompt('What HTML templating engine will you plan on using (if any)? (recommend latte)', 'latte');
70+
71+
$database = $io->prompt(
72+
'What database are you planning on using? (e.g. MySQL, SQLite, PostgreSQL, none)',
73+
'none'
74+
);
75+
76+
$templating = $io->prompt(
77+
'What HTML templating engine will you plan on using (if any)? (recommend latte)',
78+
'latte'
79+
);
80+
6181
$security = $io->confirm('Is security an important element of this project?', 'y');
6282
$performance = $io->confirm('Is performance and speed an important part of this project?', 'y');
63-
$composerLibs = $io->prompt('What major composer libraries will you be using if you know them right now?', 'none');
64-
$envSetup = $io->prompt('How will you set up your development environment? (e.g. Docker, Vagrant, PHP dev server, other)', 'Docker');
83+
84+
$composerLibs = $io->prompt(
85+
'What major composer libraries will you be using if you know them right now?',
86+
'none'
87+
);
88+
89+
$envSetup = $io->prompt(
90+
'How will you set up your development environment? (e.g. Docker, Vagrant, PHP dev server, other)',
91+
'Docker'
92+
);
93+
6594
$teamSize = $io->prompt('How many developers will be working on this project?', '1');
6695
$api = $io->confirm('Will this project expose an API?', 'n');
6796
$other = $io->prompt('Any other important requirements or context? (optional)', 'no');
@@ -107,7 +136,13 @@ public function execute(): int
107136
$data = [
108137
'model' => $model,
109138
'messages' => [
110-
['role' => 'system', 'content' => 'You are a helpful AI coding assistant focused on the Flight Framework for PHP. You are up to date with all your knowledge from https://docs.flightphp.com. As an expert into the programming language PHP, you are top notch at architecting out proper instructions for FlightPHP projects.'],
139+
[
140+
'role' => 'system',
141+
'content' => 'You are a helpful AI coding assistant focused on the Flight Framework for PHP. '
142+
. 'You are up to date with all your knowledge from https://docs.flightphp.com. '
143+
. 'As an expert into the programming language PHP, '
144+
. 'you are top notch at architecting out proper instructions for FlightPHP projects.'
145+
],
111146
['role' => 'user', 'content' => $prompt],
112147
],
113148
'temperature' => 0.2,
@@ -129,7 +164,11 @@ public function execute(): int
129164
}
130165

131166
// Write to files
132-
$io->info('Updating .github/copilot-instructions.md, .cursor/rules/project-overview.mdc, .gemini/GEMINI.md and .windsurfrules...', true);
167+
$io->info(
168+
'Updating .github/copilot-instructions.md, .cursor/rules/project-overview.mdc, .gemini/GEMINI.md and .windsurfrules...',
169+
true
170+
);
171+
133172
if (!is_dir($this->projectRoot . '.github')) {
134173
mkdir($this->projectRoot . '.github', 0755, true);
135174
}

flight/commands/AiInitCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ public function execute(): int
7979
$defaultModel = 'claude-sonnet-4-5';
8080
break;
8181
}
82-
$model = trim($io->prompt('Enter the model name you want to use (e.g. gpt-5, claude-sonnet-4-5, etc)', $defaultModel));
82+
83+
$model = trim($io->prompt(
84+
'Enter the model name you want to use (e.g. gpt-5, claude-sonnet-4-5, etc)',
85+
$defaultModel
86+
));
8387

8488
$runwayAiConfig = [
8589
'provider' => $api,

flight/commands/ControllerCommand.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ public function execute(string $controller): void
3131
$io = $this->app()->io();
3232

3333
if (empty($this->config['runway'])) {
34-
$io->warn('Using a .runway-config.json file is deprecated. Move your config values to app/config/config.php with `php runway config:migrate`.', true); // @codeCoverageIgnore
35-
$runwayConfig = json_decode(file_get_contents($this->projectRoot . '/.runway-config.json'), true); // @codeCoverageIgnore
34+
$io->warn(
35+
'Using a .runway-config.json file is deprecated. '
36+
. 'Move your config values to app/config/config.php with `php runway config:migrate`.',
37+
true
38+
); // @codeCoverageIgnore
39+
40+
$runwayConfig = json_decode(
41+
file_get_contents($this->projectRoot . '/.runway-config.json'),
42+
true
43+
); // @codeCoverageIgnore
3644
} else {
3745
$runwayConfig = $this->config['runway'];
3846
}
@@ -95,6 +103,9 @@ public function execute(string $controller): void
95103
protected function persistClass(string $controllerName, PhpFile $file, string $appRoot)
96104
{
97105
$printer = new \Nette\PhpGenerator\PsrPrinter();
98-
file_put_contents($this->projectRoot . '/' . $appRoot . 'controllers/' . $controllerName . '.php', $printer->printFile($file));
106+
file_put_contents(
107+
$this->projectRoot . '/' . $appRoot . 'controllers/' . $controllerName . '.php',
108+
$printer->printFile($file)
109+
);
99110
}
100111
}

flight/commands/RouteCommand.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,7 @@ public function shouldAddRoute(Route $route)
118118
$methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'];
119119
foreach ($methods as $method) {
120120
$lowercaseMethod = strtolower($method);
121-
if (
122-
$this->{$lowercaseMethod} === true &&
123-
(
124-
$route->methods[0] === '*' ||
125-
in_array($method, $route->methods, true) === true
126-
)
127-
) {
121+
if ($this->{$lowercaseMethod} === true && ($route->methods[0] === '*' || in_array($method, $route->methods, true) === true)) {
128122
$boolval = true;
129123
break;
130124
}

flight/core/Dispatcher.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,14 @@ class Dispatcher
5858
*
5959
* @template T of object
6060
*
61-
* @throws InvalidArgumentException If $containerHandler is not a `callable` or instance of `Psr\Container\ContainerInterface`.
61+
* @throws InvalidArgumentException
62+
* If $containerHandler is not a `callable` or instance of `Psr\Container\ContainerInterface`.
6263
*/
6364
public function setContainerHandler($containerHandler): void
6465
{
6566
$containerInterfaceNS = '\Psr\Container\ContainerInterface';
6667

67-
if (
68-
is_a($containerHandler, $containerInterfaceNS)
69-
|| is_callable($containerHandler)
70-
) {
68+
if (is_a($containerHandler, $containerInterfaceNS) || is_callable($containerHandler)) {
7169
$this->containerHandler = $containerHandler;
7270

7371
return;
@@ -289,10 +287,7 @@ public function filter(array $filters, array &$params, &$output): void
289287
*/
290288
public function execute($callback, array &$params = [])
291289
{
292-
if (
293-
is_string($callback) === true
294-
&& (strpos($callback, '->') !== false || strpos($callback, '::') !== false)
295-
) {
290+
if (is_string($callback) === true && (strpos($callback, '->') !== false || strpos($callback, '::') !== false)) {
296291
$callback = $this->parseStringClassAndMethod($callback);
297292
}
298293

@@ -419,7 +414,10 @@ protected function verifyValidClassCallable($class, $method, $resolvedClass): vo
419414

420415
// Final check to make sure it's actually a class and a method, or throw an error
421416
if (is_object($class) === false && class_exists($class) === false) {
422-
$exception = new Exception("Class '$class' not found. Is it being correctly autoloaded with Flight::path()?");
417+
$exception = new Exception(
418+
"Class '$class' not found. "
419+
. "Is it being correctly autoloaded with Flight::path()?"
420+
);
423421

424422
// If this tried to resolve a class in a container and failed somehow, throw the exception
425423
} elseif (!$resolvedClass && $this->containerException !== null) {

flight/net/Request.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,13 @@ public static function parseQuery(string $url): array
439439
*/
440440
public static function getScheme(): string
441441
{
442-
if (
443-
(strtolower(self::getVar('HTTPS')) === 'on')
444-
||
445-
(self::getVar('HTTP_X_FORWARDED_PROTO') === 'https')
446-
||
447-
(self::getVar('HTTP_FRONT_END_HTTPS') === 'on')
448-
||
449-
(self::getVar('REQUEST_SCHEME') === 'https')
450-
) {
442+
if (strtolower(self::getVar('HTTPS')) === 'on') {
443+
return 'https';
444+
} elseif (self::getVar('HTTP_X_FORWARDED_PROTO') === 'https') {
445+
return 'https';
446+
} elseif (self::getVar('HTTP_FRONT_END_HTTPS') === 'on') {
447+
return 'https';
448+
} elseif (self::getVar('REQUEST_SCHEME') === 'https') {
451449
return 'https';
452450
}
453451

@@ -478,7 +476,8 @@ public function negotiateContentType(array $supported): ?string
478476
/**
479477
* Retrieves the array of uploaded files.
480478
*
481-
* @return array<string, UploadedFile|array<int, UploadedFile>> Key is field name; value is either a single UploadedFile or an array of UploadedFile when multiple were uploaded.
479+
* @return array<string, UploadedFile|array<int, UploadedFile>>
480+
* Key is field name; value is either a single UploadedFile or an array of UploadedFile when multiple were uploaded.
482481
*/
483482
public function getUploadedFiles(): array
484483
{

flight/net/Response.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ protected function processResponseCallbacks(): void
484484
* Downloads a file.
485485
*
486486
* @param string $filePath The path to the file to be downloaded.
487-
* @param string $fileName The name the downloaded file should have. If not provided or is an empty string, the name of the file on disk will be used.
487+
* @param string $fileName The name the downloaded file should have.
488+
* If not provided or is an empty string, the name of the file on disk will be used.
488489
*
489490
* @throws Exception If the file cannot be found.
490491
*

0 commit comments

Comments
 (0)