Completed
Pull Request — develop (#27)
by Chris
13:09
created

AutoGetterSetterTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 20 4
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Model;
4
5
use Stringy\Stringy as S;
6
7
trait AutoGetterSetterTrait
8
{
9
    public function __call($method, array $arguments)
10
    {
11
        $string = S::create($method);
12
        if (!$string->startsWithAny(['has', 'get', 'is', 'set'])) {
13
            throw new \BadMethodCallException($method);
14
        }
15
16
        $property = lcfirst(preg_replace('/^(has|get|is|set)/', '', $method));
17
        if ($string->startsWithAny(['set'])) {
18
            $this->$property = current($arguments);
19
20
            return $this;
21
        }
22
23
        if (property_exists($this, $property)) {
24
            return $this->$property;
25
        }
26
27
        throw new \BadMethodCallException();
28
    }
29
}
30