Skip to content

Commit 631d491

Browse files
authored
Merge pull request #72 from samsonasik/use-structarmed-on-qa
Use StructArmed on QA
2 parents 057960f + 40bd63b commit 631d491

8 files changed

Lines changed: 35 additions & 9 deletions

File tree

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"psr/http-server-middleware": "^1.0.2"
3333
},
3434
"require-dev": {
35+
"boundwize/structarmed": "^0.18.10",
3536
"laminas/laminas-coding-standard": "^3.1.0",
3637
"mikey179/vfsstream": "^1.6.12",
3738
"phpstan/phpstan": "^2.2.5",

‎src/ErrorHandler.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ErrorHandler implements ErrorHandlerInterface
3434
*/
3535
public function __construct(callable $responseFactory, ?callable $responseGenerator = null)
3636
{
37-
$this->responseFactory = function () use ($responseFactory): ResponseInterface {
37+
$this->responseFactory = static function () use ($responseFactory): ResponseInterface {
3838
return $responseFactory();
3939
};
4040
$this->responseGenerator = $responseGenerator ?: new ErrorResponseGenerator();
@@ -89,7 +89,7 @@ public function createErrorHandler(): callable
8989
/**
9090
* @throws ErrorException if error is not within the error_reporting mask.
9191
*/
92-
return function (int $errno, string $errstr, string $errfile, int $errline): void {
92+
return static function (int $errno, string $errstr, string $errfile, int $errline): void {
9393
if (! (error_reporting() & $errno)) {
9494
// error_reporting does not include this error
9595
return;

‎src/Extra/Processor/RequestProcessor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function process(array $data): array
2828
} else {
2929
$matches = array_filter(
3030
$sensitiveParameters,
31-
fn (string $sensitiveParameter) => str_contains(strtolower($key), $sensitiveParameter)
31+
static fn (string $sensitiveParameter) => str_contains(strtolower($key), $sensitiveParameter)
3232
);
3333

3434
if (! isset($this->sensitiveParameters[ProcessorInterface::ALL]) && count($matches) === 0) {

‎src/Extra/Processor/ServerProcessor.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function process(array $data): array
4949

5050
private function stringToAssociativeArray(string $subject): array
5151
{
52-
return array_reduce(explode('; ', $subject), function (array $result, string $keyValue): array {
52+
return array_reduce(explode('; ', $subject), static function (array $result, string $keyValue): array {
5353
$keyValue = explode('=', $keyValue, 2);
5454
$result[$keyValue[0]] = $keyValue[1] ?? '';
5555

@@ -60,7 +60,7 @@ private function stringToAssociativeArray(string $subject): array
6060
private function associativeArrayToString(array $subject): string
6161
{
6262
$subject = array_map(
63-
fn(string $key, string $value) => sprintf('%s=%s', $key, $value),
63+
static fn(string $key, string $value) => sprintf('%s=%s', $key, $value),
6464
array_keys($subject),
6565
$subject
6666
);

‎src/Extra/Processor/SessionProcessor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SessionProcessor extends AbstractProcessor
1313
public function process(array $data): array
1414
{
1515
return array_map(
16-
fn (iterable $container): array => ArrayUtils::iteratorToArray($container),
16+
static fn (iterable $container): array => ArrayUtils::iteratorToArray($container),
1717
$data
1818
);
1919
}

‎src/Extra/Processor/TraceProcessor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function process(array $data): array
1515
/**
1616
* @param string[] $trace
1717
*/
18-
fn (array $trace): string => sprintf(
18+
static fn (array $trace): string => sprintf(
1919
'%s%s%s:%d',
2020
$trace['class'] ?? $trace['file'] ?? 'unknown',
2121
$trace['type'] ?? '->',

‎src/LogErrorHandler.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343
?LoggerInterface $logger = null,
4444
?ExtraProvider $extraProvider = null,
4545
) {
46-
$this->responseFactory = function () use ($responseFactory): ResponseInterface {
46+
$this->responseFactory = static function () use ($responseFactory): ResponseInterface {
4747
return $responseFactory();
4848
};
4949
$this->responseGenerator = $responseGenerator ?: new ErrorResponseGenerator();
@@ -109,7 +109,7 @@ public function createErrorHandler(): callable
109109
/**
110110
* @throws ErrorException if error is not within the error_reporting mask.
111111
*/
112-
return function (int $errno, string $errstr, string $errfile, int $errline): void {
112+
return static function (int $errno, string $errstr, string $errfile, int $errline): void {
113113
if (! (error_reporting() & $errno)) {
114114
// error_reporting does not include this error
115115
return;

‎structarmed.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Boundwize\StructArmed\Architecture;
6+
use Boundwize\StructArmed\Preset\Preset;
7+
8+
return Architecture::define()
9+
->withPresets(Preset::PSR4(), Preset::CODEQUALITY())
10+
->layer('ReplacementStrategy', 'src/Extra/ReplacementStrategy.php')
11+
->layer('Processor', 'src/Extra/Processor')
12+
->layer('Provider', 'src/Extra/Provider')
13+
->layer('Extra', 'src/Extra', [
14+
'src/Extra/ReplacementStrategy.php',
15+
'src/Extra/Processor',
16+
'src/Extra/Provider',
17+
])
18+
->layer('ErrorHandler', 'src', 'src/Extra')
19+
->ruleset([
20+
'ReplacementStrategy' => [],
21+
'Processor' => ['ReplacementStrategy'],
22+
'Provider' => ['+Processor'],
23+
'Extra' => ['+Provider'],
24+
'ErrorHandler' => ['+Extra'],
25+
]);

0 commit comments

Comments
 (0)