Completed
Push — 3 ( e98770...9f5757 )
by Damian
21s
created

CacheProxy::setOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
require_once 'Zend/Cache.php';
4
5
/**
6
 * A decorator for a Zend_Cache_Backend cache service that mutates cache keys
7
 * dynamically depending on versioned state
8
 */
9
class CacheProxy extends Zend_Cache_Core {
10
    /**
11
     * @var Zend_Cache_Backend|Zend_Cache_Backend_ExtendedInterface
12
     */
13
    protected $cache;
14
15
    /**
16
     * CacheProxy constructor.
17
     * @param Zend_Cache_Core $cache
18
     */
19
    public function __construct(Zend_Cache_Core $cache) {
20
        $this->cache = $cache;
0 ignored issues
show
Documentation Bug introduced by
It seems like $cache of type object<Zend_Cache_Core> is incompatible with the declared type object<Zend_Cache_Backen...kend_ExtendedInterface> of property $cache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
21
22
        parent::__construct();
23
    }
24
25
    public function setDirectives($directives) {
26
        $this->cache->setDirectives($directives);
27
    }
28
29
    public function setConfig(Zend_Config $config) {
30
        return $this->cache->setConfig($config);
31
    }
32
33
    public function setBackend(Zend_Cache_Backend $backendObject) {
34
        return $this->cache->setBackend($backendObject);
35
    }
36
37
    public function getBackend() {
38
        return $this->cache->getBackend();
39
    }
40
41
    public function setOption($name, $value) {
42
        $this->cache->setOption($name, $value);
0 ignored issues
show
Bug introduced by
The method setOption does only exist in Zend_Cache_Backend, but not in Zend_Cache_Backend_ExtendedInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
43
    }
44
45
    public function getOption($name) {
46
        return $this->cache->getOption($name);
47
    }
48
49
    public function setLifetime($newLifetime) {
50
        return $this->cache->setLifetime($newLifetime);
51
    }
52
53
    public function getIds() {
54
        return $this->cache->getIds();
0 ignored issues
show
Bug introduced by
The method getIds does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
55
    }
56
57
    public function getTags() {
58
        return $this->cache->getTags();
0 ignored issues
show
Bug introduced by
The method getTags does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
59
    }
60
61
    public function getIdsMatchingTags($tags = array()) {
62
        return $this->cache->getIdsMatchingTags($tags);
0 ignored issues
show
Bug introduced by
The method getIdsMatchingTags does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
63
    }
64
65
    public function getIdsNotMatchingTags($tags = array()) {
66
        return $this->cache->getIdsNotMatchingTags($tags);
0 ignored issues
show
Bug introduced by
The method getIdsNotMatchingTags does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
67
    }
68
69
    public function getIdsMatchingAnyTags($tags = array()) {
70
        return $this->cache->getIdsMatchingAnyTags($tags);
0 ignored issues
show
Bug introduced by
The method getIdsMatchingAnyTags does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
71
    }
72
73
    public function getFillingPercentage() {
74
        return $this->cache->getFillingPercentage();
0 ignored issues
show
Bug introduced by
The method getFillingPercentage does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
75
    }
76
77
    public function getMetadatas($id) {
78
        return $this->cache->getMetadatas($this->getKeyID($id));
0 ignored issues
show
Bug introduced by
The method getMetadatas does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
79
    }
80
81
    public function touch($id, $extraLifetime) {
82
        return $this->cache->touch($this->getKeyID($id), $extraLifetime);
0 ignored issues
show
Bug introduced by
The method touch does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
83
    }
84
85
    public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false) {
86
        return $this->cache->load($this->getKeyID($id), $doNotTestCacheValidity, $doNotUnserialize);
0 ignored issues
show
Unused Code introduced by
The call to Zend_Cache_Backend_ExtendedInterface::load() has too many arguments starting with $doNotUnserialize.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug introduced by
The method load does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
87
    }
88
89
    public function test($id) {
90
        return $this->cache->test($this->getKeyID($id));
0 ignored issues
show
Bug introduced by
The method test does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
91
    }
92
93
    public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8) {
94
        return $this->cache->save(
0 ignored issues
show
Bug introduced by
The method save does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
95
            $data,
96
            $this->getKeyID($id),
97
            $tags,
98
            $specificLifetime,
99
            $priority
0 ignored issues
show
Unused Code introduced by
The call to Zend_Cache_Backend_ExtendedInterface::save() has too many arguments starting with $priority.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
100
        );
101
    }
102
103
    public function remove($id) {
104
        return $this->cache->remove($this->getKeyID($id));
0 ignored issues
show
Bug introduced by
The method remove does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
105
    }
106
107
    public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) {
108
        return $this->cache->clean($mode, $tags);
0 ignored issues
show
Bug introduced by
The method clean does only exist in Zend_Cache_Backend_ExtendedInterface, but not in Zend_Cache_Backend.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
109
    }
110
111
    /**
112
     * Creates a dynamic key based on versioned state
113
     * @param string $key
114
     * @return string
115
     */
116
    protected function getKeyID($key) {
117
        $state = Versioned::get_reading_mode();
118
        if ($state) {
119
            return $key . '_' . md5($state);
120
        }
121
        return $key;
122
    }
123
}