Completed
Pull Request — 1.x (#53)
by Akihito
04:27
created

HttpCacheInterceptor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the BEAR.QueryRepository package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\QueryRepository;
8
9
use BEAR\RepositoryModule\Annotation\AbstractCacheControl;
10
use Doctrine\Common\Annotations\Reader;
11
use Ray\Aop\MethodInterceptor;
12
use Ray\Aop\MethodInvocation;
13
14
class HttpCacheInterceptor implements MethodInterceptor
15
{
16
    /**
17
     * @var Reader
18
     */
19
    private $reader;
20
21 4
    public function __construct(
22
        Reader $annotationReader
23
    ) {
24 4
        $this->reader = $annotationReader;
25 4
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 4
    public function invoke(MethodInvocation $invocation)
31
    {
32 4
        $cacheControl = $this->reader->getClassAnnotation($invocation->getMethod()->getDeclaringClass(), AbstractCacheControl::class);
33 4
        $ro = $invocation->proceed();
34 4
        if ($ro->code === 200 && $cacheControl instanceof AbstractCacheControl) {
0 ignored issues
show
Bug introduced by
The class BEAR\RepositoryModule\An...on\AbstractCacheControl does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
35 4
            $ro->headers['Cache-Control'] = (string) $cacheControl;
36
        }
37
38 4
        return $ro;
39
    }
40
}
41