Code Duplication    Length = 60-60 lines in 2 locations

src/Comodojo/Cache/Providers/PhpRedis.php 1 location

@@ 28-87 (lines=60) @@
25
 * THE SOFTWARE.
26
 */
27
28
class PhpRedis extends AbstractEnhancedProvider {
29
30
    protected $default_properties = [
31
        "server" => '127.0.0.1',
32
        "port" => 6379,
33
        "timeout" => 0,
34
        "password" => null
35
    ];
36
37
    public function __construct(array $properties = [], LoggerInterface $logger = null) {
38
39
        parent::__construct($properties, $logger);
40
41
        $properties = $this->getProperties();
42
43
        if ( empty($properties->server) ) {
44
            throw new InvalidCacheArgumentException("Invalid or unspecified memcached server");
45
        }
46
47
        $port = DataFilter::filterPort($properties->port, 6379);
48
        $timeout = DataFilter::filterInteger($properties->timeout, 0, PHP_INT_MAX, 0);
49
50
        try {
51
52
            $this->driver = new PhpRedisDriver([
53
                'server' => $properties->server,
54
                'port' => $port,
55
                'timeout' => $timeout,
56
                'password' => $properties->password
57
            ]);
58
59
            $this->test();
60
61
        } catch (Exception $e) {
62
63
            throw new CacheException($e->getMessage());
64
65
        }
66
67
    }
68
69
    public function getInstance() {
70
        return $this->driver->getInstance();
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getStats() {
77
78
        $info = $this->driver->stats();
79
80
        return new EnhancedCacheItemPoolStats(
81
            $this->getId(),
82
            $this->driver->getName(),
83
            $this->getState(),
84
            $info['objects'],
85
            $info['stats']
86
        );
87
88
    }
89
90
}

src/Comodojo/SimpleCache/Providers/PhpRedis.php 1 location

@@ 28-87 (lines=60) @@
25
 * THE SOFTWARE.
26
 */
27
28
class PhpRedis extends AbstractEnhancedProvider {
29
30
    protected $default_properties = [
31
        "server" => '127.0.0.1',
32
        "port" => 6379,
33
        "timeout" => 0,
34
        "password" => null
35
    ];
36
37
    public function __construct(array $properties = [], LoggerInterface $logger = null) {
38
39
        parent::__construct($properties, $logger);
40
41
        $properties = $this->getProperties();
42
43
        if ( empty($properties->server) ) {
44
            throw new InvalidSimpleCacheArgumentException("Invalid or unspecified memcached server");
45
        }
46
47
        $port = DataFilter::filterPort($properties->port, 6379);
48
        $timeout = DataFilter::filterInteger($properties->timeout, 0, PHP_INT_MAX, 0);
49
50
        try {
51
52
            $this->driver = new PhpRedisDriver([
53
                'server' => $properties->server,
54
                'port' => $port,
55
                'timeout' => $timeout,
56
                'password' => $properties->password
57
            ]);
58
59
            $this->test();
60
61
        } catch (Exception $e) {
62
63
            throw new SimpleCacheException($e->getMessage());
64
65
        }
66
67
    }
68
69
    public function getInstance() {
70
        return $this->driver->getInstance();
71
    }
72
73
    public function getStats() {
74
75
        $info = $this->driver->stats();
76
77
        return new EnhancedCacheItemPoolStats(
78
            $this->getId(),
79
            $this->driver->getName(),
80
            $this->getState(),
81
            $info['objects'],
82
            $info['stats']
83
        );
84
85
    }
86
87
}
88