RouteParameterAsPsr7RequestAttribute   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 3
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pheature\Community\Laravel;
6
7
use Illuminate\Contracts\Foundation\Application;
8
use Illuminate\Http\Request;
9
use Psr\Http\Message\ServerRequestInterface;
10
11
final class RouteParameterAsPsr7RequestAttribute
12
{
13
    private Application $app;
14
15 4
    public function __construct(Application $app)
16
    {
17 4
        $this->app = $app;
18 4
    }
19
20 1
    public function __invoke(ServerRequestInterface $psrRequest): ServerRequestInterface
21
    {
22
        /** @var Request $request */
23 1
        $request = $this->app->make('request');
24
        /** @var ?\Illuminate\Routing\Route $route */
25 1
        $route = $request->route();
26 1
        if ($route) {
0 ignored issues
show
introduced by
$route is of type Illuminate\Routing\Route, thus it always evaluated to true.
Loading history...
27 1
            $parameters = $route->parameters();
28
            /**
29
             * @var string $key
30
             * @var mixed $value
31
             */
32 1
            foreach ($parameters as $key => $value) {
33 1
                $psrRequest = $psrRequest->withAttribute($key, $value);
34
            }
35
        }
36 1
        return $psrRequest;
37
    }
38
}
39