XPoweredByMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Koded\Framework\Middleware;
4
5
use Psr\Http\Message\{ResponseInterface, ServerRequestInterface};
6
use Psr\Http\Server\{MiddlewareInterface, RequestHandlerInterface};
7
8
class XPoweredByMiddleware implements MiddlewareInterface
9
{
10 2
    public function __construct(private string|null $value = null)
11
    {
12 2
        @header_remove('x-powered-by');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for header_remove(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

12
        /** @scrutinizer ignore-unhandled */ @header_remove('x-powered-by');

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
Are you sure the usage of header_remove('x-powered-by') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
13
    }
14
15 2
    public function process(
16
        ServerRequestInterface $request,
17
        RequestHandlerInterface $handler): ResponseInterface
18
    {
19 2
        $response = $handler->handle($request);
20 2
        if (null === $this->value) {
21 1
            return $response;
22
        }
23 1
        return $response->withHeader('x-powered-by', $this->value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->withHe...ered-by', $this->value) returns the type Psr\Http\Message\MessageInterface which includes types incompatible with the type-hinted return Psr\Http\Message\ResponseInterface.
Loading history...
24
    }
25
}
26