MemcachedPhpBagOStuff::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Object caching using memcached.
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 * http://www.gnu.org/copyleft/gpl.html
19
 *
20
 * @file
21
 * @ingroup Cache
22
 */
23
24
/**
25
 * A wrapper class for the pure-PHP memcached client, exposing a BagOStuff interface.
26
 *
27
 * @ingroup Cache
28
 */
29
class MemcachedPhpBagOStuff extends MemcachedBagOStuff {
30
	/**
31
	 * Available parameters are:
32
	 *   - servers:             The list of IP:port combinations holding the memcached servers.
33
	 *   - debug:               Whether to set the debug flag in the underlying client.
34
	 *   - persistent:          Whether to use a persistent connection
35
	 *   - compress_threshold:  The minimum size an object must be before it is compressed
36
	 *   - timeout:             The read timeout in microseconds
37
	 *   - connect_timeout:     The connect timeout in seconds
38
	 *
39
	 * @param array $params
40
	 */
41
	function __construct( $params ) {
42
		parent::__construct( $params );
43
		$params = $this->applyDefaultParams( $params );
44
45
		$this->client = new MemcachedClient( $params );
46
		$this->client->set_servers( $params['servers'] );
47
		$this->client->set_debug( $params['debug'] );
48
	}
49
50
	public function setDebug( $debug ) {
51
		$this->client->set_debug( $debug );
0 ignored issues
show
Bug introduced by
The method set_debug does only exist in MemcachedClient, but not in Memcached.

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...
52
	}
53
54
	public function getMulti( array $keys, $flags = 0 ) {
55
		foreach ( $keys as $key ) {
56
			$this->validateKeyEncoding( $key );
57
		}
58
59
		return $this->client->get_multi( $keys );
0 ignored issues
show
Bug introduced by
The method get_multi does only exist in MemcachedClient, but not in Memcached.

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...
60
	}
61
62
	public function incr( $key, $value = 1 ) {
63
		$this->validateKeyEncoding( $key );
64
65
		return $this->client->incr( $key, $value );
0 ignored issues
show
Bug introduced by
The method incr does only exist in MemcachedClient, but not in Memcached.

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...
66
	}
67
68
	public function decr( $key, $value = 1 ) {
69
		$this->validateKeyEncoding( $key );
70
71
		return $this->client->decr( $key, $value );
0 ignored issues
show
Bug introduced by
The method decr does only exist in MemcachedClient, but not in Memcached.

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...
72
	}
73
}
74