GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 3c123c...1dd30d )
by Damien
03:16
created

Saml   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Test Coverage

Coverage 98.08%

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 152
ccs 51
cts 52
cp 0.9808
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A loadSaml2Container() 0 7 1
A getResponse() 0 3 1
A getSettings() 0 3 1
A getAuthnRequest() 0 3 1
A getProviderIdentityRecordClass() 0 3 1
A initComponents() 0 9 1
A initEvents() 0 37 1
A createSettingsModel() 0 4 1
A init() 0 7 1
A getSession() 0 3 1
A getResponseAssertion() 0 3 1
A getProviderRecordClass() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dsmrt
5
 * Date: 1/9/18
6
 * Time: 9:11 AM
7
 */
8
9
namespace flipbox\saml\idp;
10
11
use craft\events\RegisterComponentTypesEvent;
12
use craft\events\UserGroupEvent;
13
use craft\models\UserGroup;
14
use craft\services\Fields;
15
use craft\services\UserGroups;
16
use craft\web\UrlManager;
17
use craft\web\User;
18
use flipbox\saml\core\AbstractPlugin;
19
use flipbox\saml\core\containers\Saml2Container;
20
use flipbox\saml\core\models\SettingsInterface;
21
use flipbox\saml\core\records\AbstractProvider;
22
use flipbox\saml\idp\fields\ExternalIdentity;
23
use flipbox\saml\idp\models\Settings;
24
use flipbox\saml\idp\records\ProviderIdentityRecord;
25
use flipbox\saml\idp\records\ProviderRecord;
26
use flipbox\saml\idp\services\messages\AuthnRequest;
27
use flipbox\saml\idp\services\messages\Response;
28
use flipbox\saml\idp\services\messages\ResponseAssertion;
29
use flipbox\saml\idp\services\Provider;
30
use flipbox\saml\idp\services\ProviderIdentity;
31
use flipbox\saml\idp\services\Session;
32
use SAML2\Compat\AbstractContainer;
33
use yii\base\Event;
34
35
class Saml extends AbstractPlugin
36
{
37
38 38
    public function init()
39
    {
40 38
        parent::init();
41
42 38
        $this->initCore();
43 38
        $this->initComponents();
44 38
        $this->initEvents();
45 38
    }
46
47 38
    public function initComponents()
48
    {
49 38
        $this->setComponents([
50 38
            'authnRequest' => AuthnRequest::class,
51
            'provider' => Provider::class,
52
            'providerIdentity' => ProviderIdentity::class,
53
            'response' => Response::class,
54
            'responseAssertion' => ResponseAssertion::class,
55
            'session' => Session::class,
56
        ]);
57 38
    }
58
59
    /**
60
     * Init events
61
     */
62 38
    public function initEvents()
63
    {
64
        /**
65
         * After login
66
         */
67 38
        Event::on(
68 38
            User::class,
69 38
            User::EVENT_AFTER_LOGIN,
70
            [
71 38
                $this->getResponse(),
72 38
                'createAndSendFromSession',
73
            ]
74
        );
75
76
        /**
77
         * CP routes
78
         */
79 38
        Event::on(
80 38
            UrlManager::class,
81 38
            UrlManager::EVENT_REGISTER_CP_URL_RULES,
82 38
            [self::class, 'onRegisterCpUrlRules']
83
        );
84
85
        /**
86
         * Clean Frontend Endpoints
87
         */
88 38
        Event::on(
89 38
            UrlManager::class,
90 38
            UrlManager::EVENT_REGISTER_SITE_URL_RULES,
91 38
            [static::class, 'onRegisterSiteUrlRules']
92
        );
93
94 38
        Event::on(
95 38
            Fields::class,
96 38
            Fields::EVENT_REGISTER_FIELD_TYPES,
97 19
            function (RegisterComponentTypesEvent $event) {
98
                $event->types[] = ExternalIdentity::class;
99 38
            }
100
        );
101 38
    }
102
103
    /**
104
     * @return Settings
105
     */
106 16
    public function getSettings(): SettingsInterface
107
    {
108 16
        return parent::getSettings();
109
    }
110
111
    /**
112
     * @inheritdoc
113
     */
114 18
    public function createSettingsModel()
115
    {
116 18
        return new Settings([
117 18
            'myType' => SettingsInterface::IDP,
118
        ]);
119
    }
120
121
    /**
122
     * Components
123
     */
124
125
    /**
126
     * @return AuthnRequest
127
     */
128 4
    public function getAuthnRequest()
129
    {
130 4
        return $this->get('authnRequest');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('authnRequest') also could return the type mixed which is incompatible with the documented return type flipbox\saml\idp\services\messages\AuthnRequest.
Loading history...
131
    }
132
133
    /**
134
     * @return Response
135
     */
136 38
    public function getResponse()
137
    {
138 38
        return $this->get('response');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('response') also could return the type mixed which is incompatible with the documented return type flipbox\saml\idp\services\messages\Response.
Loading history...
139
    }
140
141
    /**
142
     * @return ResponseAssertion
143
     */
144 4
    public function getResponseAssertion()
145
    {
146 4
        return $this->get('responseAssertion');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('responseAssertion') also could return the type mixed which is incompatible with the documented return type flipbox\saml\idp\service...sages\ResponseAssertion.
Loading history...
147
    }
148
149
    /**
150
     * @return Session
151
     */
152 10
    public function getSession()
153
    {
154 10
        return $this->get('session');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('session') also could return the type mixed which is incompatible with the documented return type flipbox\saml\idp\services\Session.
Loading history...
155
    }
156
157
    /**
158
     * Util Methods
159
     */
160
161
    /**
162
     * @return string
163
     */
164 10
    public function getProviderRecordClass()
165
    {
166 10
        return ProviderRecord::class;
167
    }
168
169
    /**
170
     * @return string
171
     */
172 2
    public function getProviderIdentityRecordClass()
173
    {
174 2
        return ProviderIdentityRecord::class;
175
    }
176
177
    /**
178
     * @return Saml2Container
179
     */
180 4
    public function loadSaml2Container(): AbstractContainer
181
    {
182 4
        $container = new Saml2Container($this);
183
184 4
        \SAML2\Compat\ContainerSingleton::setContainer($container);
185
186 4
        return $container;
187
    }
188
}
189