HttpCache   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 4
eloc 2
dl 0
loc 24
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isNotModified() 0 3 2
A transfer() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use BEAR\QueryRepository\HttpCacheInterface as DeprecatedHttpCacheInterface;
8
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, BEAR\QueryRepository\HttpCacheInterface. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
10
use function http_response_code;
11
12
/** @psalm-suppress DeprecatedInterface for BC */
13
final class HttpCache implements HttpCacheInterface, DeprecatedHttpCacheInterface
0 ignored issues
show
Deprecated Code introduced by
The interface BEAR\QueryRepository\HttpCacheInterface has been deprecated: Use \BEAR\Sunday\Extension\Transfer\HttpCacheInterface instead ( Ignorable by Annotation )

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

13
final class HttpCache implements HttpCacheInterface, /** @scrutinizer ignore-deprecated */ DeprecatedHttpCacheInterface

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
14 14
{
15
    public function __construct(
16 14
        private readonly ResourceStorageInterface $storage,
17 14
    ) {
18
    }
19
20
    /**
21
     * {@inheritDoc}
22 2
     */
23
    public function isNotModified(array $server): bool
24 2
    {
25
        return isset($server[Header::HTTP_IF_NONE_MATCH]) && $this->storage->hasEtag($server[Header::HTTP_IF_NONE_MATCH]);
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     *
31
     * @return void
32
     */
33
    public function transfer()
34
    {
35
        // @codeCoverageIgnoreStart
36
        http_response_code(304);
37
        // @codeCoverageIgnoreEnd
38
    }
39
}
40