Completed
Push — master ( 1223fc...6af157 )
by Damien
05:06
created

ExternalIdentity::getStaticHtml()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 16
cp 0
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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
    public function getStaticHtml($value, ElementInterface $element): string
35
    {
36
        if (! ($value instanceof Query)) {
37
            return '';
38
        }
39
        return \Craft::$app->getView()->renderTemplate(
40
            'saml-sp/_cp/fields/external-id',
41
            [
42
                'identities' => $value,
43
                'element'    => $element,
44
                'baseProviderUrl' => UrlHelper::cpUrl(
45
                    'saml-sp/metadata'
46
                ),
47
            ]
48
        );
49
    }
50
}
51