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.
Passed
Push — master ( 4361af...2ec378 )
by Damien
03:49
created

Saml::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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