XmlAuthenticationSuccessResponse   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 12.5 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 97.3%

Importance

Changes 0
Metric Value
dl 9
loc 72
ccs 36
cts 37
cp 0.973
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setUser() 0 8 1
A setProxies() 0 11 2
A setAttributes() 0 17 4
A setProxyGrantingTicket() 0 8 1
A getAuthNode() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: leo108
5
 * Date: 2016/10/23
6
 * Time: 16:01
7
 */
8
9
namespace Leo108\CAS\Responses;
10
11
use Leo108\CAS\Contracts\Responses\AuthenticationSuccessResponse;
12
use SimpleXMLElement;
13
14
class XmlAuthenticationSuccessResponse extends BaseXmlResponse implements AuthenticationSuccessResponse
15
{
16
    /**
17
     * XmlAuthenticationSuccessResponse constructor.
18
     */
19 5
    public function __construct()
20
    {
21 5
        parent::__construct();
22 5
        $this->node->addChild('cas:authenticationSuccess');
23 5
    }
24
25 1
    public function setUser($user)
26
    {
27 1
        $authNode = $this->getAuthNode();
28 1
        $this->removeByXPath($authNode, 'cas:user');
29 1
        $authNode->addChild('cas:user', $user);
30
31 1
        return $this;
32
    }
33
34 1
    public function setProxies($proxies)
35
    {
36 1
        $authNode = $this->getAuthNode();
37 1
        $this->removeByXPath($authNode, 'cas:proxies');
38 1
        $proxiesNode = $authNode->addChild('cas:proxies');
39 1
        foreach ($proxies as $proxy) {
40 1
            $proxiesNode->addChild('cas:proxy', $proxy);
41
        }
42
43 1
        return $this;
44
    }
45
46 2
    public function setAttributes($attributes)
47
    {
48 2
        $authNode = $this->getAuthNode();
49 2
        $this->removeByXPath($authNode, 'cas:attributes');
50 2
        $attributesNode = $authNode->addChild('cas:attributes');
51 2
        foreach ($attributes as $key => $value) {
52 2
            $valueArr = (array) $value;
53 2
            foreach($valueArr as $v){
54 2
                $str = $this->stringify($v);
55 2
                if (is_string($str)) {
56 2
                    $attributesNode->addChild('cas:'.$key, $str);
57
                }
58
            }
59
        }
60
61 2
        return $this;
62
    }
63
64 1
    public function setProxyGrantingTicket($ticket)
65
    {
66 1
        $authNode = $this->getAuthNode();
67 1
        $this->removeByXPath($authNode, 'cas:proxyGrantingTicket');
68 1
        $authNode->addChild('cas:proxyGrantingTicket', $ticket);
69
70 1
        return $this;
71
    }
72
73
    /**
74
     * @return SimpleXMLElement
75
     */
76 5 View Code Duplication
    protected function getAuthNode()
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...
77
    {
78 5
        $authNodes = $this->node->xpath('cas:authenticationSuccess');
79 5
        if (count($authNodes) < 1) {
80
            return $this->node->addChild('cas:authenticationSuccess');
81
        }
82
83 5
        return $authNodes[0];
84
    }
85
}
86