BaseModel::__call()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 12
cp 0
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 12
1
<?php
2
3
namespace Codexshaper\WooCommerce\PHP\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 View Code Duplication
    public function __call($method, $parameters)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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