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 ( 78d2a4...52ff30 )
by Jindřich
14s queued 11s
created

Skautis::getDebugLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 4
    public function __construct(WsdlManager $wsdlManager, User $user)
70
    {
71 4
        $this->wsdlManager = $wsdlManager;
72 4
        $this->user = $user;
73 4
    }
74
75
    public function getWsdlManager(): WsdlManager
76
    {
77
        return $this->wsdlManager;
78
    }
79
80 3
    public function getConfig(): Config
81
    {
82 3
        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
   * @return void
115
   *
116
   * @phpstan-return never
117
   */
118 1
    public function __set(
119
      $name,
120
      $value
121
    ) {
122 1
      throw new DynamicPropertiesDisabledException();
123
    }
124
125
126
  /**
127
     * Vrací URL na přihlášení
128
     */
129 1
    public function getLoginUrl(string $backlink = ''): string
130
    {
131 1
        $query = [];
132 1
        $query['appid'] = $this->getConfig()->getAppId();
133 1
        if (!empty($backlink)) {
134 1
            $query['ReturnUrl'] = $backlink;
135
        }
136 1
        return $this->getConfig()->getBaseUrl() . 'Login/?' . http_build_query($query, '', '&');
137
    }
138
139
    /**
140
     * Vrací URL na odhlášení
141
     */
142 1
    public function getLogoutUrl(): string
143
    {
144 1
        $query = [];
145 1
        $query['appid'] = $this->getConfig()->getAppId();
146 1
        $query['token'] = $this->user->getLoginId();
147 1
        return $this->getConfig()->getBaseUrl() . 'Login/LogOut.aspx?' . http_build_query($query, '', '&');
148
    }
149
150
    /**
151
     * Vrací URL k registraci
152
     */
153 1
    public function getRegisterUrl(string $backlink = ''): string
154
    {
155 1
        $query = [];
156 1
        $query['appid'] = $this->getConfig()->getAppId();
157 1
        if (!empty($backlink)) {
158
            $query['ReturnUrl'] = $backlink;
159
        }
160 1
        return $this->getConfig()->getBaseUrl() . 'Login/Registration.aspx?' . http_build_query($query, '', '&');
161
    }
162
163
    /**
164
     * Hromadné nastavení po přihlášení
165
     *
166
     * @param array<string, mixed> $data
167
     */
168
    public function setLoginData(array $data): void
169
    {
170
        $data = Helpers::parseLoginData($data);
171
        $this->getUser()->setLoginData($data[User::ID_LOGIN], $data[User::ID_ROLE], $data[User::ID_UNIT], $data[User::LOGOUT_DATE]);
172
    }
173
174
    /**
175
     * Ověřuje, zda je skautIS odstaven pro údržbu
176
     */
177
    public function isMaintenance(): bool
178
    {
179
        return $this->wsdlManager->isMaintenance();
180
    }
181
182
    /**
183
     * Zapne logování všech SOAP callů
184
     */
185
    public function enableDebugLog(): void
186
    {
187
        if ($this->log !== null) {
188
            // Debug log byl již zapnut dříve.
189
            return;
190
        }
191
192
        $this->log = [];
193
        $logger = function (SkautisQuery $query): void {
194
            $this->log[] = $query;
195
        };
196
        $this->wsdlManager->addWebServiceListener(WebService::EVENT_SUCCESS, $logger);
197
        $this->wsdlManager->addWebServiceListener(WebService::EVENT_FAILURE, $logger);
198
    }
199
200
    /**
201
     * Vrací zalogované SOAP cally
202
     *
203
     * @return SkautisQuery[]
204
     */
205
    public function getDebugLog(): array
206
    {
207
        return $this->log ?? [];
208
    }
209
210
  /**
211
   * Vrací celé jméno webové služby
212
   *
213
   * @param string $name jméno nebo alias webové služby
214
   *
215
   * @throws WsdlException
216
   */
217 2
  protected function getWebServiceName(string $name): string
218
  {
219 2
    if (WebServiceName::isValidServiceName($name)) {
220 2
      return $name;
221
    }
222
223
    try {
224 1
      return WebServiceAlias::resolveAlias($name);
225
    }
226
    catch (WebServiceAliasNotFoundException $ex) {
227
      throw new WebServiceNotFoundException($name, 0, $ex);
228
    }
229
  }
230
}
231