AbstractProvider   B
last analyzed

Complexity

Total Complexity 44

Size/Duplication

Total Lines 355
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 16

Importance

Changes 0
Metric Value
wmc 44
lcom 3
cbo 16
dl 0
loc 355
rs 8.8798
c 0
b 0
f 0

32 Methods

Rating   Name   Duplication   Size   Complexity  
getLoginPath() 0 1 ?
getLogoutPath() 0 1 ?
getDefaultSettings() 0 1 ?
A getLoginRequestEndpoint() 0 9 1
A getLoginEndpoint() 0 9 1
A getLogoutRequestEndpoint() 0 9 1
A getLogoutEndpoint() 0 9 1
A loadDefaultValues() 0 11 2
A generateUid() 0 6 2
B beforeSave() 0 28 6
A getEntityId() 0 5 1
A getMetadataModel() 0 11 3
A setMetadataModel() 0 5 1
A isIdentityProvider() 0 4 1
A isServiceProvider() 0 4 1
A getType() 0 4 1
A getLink() 0 6 1
A getKeychain() 0 8 1
A setKeychain() 0 5 1
A setSite() 0 5 1
A getSite() 0 4 1
A getSiteModel() 0 10 2
A setMapping() 0 6 1
A getMapping() 0 9 2
A setMetadataOptions() 0 6 1
A getMetadataOptions() 0 9 2
A setGroupOptions() 0 6 1
A getGroupOptions() 0 9 2
A hasMapping() 0 4 1
A hasGroupOptions() 0 4 1
A hasMetadataOptions() 0 4 1
A hasJsonProperty() 0 12 3

How to fix   Complexity   

Complex Class

Complex classes like AbstractProvider often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AbstractProvider, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace flipbox\saml\core\records;
4
5
use craft\db\ActiveRecord;
6
use craft\helpers\StringHelper;
7
use craft\records\Site;
8
use flipbox\keychain\records\KeyChainRecord;
9
use flipbox\saml\core\helpers\UrlHelper;
10
use flipbox\saml\core\models\GroupOptions;
11
use flipbox\saml\core\models\MetadataOptions;
12
use flipbox\saml\core\records\traits\Ember;
13
use SAML2\DOMDocumentFactory;
14
use SAML2\XML\md\EntityDescriptor;
15
use yii\db\ActiveQuery;
16
use yii\db\ActiveQueryInterface;
17
use flipbox\saml\core\models\AbstractSettings;
18
19
/**
20
 * Class AbstractProvider
21
 * @package flipbox\saml\core\records
22
 */
