Passed
Push — master ( 6bb734...c9a16f )
by Oliver
08:15
created

Type::getClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of Mailable.
5
 *
6
 * (c) Oliver Green <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace BoxedCode\Eloquent\Meta\Types;
13
14
use BoxedCode\Eloquent\Meta\Contracts\MetaItem as MetaItemContract;
15
16
abstract class Type
17
{
18
    /**
19
     * MetaItem model instance.
20
     *
21
     * @var \BoxedCode\Eloquent\Meta\Contracts\MetaItem
22
     */
23
    protected $model;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param \BoxedCode\Eloquent\Meta\Contracts\MetaItem|null $model
29
     */
30 57
    public function __construct(MetaItemContract $model = null)
31
    {
32 57
        $this->model = $model;
33 57
    }
34
35
    /**
36
     * Gets the model instance.
37
     *
38
     * @return \BoxedCode\Eloquent\Meta\Contracts\MetaItem|null
39
     */
40 1
    public function getModel()
41
    {
42 1
        return $this->model;
43
    }
44
45
    /**
46
     * Parse & return the meta item value.
47
     *
48
     * @return mixed
49
     */
50 19
    public function get()
51
    {
52 19
        return $this->model->getRawValue();
53
    }
54
55
    /**
56
     * Parse & set the meta item value.
57
     *
58
     * @param mixed $value
59
     */
60 54
    public function set($value)
61
    {
62 54
        $this->model->setRawValue($value);
63 54
    }
64
65
    /**
66
     * Assertain whether we can handle the
67
     * type of variable passed.
68
     *
69
     * @param  mixed  $value
70
     * @return bool
71
     */
72
    abstract public function isType($value);
73
74
    /**
75
     * Get the types class name.
76
     *
77
     * @return string
78
     */
79 54
    public function getClass()
80
    {
81 54
        return get_class($this);
82
    }
83
84
    /**
85
     * Output value to string.
86
     *
87
     * @return string
88
     */
89 1
    public function __toString()
90
    {
91 1
        return serialize($this->get());
92
    }
93
}
94