Completed
Push — master ( 8e06a1...b0dbe4 )
by Jaime Pérez
05:41
created

Issuer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 9.38 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B toXML() 6 24 3

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
namespace SAML2\XML\saml;
4
5
use SAML2\Constants;
6
use SAML2\DOMDocumentFactory;
7
8
/**
9
 * Class representing the saml:Issuer element.
10
 *
11
 * @author Jaime Pérez Crespo, UNINETT AS <[email protected]>
12
 * @package simplesamlphp/saml2
13
 */
14
class Issuer extends NameIDType
15
{
16
17
    /**
18
     * The format of this NameIDType.
19
     *
20
     * Defaults to urn:oasis:names:tc:SAML:2.0:nameid-format:entity:
21
     *
22
     * Indicates that the content of the element is the identifier of an entity that provides SAML-based services (such
23
     * as a SAML authority, requester, or responder) or is a participant in SAML profiles (such as a service provider
24
     * supporting the browser SSO profile). Such an identifier can be used in the <Issuer> element to identify the
25
     * issuer of a SAML request, response, or assertion, or within the <NameID> element to make assertions about system
26
     * entities that can issue SAML requests, responses, and assertions. It can also be used in other elements and
27
     * attributes whose purpose is to identify a system entity in various protocol exchanges.
28
     *
29
     * The syntax of such an identifier is a URI of not more than 1024 characters in length. It is RECOMMENDED that a
30
     * system entity use a URL containing its own domain name to identify itself.
31
     *
32
     * @see saml-core-2.0-os
33
     *
34
     * @var string
35
     */
36
    public $Format = Constants::NAMEID_ENTITY;
37
38
    /**
39
     * Set the name of this XML element to "saml:Issuer"
40
     *
41
     * @var string
42
     */
43
    protected $nodeName = 'saml:Issuer';
44
45
46
    /**
47
     * Convert this Issuer to XML.
48
     *
49
     * @param \DOMElement|null $parent The element we should append to.
50
     *
51
     * @return \DOMElement The current Issuer object converted into a \DOMElement.
52
     */
53
    public function toXML(\DOMElement $parent = null)
54
    {
55
        if ($this->Format !== Constants::NAMEID_ENTITY) {
56
            return parent::toXML($parent);
57
        }
58
59
        /*
60
         * From saml-core-2.0-os 8.3.6, when the entity Format is used: "The NameQualifier, SPNameQualifier, and
61
         * SPProvidedID attributes MUST be omitted."
62
         */
63 View Code Duplication
        if ($parent === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
64
            $parent = DOMDocumentFactory::create();
65
            $doc = $parent;
66
        } else {
67
            $doc = $parent->ownerDocument;
68
        }
69
        $element = $doc->createElementNS(Constants::NS_SAML, 'saml:Issuer');
70
        $parent->appendChild($element);
71
72
        $value = $element->ownerDocument->createTextNode($this->value);
73
        $element->appendChild($value);
74
75
        return $element;
76
    }
77
}
78