BaseModel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 48
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 4 1
A __set() 0 4 1
A __call() 0 13 3
A __callStatic() 0 4 1
1
<?php
2
3
namespace Codexshaper\WooCommerce\Models;
4
5
class BaseModel
6
{
7
    protected $properties = [];
8
9
    /**
10
     * Get  Inaccessible Property.
11
     *
12
     * @param string $name
13
     *
14
     * @return int|string|array|object|null
15
     */
16
    public function __get($name)
17
    {
18
        return $this->$name;
19
    }
20
21
    /**
22
     * Set Option.
23
     *
24
     * @param string $name
25
     * @param string $value
26
     *
27
     * @return void
28
     */
29
    public function __set($name, $value)
30
    {
31
        $this->properties[$name] = $value;
32
    }
33
34
    public function __call($method, $parameters)
35
    {
36
        if (!method_exists($this, $method)) {
37
            preg_match_all('/((?:^|[A-Z])[a-z]+)/', $method, $partials);
38
            $method = array_shift($partials[0]);
39
            if (!method_exists($this, $method)) {
40
                throw new \Exception('Sorry! you are calling wrong method');
41
            }
42
            array_unshift($parameters, strtolower(implode('_', $partials[0])));
43
        }
44
45
        return $this->$method(...$parameters);
46
    }
47
48
    public static function __callStatic($method, $parameters)
49
    {
50
        return (new static())->$method(...$parameters);
51
    }
52
}
53