Code Duplication    Length = 67-67 lines in 2 locations

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

@@ 30-96 (lines=67) @@
27
 * THE SOFTWARE.
28
 */
29
30
class Memcached extends AbstractEnhancedProvider {
31
32
    public function __construct(
33
        $server = '127.0.0.1',
34
        $port = 11211,
35
        $weight = 0,
36
        $persistent_id = null,
37
        LoggerInterface $logger = null
38
    ) {
39
40
        if ( empty($server) ) {
41
            throw new InvalidCacheArgumentException("Invalid or unspecified memcached server");
42
        }
43
44
        if ( $persistent_id !== null && DataValidation::validateString($persistent_id) === false ) {
45
            throw new InvalidCacheArgumentException("Invalid persistent id");
46
        }
47
48
        $port = DataFilter::filterPort($port, 11211);
49
        $weight = DataFilter::filterInteger($weight);
50
51
        try {
52
53
            $this->driver = new MemcachedDriver([
54
                'persistent_id' => $persistent_id,
55
                'server' => $server,
56
                'port' => $port,
57
                'weight' => $weight
58
            ]);
59
60
            parent::__construct($logger);
61
62
        } catch (Exception $e) {
63
64
            throw new CacheException($e->getMessage());
65
66
        }
67
68
    }
69
70
    public function getInstance() {
71
        return $this->driver->getInstance();
72
    }
73
74
    public function getStats() {
75
76
        $info = $this->driver->stats();
77
78
        $objects = 0;
79
80
        foreach ( $info as $key => $value ) {
81
82
            $objects = max($objects, $value['curr_items']);
83
84
        }
85
86
        return new EnhancedCacheItemPoolStats(
87
            $this->getId(),
88
            $this->driver->getName(),
89
            $this->getState(),
90
            $objects,
91
            $info
92
        );
93
94
    }
95
96
}
97

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

@@ 29-95 (lines=67) @@
26
 * THE SOFTWARE.
27
 */
28
29
class Memcached extends AbstractEnhancedProvider {
30
31
    public function __construct(
32
        $server = '127.0.0.1',
33
        $port = 11211,
34
        $weight = 0,
35
        $persistent_id = null,
36
        LoggerInterface $logger = null
37
    ) {
38
39
        if ( empty($server) ) {
40
            throw new InvalidSimpleCacheArgumentException("Invalid or unspecified memcached server");
41
        }
42
43
        if ( $persistent_id !== null && DataValidation::validateString($persistent_id) === false ) {
44
            throw new InvalidSimpleCacheArgumentException("Invalid persistent id");
45
        }
46
47
        $port = DataFilter::filterPort($port, 11211);
48
        $weight = DataFilter::filterInteger($weight);
49
50
        try {
51
52
            $this->driver = new MemcachedDriver([
53
                'persistent_id' => $persistent_id,
54
                'server' => $server,
55
                'port' => $port,
56
                'weight' => $weight
57
            ]);
58
59
            parent::__construct($logger);
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
        $objects = 0;
78
79
        foreach ( $info as $key => $value ) {
80
81
            $objects = max($objects, $value['curr_items']);
82
83
        }
84
85
        return new EnhancedCacheItemPoolStats(
86
            $this->getId(),
87
            $this->driver->getName(),
88
            $this->getState(),
89
            $objects,
90
            $info
91
        );
92
93
    }
94
95
}
96