MemcachedConnector::getMemcached()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 */
13
14
namespace Ytake\LaravelCouchbase;
15
16
/**
17
 * Class MemcachedConnector.
18
 * for couchbase memcached bucket.
19
 *
20
 * @codeCoverageIgnore
21
 *
22
 * @author Yuuki Takezawa<[email protected]>
23
 */
24
class MemcachedConnector extends \Illuminate\Cache\MemcachedConnector
25
{
26
    /**
27
     * Create a new Memcached connection.
28
     *
29
     * @param  array       $servers
30
     * @param  string|null $connectionId
31
     * @param  array       $options
32
     * @param  array       $credentials
33
     *
34
     * @return \Memcached
35
     *
36
     * @throws \RuntimeException
37
     */
38
    public function connect(
39
        array $servers,
40
        $connectionId = null,
41
        array $options = [],
42
        array $credentials = []
43
    ) {
44
        $memcached = $this->getMemcached($connectionId, $credentials, []);
45
46
        foreach ($servers as $server) {
47
            $memcached->addServer(
48
                $server['host'], intval($server['port']), $server['weight']
49
            );
50
        }
51
52
        return $memcached;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function getMemcached($connectionId, array $credentials, array $options)
59
    {
60
        return $this->createMemcachedInstance($connectionId);
61
    }
62
}
63