YConnectResourceOwner::getResource()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
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
}