CacheData::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Nip\Cache\Cacheable;
5
6
/**
7
 *
8
 */
9
class CacheData extends \ArrayObject
10
{
11
    public const DEFAULT_KEY = '__DEFAULT__';
12
    public static function from($data): CacheData
13
    {
14
        return new self($data);
15
    }
16
17
    /**
18
     * @param $data
19
     * @param $key
20
     * @return $this
21
     */
22
    public function set($data, $key = self::DEFAULT_KEY): static
23
    {
24
        $this[$key] = $data;
25
        return $this;
26
    }
27
28
    /**
29
     * @param $key
30
     * @param $default
31
     * @return mixed|null
32
     */
33
    public function get($key = self::DEFAULT_KEY, $default = null)
34
    {
35
        return $this[$key] ?? $default;
36
    }
37
}