CachePutInterceptor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 25
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A invoke() 17 17 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 *
13
 * This software consists of voluntary contributions made by many individuals
14
 * and is licensed under the MIT license.
15
 *
16
 * Copyright (c) 2015-2020 Yuuki Takezawa
17
 *
18
 */
19
20
namespace Ytake\LaravelAspect\Interceptor;
21
22
use Ray\Aop\MethodInvocation;
23
24
use function is_array;
25
26
/**
27
 * Class AroundCachePutAspect
28
 */
29 View Code Duplication
class CachePutInterceptor extends AbstractCache
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
{
31
    /**
32
     * @param MethodInvocation|\Ray\Aop\ReflectiveMethodInvocation $invocation
33
     *
34
     * @return mixed
35
     */
36
    public function invoke(MethodInvocation $invocation)
37
    {
38
        $annotation = $invocation->getMethod()->getAnnotation($this->annotation) ?? new $this->annotation([]);
39
        $keys = $this->generateCacheName($annotation->cacheName, $invocation);
40
        if (!is_array($annotation->key)) {
41
            $annotation->key = [$annotation->key];
42
        }
43
        $keys = $this->detectCacheKeys($invocation, $annotation, $keys);
44
        // detect use cache driver
45
        $cache = $this->detectCacheRepository($annotation);
46
        $result = $invocation->proceed();
47
        if ($result !== null) {
48
            $cache->put($this->recursiveImplode($this->join, $keys), $result, $annotation->lifetime);
49
        }
50
51
        return $result;
52
    }
53
}
54