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 — 3.x ( 56b2ee...e477bf )
by Jindřich
01:49
created

Skautis::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Skautis;
5
6
use Skautis\Wsdl\WebService;
7
use Skautis\Wsdl\WebServiceAlias;
8
use Skautis\Wsdl\WebServiceAliasNotFoundException;
9
use Skautis\Wsdl\WebServiceInterface;
10
use Skautis\Wsdl\WebServiceName;
11
use Skautis\Wsdl\WebServiceNotFoundException;
12
use Skautis\Wsdl\WsdlException;
13
use Skautis\Wsdl\WsdlManager;
14
15
/**
16
 * Třída pro práci se skautISem
17
 *
18
 * Sdružuje všechny komponenty a zprostředkovává jejich komunikaci.
19
 *
20
 * @author Hána František <[email protected]>
21
 *
22
 * @property-read WebServiceInterface $ApplicationManagement
23
 * @property-read WebServiceInterface $ContentManagement
24
 * @property-read WebServiceInterface $Evaluation
25
 * @property-read WebServiceInterface $Events
26
 * @property-read WebServiceInterface $Exports
27
 * @property-read WebServiceInterface $GoogleApps
28
 * @property-read WebServiceInterface $Journal
29
 * @property-read WebServiceInterface $Material
30
 * @property-read WebServiceInterface $Message
31
 * @property-read WebServiceInterface $OrganizationUnit
32
 * @property-read WebServiceInterface $Power
33
 * @property-read WebServiceInterface $Reports
34
 * @property-read WebServiceInterface $Summary
35
 * @property-read WebServiceInterface $Task
36
 * @property-read WebServiceInterface $Telephony
37
 * @property-read WebServiceInterface $UserManagement
38
 * @property-read WebServiceInterface $Vivant
39
 * @property-read WebServiceInterface $Welcome
40
 */
41
class Skautis
42
{
43
44
    use HelperTrait;
45
46
    /**
47
     * @var WsdlManager
48
     */
49
    private $wsdlManager;
50
51
    /**
52
     * @var User
53
     */
54
    private $user;
55
56
    /**
57
     * Zaznamy o provedenych dotazech na Skautis
58
     * Pokud je null, query logging je vypnuto
59
     *
60
     * @var SkautisQuery[]|null
61
     */
62
    private $log;
63
64
65
    /**
66
     * @param WsdlManager $wsdlManager
67
     * @param User $user
68
     */
69 3
    public function __construct(WsdlManager $wsdlManager, User $user)
70
    {
71 3
        $this->wsdlManager = $wsdlManager;
72 3
        $this->user = $user;
73 3
    }
74
75
    public function getWsdlManager(): WsdlManager
76
    {
77
        return $this->wsdlManager;
78
    }
79
80
    public function getConfig(): Config
81
    {
82
        return $this->wsdlManager->getConfig();
83
    }
84
85
    public function getUser(): User
86
    {
87
        return $this->user;
88
    }
89
90
    /**
91
     * Získá objekt webové služby
92
     */
93 2
    public function getWebService(string $name): WebServiceInterface
94
    {
95 2
        $realServiceName = $this->getWebServiceName($name);
96 2
        return $this->wsdlManager->getWebService($realServiceName, $this->user->getLoginId());
97
    }
98
99
    /**
100
     * Trocha magie pro snadnější přístup k webovým službám.
101
     */
102 2
    public function __get(string $name): WebServiceInterface
103
    {
104 2
        return $this->getWebService($name);
105
    }
106
107
  /**
108
   * NEPOUŽÍVAT - vždy vyhodí výjimku
109
   *
110
   * @deprecated
111
   * @param string $name
112
   * @param mixed $value
113
   */
114 1
    public function __set(
115
      $name,
116
      $value
117
    ) {
118 1
      throw new DynamicPropertiesDisabledException();
119
    }
120
121
122
  /**
123
     * Vrací URL na přihlášení
124
     */
125
    public function getLoginUrl(string $backlink = ''): string
126
    {
127
        $query = [];
128
        $query['appid'] = $this->getConfig()->getAppId();
129
        if (!empty($backlink)) {
130
            $query['ReturnUrl'] = $backlink;
131
        }
132
        return $this->getConfig()->getBaseUrl() . 'Login/?' . http_build_query($query, '', '&');
133
    }
134
135
    /**
136
     * Vrací URL na odhlášení
137
     */
138
    public function getLogoutUrl(): string
139
    {
140
        $query = [];
141
        $query['appid'] = $this->getConfig()->getAppId();
142
        $query['token'] = $this->user->getLoginId();
143
        return $this->getConfig()->getBaseUrl() . 'Login/LogOut.aspx?' . http_build_query($query, '', '&');
144
    }
145
146
    /**
147
     * Vrací URL k registraci
148
     */
149
    public function getRegisterUrl(string $backlink = ''): string
150
    {
151
        $query = [];
152
        $query['appid'] = $this->getConfig()->getAppId();
153
        if (!empty($backlink)) {
154
            $query['ReturnUrl'] = $backlink;
155
        }
156
        return $this->getConfig()->getBaseUrl() . 'Login/Registration.aspx?' . http_build_query($query, '', '&');
157
    }
158
159
    /**
160
     * Hromadné nastavení po přihlášení
161
     */
162
    public function setLoginData(array $data): void
163
    {
164
        $data = Helpers::parseLoginData($data);
165
        $this->getUser()->setLoginData($data[User::ID_LOGIN], $data[User::ID_ROLE], $data[User::ID_UNIT], $data[User::LOGOUT_DATE]);
166
    }
167
168
    /**
169
     * Ověřuje, zda je skautIS odstaven pro údržbu
170
     */
171
    public function isMaintenance(): bool
172
    {
173
        return $this->wsdlManager->isMaintenance();
174
    }
175
176
    /**
177
     * Zapne logování všech SOAP callů
178
     */
179
    public function enableDebugLog(): void
180
    {
181
        if ($this->log !== null) {
182
            // Debug log byl již zapnut dříve.
183
            return;
184
        }
185
186
        $this->log = [];
187
        $logger = function (SkautisQuery $query) {
188
            $this->log[] = $query;
189
        };
190
        $this->wsdlManager->addWebServiceListener(WebService::EVENT_SUCCESS, $logger);
191
        $this->wsdlManager->addWebServiceListener(WebService::EVENT_FAILURE, $logger);
192
    }
193
194
    /**
195
     * Vrací zalogované SOAP cally
196
     */
197
    public function getDebugLog(): array
198
    {
199
        return $this->log ?? [];
200
    }
201
202
  /**
203
   * Vrací celé jméno webové služby
204
   *
205
   * @param string $name jméno nebo alias webové služby
206
   *
207
   * @throws WsdlException
208
   */
209 2
  protected function getWebServiceName(string $name): string
210
  {
211 2
    if (WebServiceName::isValidServiceName($name)) {
212 2
      return $name;
213
    }
214
215
    try {
216 1
      return WebServiceAlias::resolveAlias($name);
217
    }
218
    catch (WebServiceAliasNotFoundException $ex) {
219
      throw new WebServiceNotFoundException($name, 0, $ex);
220
    }
221
  }
222
}
223