Completed
Push — master ( 04518a...0908bf )
by
01:37
created

Model::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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
namespace PhpMob\Omise;
13
14
use Doctrine\Common\Inflector\Inflector;
15
16
/**
17
 * @author Ishmael Doss <[email protected]>
18
 */
19
abstract class Model
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $idAttribute = 'id';
25
26
    /**
27
     * @var array
28
     */
29
    protected $store = [];
30
31
    /**
32
     * @param array $store
33
     */
34
    public function __construct(array $store = [])
35
    {
36
        $this->store = $store;
37
    }
38
39
    /**
40
     * @param array $store
41
     *
42
     * @return static
43
     */
44
    public static function make(array $store = [])
45
    {
46
        return new static($store);
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function toArray()
53
    {
54
        return $this->store;
55
    }
56
57
    /**
58
     * @param array $data
59
     */
60
    public function updateStore(array $data)
61
    {
62
        $this->store = $data;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function __toString()
69
    {
70
        $idAttribute = $this->idAttribute;
71
72
        return (string) $this->$idAttribute;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function __get($name)
79
    {
80
        $name = Inflector::tableize($property = $name);
81
82
        if (!array_key_exists($name, $this->store)) {
83
            return property_exists(get_called_class(), $property) ? $this->$property : null;
84
        }
85
86
        return $this->store[$name];
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function __set($name, $value)
93
    {
94
        $this->store[Inflector::tableize($name)] = $value;
95
    }
96
97
    /*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...
98
    {
99
        // TODO:
100
    }*/
101
}
102