AbstractAttribute::set()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
nc 1
1
<?php
2
3
namespace Tacone\Bees\Attribute;
4
5
abstract class AbstractAttribute
6
{
7
    protected $object;
8
    protected $storage;
9
    protected $path;
10
    protected $default;
11
12
    protected function __construct($object, &$storage, $path)
13
    {
14
        $this->object = $object;
15
        $this->storage = &$storage;
16
        $this->path = $path;
17
    }
18
19
    abstract protected function get();
20
21
    abstract protected function set($arguments);
22
23
    public function handle($arguments)
24
    {
25
        if (!count($arguments)) {
26
            return array_key_exists($this->path, $this->storage)
27
                ? $this->get()
28
                : $this->default;
29
        }
30
31
        $this->set($arguments);
32
33
        return $this->object;
34
    }
35
36
    /**
37
     * @param \Tacone\Bees\Field\Field $object
38
     * @param $storage
39
     * @param string $path
40
     *
41
     * @return static
42
     */
43
    public static function make($object, &$storage, $path, $default = null)
44
    {
45
        $instance = new static ($object, $storage, $path);
46
        if (func_num_args() > 3) {
47
            $instance->defaults($default);
48
        }
49
50
        return $instance;
51
    }
52
53
    public function defaults($value = null)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        $arguments = func_get_args();
56
        if (!count($arguments)) {
57
            return $this->default;
58
        }
59
60
        $this->default = $arguments[0];
61
62
        return $this->object;
63
    }
64
65
    public function reset()
66
    {
67
        unset($this->storage[$this->path]);
68
69
        return $this->object;
70
    }
71
}
72