Code Duplication    Length = 30-30 lines in 2 locations

src/SAML2/AttributeQuery.php 1 location

@@ 58-87 (lines=30) @@
55
56
        $firstAttribute = true;
57
        $attributes = Utils::xpQuery($xml, './saml_assertion:Attribute');
58
        foreach ($attributes as $attribute) {
59
            if (!$attribute->hasAttribute('Name')) {
60
                throw new \Exception('Missing name on <saml:Attribute> element.');
61
            }
62
            $name = $attribute->getAttribute('Name');
63
64
            if ($attribute->hasAttribute('NameFormat')) {
65
                $nameFormat = $attribute->getAttribute('NameFormat');
66
            } else {
67
                $nameFormat = Constants::NAMEFORMAT_UNSPECIFIED;
68
            }
69
70
            if ($firstAttribute) {
71
                $this->nameFormat = $nameFormat;
72
                $firstAttribute = false;
73
            } else {
74
                if ($this->nameFormat !== $nameFormat) {
75
                    $this->nameFormat = Constants::NAMEFORMAT_UNSPECIFIED;
76
                }
77
            }
78
79
            if (!array_key_exists($name, $this->attributes)) {
80
                $this->attributes[$name] = array();
81
            }
82
83
            $values = Utils::xpQuery($attribute, './saml_assertion:AttributeValue');
84
            foreach ($values as $value) {
85
                $this->attributes[$name][] = trim($value->textContent);
86
            }
87
        }
88
    }
89
90
    /**

src/SAML2/Assertion.php 1 location

@@ 479-508 (lines=30) @@
476
    {
477
        $firstAttribute = true;
478
        $attributes = Utils::xpQuery($xml, './saml_assertion:AttributeStatement/saml_assertion:Attribute');
479
        foreach ($attributes as $attribute) {
480
            if (!$attribute->hasAttribute('Name')) {
481
                throw new \Exception('Missing name on <saml:Attribute> element.');
482
            }
483
            $name = $attribute->getAttribute('Name');
484
485
            if ($attribute->hasAttribute('NameFormat')) {
486
                $nameFormat = $attribute->getAttribute('NameFormat');
487
            } else {
488
                $nameFormat = Constants::NAMEFORMAT_UNSPECIFIED;
489
            }
490
491
            if ($firstAttribute) {
492
                $this->nameFormat = $nameFormat;
493
                $firstAttribute = false;
494
            } else {
495
                if ($this->nameFormat !== $nameFormat) {
496
                    $this->nameFormat = Constants::NAMEFORMAT_UNSPECIFIED;
497
                }
498
            }
499
500
            if (!array_key_exists($name, $this->attributes)) {
501
                $this->attributes[$name] = array();
502
            }
503
504
            $values = Utils::xpQuery($attribute, './saml_assertion:AttributeValue');
505
            foreach ($values as $value) {
506
                $this->attributes[$name][] = trim($value->textContent);
507
            }
508
        }
509
    }
510
511
    /**