Completed
Branch master (d9b923)
by Damien
01:32
created

ExternalIdentity::getStaticHtml()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1852

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 3
cts 9
cp 0.3333
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 3.1852
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 */
6
7
namespace flipbox\saml\sp\fields;
8
9
use craft\base\ElementInterface;
10
use craft\helpers\UrlHelper;
11
use flipbox\saml\core\fields\AbstractExternalIdentity;
12
use flipbox\saml\core\SamlPluginInterface;
13
use flipbox\saml\sp\Saml;
14
use yii\db\Query;
15
16
class ExternalIdentity extends AbstractExternalIdentity
17
{
18
19
    /**
20
     * @inheritdoc
21
     */
22
    protected function getSamlPlugin(): SamlPluginInterface
23
    {
24
        return Saml::getInstance();
25
    }
26
27
    /**
28
     * @param $value
29
     * @param ElementInterface $element
30
     * @return string
31
     * @throws \Twig_Error_Loader
32
     * @throws \yii\base\Exception
33
     */
34 3
    public function getStaticHtml($value, ElementInterface $element): string
35
    {
36 3
        if (! ($value instanceof Query)) {
37 3
            return '';
38
        }
39
40
        return \Craft::$app->getView()->renderTemplate(
41
            'saml-sp/_cp/fields/external-id',
42
            [
43
                'identities' => $value,
44
                'element'    => $element,
45
                'baseProviderUrl' => UrlHelper::cpUrl(
46
                    'saml-sp/metadata'
47
                ),
48
            ]
49
        );
50
    }
51
}
52