Completed
Pull Request — master (#1)
by leo
03:28
created

XmlAuthenticationSuccessResponse   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 69
Duplicated Lines 13.04 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 97.37%

Importance

Changes 0
Metric Value
dl 9
loc 69
ccs 37
cts 38
cp 0.9737
rs 10
c 0
b 0
f 0
wmc 10
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 14 3
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 4
    public function __construct()
20
    {
21 4
        parent::__construct();
22 4
        $this->node->addChild('cas:authenticationSuccess');
23 4
    }
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 1
        }
42
43 1
        return $this;
44
    }
45
46 1
    public function setAttributes($attributes)
47
    {
48 1
        $authNode = $this->getAuthNode();
49 1
        $this->removeByXPath($authNode, 'cas:attributes');
50 1
        $attributesNode = $authNode->addChild('cas:attributes');
51 1
        foreach ($attributes as $key => $value) {
52 1
            $str = $this->stringify($value);
53 1
            if (is_string($str)) {
54 1
                $attributesNode->addChild('cas:'.$key, $str);
55 1
            }
56 1
        }
57
58 1
        return $this;
59
    }
60
61 1
    public function setProxyGrantingTicket($ticket)
62
    {
63 1
        $authNode = $this->getAuthNode();
64 1
        $this->removeByXPath($authNode, 'cas:proxyGrantingTicket');
65 1
        $authNode->addChild('cas:proxyGrantingTicket', $ticket);
66
67 1
        return $this;
68
    }
69
70
    /**
71
     * @return SimpleXMLElement
72
     */
73 4 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...
74
    {
75 4
        $authNodes = $this->node->xpath('cas:authenticationSuccess');
76 4
        if (count($authNodes) < 1) {
77
            return $this->node->addChild('cas:authenticationSuccess');
78
        }
79
80 4
        return $authNodes[0];
81
    }
82
}
83