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

HttpCacheInterceptor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A invoke() 0 10 3
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