Completed
Pull Request — develop (#365)
by
unknown
15:42
created

AbstractAdapter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A init() 0 2 1
A fetch() 0 12 2
queryApi() 0 1 ?
A getProfile() 0 7 1
A getProfileClass() 0 9 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** AbstractProfile.php */
11
namespace Auth\Controller\Plugin\SocialProfiles;
12
13
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
14
use Hybrid_Provider_Adapter;
15
16
abstract class AbstractAdapter extends AbstractPlugin
17
{
18
    
19
    public function __invoke($api)
20
    {
21
        return $this->fetch($api);
22
    }
23
    
24
    /**
25
     * @param mixed $api
26
     * @param Hybrid_Provider_Adapter $hauthAdapter
27
     */
28
    public function init($api, Hybrid_Provider_Adapter $hauthAdapter)
29
    {}
30
    
31
    public function fetch($api)
32
    {
33
        $result  = $this->queryApi($api);
34
        if (!$result) {
35
            return false;
36
        }
37
        
38
        $profile = $this->getProfile();
39
        $profile->setData($result);
40
                
41
        return $profile;
42
    }
43
    
44
    abstract protected function queryApi($api);
45
    
46
    protected function getProfile()
47
    {
48
        $class   = $this->getProfileClass();
49
        $profile = new $class();
50
        
51
        return $profile;
52
    }
53
    
54
    protected function getProfileClass()
55
    {
56
        $class = get_class($this);
57
        $class = explode('\\', $class);
58
        $class = array_pop($class);
59
        $class = '\\Auth\\Entity\\SocialProfiles\\' . $class;
60
        
61
        return $class;
62
    }
63
}
64