23
abstract class AbstractProvider extends ActiveRecord implements ProviderInterface
24
{
25
26
    use traits\EntityDescriptor, traits\KeyChain, traits\MapUser, Ember;
27
28
    const METADATA_HASH_ALGORITHM = 'sha256';
29
    const DEFAULT_GROUPS_ATTRIBUTE_NAME = 'groups';
30
31
    protected $metadataModel;
32
    protected $cachedKeychain;
33
34
    /**
35
     * This method helps initiate the login process for a remote provider.
36
     * When using this method, say your craft site is the SP. This method will be helpful
37
     * on the IDP provider record. Going to this login path will
38
     * initiate the login process for this IDP. Returns null when you getLoginPath for the
39
     * local provider (the current craft site).
40
     *
41
     * @return string|null
42
     */
43
    abstract public function getLoginPath();
44
45
    /**
46
     * Similar to getLoginPath(), this method initiates logout with the intended remote
47
     * provider.
48
     *
49
     * @return string|null
50
     */
51
    abstract public function getLogoutPath();
52
53
    abstract protected function getDefaultSettings():AbstractSettings;
54
55
    public function getLoginRequestEndpoint(AbstractSettings $settings = null)
56
    {
57
        return UrlHelper::buildEndpointUrl(
58
            $settings ?? $this->getDefaultSettings(),
59
            UrlHelper::LOGIN_REQUEST_ENDPOINT,
60
            $this,
61
            true
62
        );
63
    }
64
65
    public function getLoginEndpoint(AbstractSettings $settings = null)
66
    {
67
        return UrlHelper::buildEndpointUrl(
68
            $settings ?? $this->getDefaultSettings(),
69
            UrlHelper::LOGIN_ENDPOINT,
70
            $this,
71
            true
72
        );
73
    }
74
75
    public function getLogoutRequestEndpoint(AbstractSettings $settings = null)
76
    {
77
        return UrlHelper::buildEndpointUrl(
78
            $settings ?? $this->getDefaultSettings(),
79
            UrlHelper::LOGOUT_REQUEST_ENDPOINT,
80
            $this,
81
            true
82
        );
83
    }
84
85
    public function getLogoutEndpoint(AbstractSettings $settings = null)
86
    {
87
        return UrlHelper::buildEndpointUrl(
88
            $settings ?? $this->getDefaultSettings(),
89
            UrlHelper::LOGOUT_ENDPOINT,
90
            $this,
91
            true
92
        );
93
    }
94
95
    /**
96
     * @inheritDoc
97
     */
98
    public function loadDefaultValues($skipIfSet = true)
99
    {
100
        parent::loadDefaultValues($skipIfSet);
101
102
        // fix the issue with postgres pulling zero as default
103
        if (!trim($this->uid)) {
104
            $this->generateUid();
105
        }
106
107
        return $this;
108
    }
109
110
    /**
111
     * @throws \Exception
112
     */
113
    public function generateUid()
114
    {
115
        if (!$this->uid) {
116
            $this->uid = StringHelper::UUID();
117
        }
118
    }
119
120
    /**
121
     * @inheritdoc
122
     */
123
    public function beforeSave($insert)
124
    {
125
        if (! $this->entityId) {
0 ignored issues
show
Documentation introduced by
The property entityId does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
126
            $this->entityId = $this->getEntityId();
0 ignored issues
show
Documentation introduced by
The property entityId does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
127
        }
128
129
        if (is_array($this->mapping)) {
0 ignored issues
show
Documentation introduced by
The property mapping does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
130
            $this->mapping = json_encode($this->mapping);
0 ignored issues
show
Documentation introduced by
The property mapping does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property mapping does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
131
        }
132
133
        if ($this->groupOptions instanceof GroupOptions) {
0 ignored issues
show
Documentation introduced by
The property groupOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
134
            $this->groupOptions = json_encode($this->groupOptions);
0 ignored issues
show
Documentation introduced by
The property groupOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property groupOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
135
        }
136
137
        if ($this->metadataOptions instanceof MetadataOptions) {
0 ignored issues
show
Documentation introduced by
The property metadataOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
138
            $this->metadataOptions = json_encode($this->metadataOptions);
0 ignored issues
show
Documentation introduced by
The property metadataOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property metadataOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
139
        }
140
141
        $this->sha256 = hash(static::METADATA_HASH_ALGORITHM, $this->metadata);
0 ignored issues
show
Documentation introduced by
The property sha256 does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The property metadata does not seem to exist. Did you mean metadataModel?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
142
143
        $this->metadata = $this->getMetadataModel()->toXML()->ownerDocument->saveXML();
0 ignored issues
show
Bug introduced by
The property metadata does not seem to exist. Did you mean metadataModel?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
144
145
        if ($this->site instanceof Site) {
0 ignored issues
show
Documentation introduced by
The property site does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
146
            $this->siteId = $this->site->id;
0 ignored issues
show
Documentation introduced by
The property siteId does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property site does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
147
        }
148
149
        return parent::beforeSave($insert);
150
    }
151
152
    /**
153
     * @return string
154
     */
155
    public function getEntityId()
156
    {
157
        $metadata = $this->getMetadataModel();
158
        return $metadata->getEntityID();
159
    }
160
161
    /**
162
     * @return EntityDescriptor
163
     */
164
    public function getMetadataModel()
165
    {
166
167
        if (! $this->metadataModel && $this->metadata) {
0 ignored issues
show
Bug introduced by
The property metadata does not seem to exist. Did you mean metadataModel?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
168
            $this->metadataModel = new EntityDescriptor(
169
                DOMDocumentFactory::fromString($this->metadata)->documentElement
0 ignored issues
show
Bug introduced by
The property metadata does not seem to exist. Did you mean metadataModel?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
170
            );
171
        }
172
173
        return $this->metadataModel;
174
    }
175
176
    /**
177
     * @param EntityDescriptor $descriptor
178
     * @return $this
179
     */
180
    public function setMetadataModel(EntityDescriptor $descriptor)
181
    {
182
        $this->metadataModel = $descriptor;
183
        return $this;
184
    }
185
186
    /**
187
     * @return bool
188
     */
189
    public function isIdentityProvider()
190
    {
191
        return $this->providerType === static::TYPE_IDP;
0 ignored issues
show
Documentation introduced by
The property providerType does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
192
    }
193
194
    /**
195
     * @return bool
196
     */
197
    public function isServiceProvider()
198
    {
199
        return $this->providerType === static::TYPE_SP;
0 ignored issues
show
Documentation introduced by
The property providerType does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
200
    }
201
202
    /**
203
     * @return string
204
     */
205
    public function getType()
206
    {
207
        return $this->providerType;
0 ignored issues
show
Documentation introduced by
The property providerType does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
208
    }
209
210
    /**
211
     * @return ActiveQuery
212
     */
213
    public function getLink()
214
    {
215
        return $this->hasOne(LinkRecord::class, [
216
            'providerId' => 'id',
217
        ]);
218
    }
219
220
    /**
221
     * @return ActiveQuery
222
     */
223
    public function getKeychain()
224
    {
225
        return $this->hasOne(KeyChainRecord::class, [
226
            'id' => 'keyChainId',
227
        ])->viaTable(LinkRecord::tableName(), [
228
            'providerId' => 'id',
229
        ]);
230
    }
231
232
    /**
233
     * @param KeyChainRecord $keyChain
234
     * @return AbstractProvider
235
     */
236
    public function setKeychain(KeyChainRecord $keyChain)
237
    {
238
        $this->populateRelation('keychain', $keyChain);
239
        return $this;
240
    }
241
242
    /**
243
     *
244
     */
245
    public function setSite(Site $site)
246
    {
247
        $this->populateRelation('site', $site);
248
        return $this;
249
    }
250
251
    /**
252
     * Returns the provider's site.
253
     *
254
     * @return ActiveQueryInterface The relational query object.
255
     */
256
    public function getSite(): ActiveQueryInterface
257
    {
258
        return $this->hasOne(Site::class, ['id' => 'siteId']);
259
    }
260
261
    /**
262
     * @return \craft\models\Site|null
263
     */
264
    public function getSiteModel()
265
    {
266
        $site = $this->getSite()->one();
267
268
        if ($site instanceof Site) {
269
            return new \craft\models\Site($site);
0 ignored issues
show
Documentation introduced by
$site is of type object<craft\records\Site>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
270
        }
271
272
        return null;
273
    }
274
275
    /**
276
     * @param array $mapping
277
     * @return $this
278
     */
279
    public function setMapping(array $mapping)
280
    {
281
        $this->mapping = array_values($mapping);
0 ignored issues
show
Documentation introduced by
The property mapping does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
282
283
        return $this;
284
    }
285
286
    /**
287
     * @return array
288
     */
289
    public function getMapping()
290
    {
291
        $mapping = [];
292
        if ($this->hasMapping()) {
293
            $mapping = json_decode($this->mapping, true);
0 ignored issues
show
Documentation introduced by
The property mapping does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
294
        }
295
296
        return $mapping;
297
    }
298
299
    public function setMetadataOptions(MetadataOptions $metadataOptions)
300
    {
301
        $this->metadataOptions = $metadataOptions;
0 ignored issues
show
Documentation introduced by
The property metadataOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
302
303
        return $this;
304
    }
305
306
    public function getMetadataOptions(): MetadataOptions
307
    {
308
        $metadataOptions = new MetadataOptions();
309
        if ($this->hasMetadataOptions()) {
310
            $metadataOptions = MetadataOptions::jsonUnserialize($this->metadataOptions);
0 ignored issues
show
Documentation introduced by
The property metadataOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
311
        }
312
313
        return $metadataOptions;
314
    }
315
316
    /**
317
     * @param GroupOptions $groupOptions
318
     * @return $this
319
     */
320
    public function setGroupOptions(GroupOptions $groupOptions)
321
    {
322
        $this->groupOptions = $groupOptions;
0 ignored issues
show
Documentation introduced by
The property groupOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
323
324
        return $this;
325
    }
326
327
    public function getGroupOptions(): GroupOptions
328
    {
329
        $groupOptions = new GroupOptions();
330
        if ($this->hasGroupOptions()) {
331
            $groupOptions = GroupOptions::jsonUnserialize($this->groupOptions);
0 ignored issues
show
Documentation introduced by
The property groupOptions does not exist on object<flipbox\saml\core...cords\AbstractProvider>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
332
        }
333
334
        return $groupOptions;
335
    }
336
337
    /**
338
     * @return bool
339
     */
340
    public function hasMapping()
341
    {
342
        return $this->hasJsonProperty('mapping');
343
    }
344
345
    /**
346
     * @return bool
347
     */
348
    public function hasGroupOptions(): bool
349
    {
350
        return $this->hasJsonProperty('groupOptions');
351
    }
352
353
    /**
354
     * @return bool
355
     */
356
    public function hasMetadataOptions(): bool
357
    {
358
        return $this->hasJsonProperty('metadataOptions');
359
    }
360
361
    /**
362
     * @param string $property
363
     * @return bool
364
     */
365
    protected function hasJsonProperty(string $property)
366
    {
367
        if (! $this->{$property}) {
368
            return false;
369
        }
370
        try {
371
            json_decode($this->{$property}, true);
372
            return true;
373
        } catch (\Exception $e) {
374
            return false;
375
        }
376
    }
377
}
378