Test Setup Failed
Push — master ( 9006a2...b92186 )
by Php Easy Api
04:10
created

ContainerMethodDocumentResolver::isCacheMethod()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 34
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 14
nc 3
nop 0
dl 0
loc 34
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Container;
4
5
use Resta\Support\Utils;
6
use Resta\Foundation\ApplicationProvider;
7
8
class ContainerMethodDocumentResolver extends ApplicationProvider
9
{
10
    /**
11
     * @var null|object
12
     */
13
    protected $reflection;
14
15
    /**
16
     * @var array
17
     */
18
    protected $class;
19
20
    /**
21
     * ContainerMethodDocumentResolver constructor.
22
     * 
23
     * @param $app
24
     * @param $reflection
25
     * @param array $class
26
     */
27
    public function __construct($app,$reflection,$class=array())
28
    {
29
        parent::__construct($app);
30
31
        $this->reflection = $reflection;
32
        $this->class = $class;
33
34
        // for class method,
35
        // if there is cache in document data, it will be saved in container.
36
        $this->isCacheMethod();
37
    }
38
39
    /**
40
     * detect document cache for class method
41
     *
42
     * @return void|mixed
43
     */
44
    private function isCacheMethod()
45
    {
46
        $cacheData = [];
47
48
        if(!isset($this->class[1]) && !is_object($this->class[0])) return;
49
50
        // if you have information about cache in
51
        // the document section of the method, the cache process is executed.
52
        if($this->reflection->isAvailableMethodDocument($this->class[1],'cache')){
0 ignored issues
show
Bug introduced by
The method isAvailableMethodDocument() does not exist on null. ( Ignorable by Annotation )

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

52
        if($this->reflection->/** @scrutinizer ignore-call */ isAvailableMethodDocument($this->class[1],'cache')){

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
            
54
            //as static we inject the name value into the cache data.
55
            $cacheData = ['cache'=>['name' => Utils::encryptArrayData($this->class)]];
56
57
            //cache data with the help of foreach data are transferred into the cache.
58
            foreach(array_filter(explode(" ",$this->reflection->getDocumentData()),'strlen') as $item){
59
60
                $items = explode("=",$item);
61
62
                $cacheData['cache'][$items[0]] = $items[1];
63
64
                if(in_array('query',$items)){
65
                    $query = get($items[1],null);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $query is correct as get($items[1], null) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
66
                    if(!is_null($query)){
67
                        $cacheData['cache']['name'] = md5(sha1(
68
                            $cacheData['cache']['name'].'_'.$items[1].':'.$query
69
                        ));
70
                    }
71
                }
72
            }
73
        }
74
75
        //we save the data stored in the cacheData variable as methodCache.
76
        $this->app->register('cache','methodCache',$cacheData);
77
        $this->app->register('cache','class',$this->class);
78
    }
79
}