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 ( 542ce3...d805b4 )
by Jindřich
03:23 queued 02:10
created

WsdlManager   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 67.74%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 5
dl 0
loc 109
ccs 21
cts 31
cp 0.6774
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getWebService() 0 12 2
A createWebService() 0 13 3
A getWebServiceUrl() 0 8 2
A isMaintenance() 0 5 2
A addWebServiceListener() 0 7 1
A getConfig() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Skautis\Wsdl;
5
6
use Skautis\EventDispatcher\EventDispatcherInterface;
7
use Skautis\Config;
8
use Skautis\User;
9
10
/**
11
 * Třída pro správu webových služeb SkautISu
12
 */
13
class WsdlManager
14
{
15
16
    /**
17
     * @var WebServiceFactoryInterface
18
     */
19
    protected $webServiceFactory;
20
21
    /**
22
     * @var Config
23
     */
24
    protected $config;
25
26
    /**
27
     * @var array
28
     */
29
    protected $webServiceListeners = [];
30
31
    /**
32
     * Pole aktivních webových služeb
33
     *
34
     * @var array
35
     */
36
    protected $webServices = [];
37
38
39
    /**
40
     * @param WebServiceFactoryInterface $webServiceFactory továrna pro vytváření objektů webových služeb
41
     * @param Config $config
42
     */
43 4
    public function __construct(WebServiceFactoryInterface $webServiceFactory, Config $config)
44
    {
45 4
        $this->webServiceFactory = $webServiceFactory;
46 4
        $this->config = $config;
47 4
    }
48
49 2
    public function getConfig(): Config
50
    {
51 2
        return $this->config;
52
    }
53
54
    /**
55
     * Získá objekt webové služby
56
     *
57
     * @param string $name celé jméno webové služby
58
     * @param string|null $loginId skautIS login token
59
     */
60 3
    public function getWebService(string $name, ?string $loginId = null): WebServiceInterface
61
    {
62 3
        $key = $loginId . '_' . $name;
63
64 3
        if (!isset($this->webServices[$key])) {
65 2
            $options = $this->config->getSoapOptions();
66 2
            $options[User::ID_LOGIN] = $loginId;
67 2
            $this->webServices[$key] = $this->createWebService($name, $options);
68
        }
69
70 3
        return $this->webServices[$key];
71
    }
72
73
    /**
74
     * Vytváří objekt webové služby
75
     *
76
     * @param string $name jméno webové služby
77
     * @param array $options volby pro SoapClient
78
     */
79 2
    public function createWebService(string $name, array $options = []): WebServiceInterface
80
    {
81 2
        $webService = $this->webServiceFactory->createWebService($this->getWebServiceUrl($name), $options);
82
83 2
        if ($webService instanceof EventDispatcherInterface) {
84
            // Zaregistruj listenery na vytvořeném objektu webové služby, pokud je to podporováno
85 2
            foreach ($this->webServiceListeners as $listener) {
86
                $webService->subscribe($listener['eventName'], $listener['callback']);
87
            }
88
        }
89
90 2
        return $webService;
91
    }
92
93
    /**
94
     * Vrací URL webové služby podle jejího jména
95
     */
96 2
    protected function getWebServiceUrl(string $name): string
97
    {
98 2
        if (!WebServiceName::isValidServiceName($name)) {
99
          throw new WsdlException("Web service '$name' not found.");
100
        }
101
102 2
        return $this->config->getBaseUrl() . 'JunakWebservice/' . rawurlencode($name) . '.asmx?WSDL';
103
    }
104
105
    public function isMaintenance(): bool
106
    {
107
        $headers = get_headers($this->getWebServiceUrl("UserManagement"));
108
        return !$headers || !in_array('HTTP/1.1 200 OK', $headers);
0 ignored issues
show
Bug Best Practice introduced by
The expression $headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
109
    }
110
111
    /**
112
     * Přidá listener na spravovaných vytvářených webových služeb.
113
     */
114
    public function addWebServiceListener(string $eventName, callable $callback): void
115
    {
116
        $this->webServiceListeners[] = [
117
            'eventName' => $eventName,
118
            'callback' => $callback,
119
        ];
120
    }
121
}
122