Model::toArray()   A
last analyzed

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 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[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
declare(strict_types=1);
13
14
namespace PhpMob\Omise;
15
16
use Doctrine\Common\Inflector\Inflector;
17
18
/**
19
 * @author Ishmael Doss <[email protected]>
20
 */
21
abstract class Model
22
{
23
    /**
24
     * @var string
25
     */
26
    protected $idAttribute = 'id';
27
28
    /**
29
     * @var array
30
     */
31
    protected $store = [];
32
33
    /**
34
     * @param array $store
35
     */
36 55
    public function __construct(array $store = [])
37
    {
38 55
        $this->store = $store;
39 55
    }
40
41
    /**
42
     * @param array $store
43
     *
44
     * @return static
45
     */
46
    public static function make(array $store = [])
47
    {
48
        return new static($store);
49
    }
50
51
    /**
52
     * @return array
53
     */
54 29
    public function toArray()
55
    {
56 29
        return $this->store;
57
    }
58
59
    /**
60
     * @param array $data
61
     */
62 29
    public function updateStore(array $data)
63
    {
64 29
        $this->store = $data;
65 29
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function __toString()
71
    {
72
        $idAttribute = $this->idAttribute;
73
74
        return (string) $this->$idAttribute;
75
    }
76
77 44
    public function __get($name)
78
    {
79 44
        $name = Inflector::tableize($property = $name);
80
81 44
        if (!array_key_exists($name, $this->store)) {
82 18
            return property_exists(get_called_class(), $property) ? $this->$property : null;
83
        }
84
85 42
        return $this->store[$name];
86
    }
87
88 23
    public function __set($name, $value)
89
    {
90 23
        $this->store[Inflector::tableize($name)] = $value;
91 23
    }
92
93
    /*public function convertDateTime($string)
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
94
    {
95
        // TODO:
96
    }*/
97
}
98