YConnectResourceOwner   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 60.87%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 60
ccs 14
cts 23
cp 0.6087
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 11 2
A getId() 0 4 1
A getName() 0 4 1
A getEmail() 0 4 1
A getAddress() 0 4 1
A toArray() 0 4 1
A getResource() 0 4 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: polidog
5
 * Date: 2016/11/09
6
 */
7
8
namespace Tavii\OAuth2\Client\Provider;
9
10
11
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
12
13
class YConnectResourceOwner implements ResourceOwnerInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $response;
19
20
    /**
21
     * YConnectResourceOwner constructor.
22
     * @param array $response
23
     */
24 4
    public function __construct(array $response = [])
25
    {
26 4
        $this->response = $response;
27 4
    }
28
29 2
    public function __call($name, $arguments)
30
    {
31 2
        $get = substr($name,0, 3);
32 2
        if ($get !== 'get') {
33
            return null;
34
        }
35 2
        $parameter = function($name) {
36 2
            return ltrim(strtolower(preg_replace('/[A-Z]/', '_\0', str_replace("get", "", $name))), '_');
37 2
        };
38 2
        return $this->getResource($parameter($name));
39
    }
40
41
42 2
    public function getId()
43
    {
44 2
        return $this->getResource('user_id');
45
    }
46
47
    public function getName()
48
    {
49
        return $this->getResource('name');
50
    }
51
52
    public function getEmail()
53
    {
54
        return $this->getResource('email');
55
    }
56
57
    public function getAddress()
58
    {
59
        return $this->getResource('address');
60
    }
61
62
    public function toArray()
63
    {
64
        return $this->response;
65
    }
66
67 4
    protected function getResource($name)
68
    {
69 4
        return isset($this->response[$name]) ? $this->response[$name] : null;
70
    }
71
72
}