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 ( 48a2e9...c23789 )
by Jindřich
20s queued 11s
created

WsdlManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 96%

Importance

Changes 0
Metric Value
dl 0
loc 98
ccs 24
cts 25
cp 0.96
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getConfig() 0 4 1
A getWebService() 0 12 2
A createWebService() 0 4 1
A getWebServiceUrl() 0 8 2
A isMaintenance() 0 18 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Skaut\Skautis\Wsdl;
5
6
use Skaut\Skautis\Config;
7
use Skaut\Skautis\User;
8
9
/**
10
 * Třída pro správu webových služeb SkautISu
11
 */
12
class WsdlManager
13
{
14
15
    /**
16
     * @var WebServiceFactoryInterface
17
     */
18
    protected $webServiceFactory;
19
20
    /**
21
     * @var Config
22
     */
23
    protected $config;
24
25
    /**
26
     * Pole aktivních webových služeb
27
     *
28
     * @var array<string, WebServiceInterface>
29
     */
30
    protected $webServices = [];
31
32
33
    /**
34
     * @param WebServiceFactoryInterface $webServiceFactory továrna pro vytváření objektů webových služeb
35
     * @param Config $config
36
     */
37 8
    public function __construct(WebServiceFactoryInterface $webServiceFactory, Config $config)
38
    {
39 8
        $this->webServiceFactory = $webServiceFactory;
40 8
        $this->config = $config;
41 8
    }
42
43 2
    public function getConfig(): Config
44
    {
45 2
        return $this->config;
46
    }
47
48
    /**
49
     * Získá objekt webové služby
50
     *
51
     * @param string $name celé jméno webové služby
52
     * @param string|null $loginId skautIS login token
53
     */
54 3
    public function getWebService(string $name, ?string $loginId = null): WebServiceInterface
55
    {
56 3
        $key = $loginId . '_' . $name;
57
58 3
        if (!isset($this->webServices[$key])) {
59 2
            $options = $this->config->getSoapOptions();
60 2
            $options[User::ID_LOGIN] = $loginId;
61 2
            $this->webServices[$key] = $this->createWebService($name, $options);
62
        }
63
64 3
        return $this->webServices[$key];
65
    }
66
67
    /**
68
     * Vytváří objekt webové služby
69
     *
70
     * @param string $name jméno webové služby
71
     * @param array<string, mixed> $options volby pro SoapClient
72
     */
73 2
    public function createWebService(string $name, array $options = []): WebServiceInterface
74
    {
75 2
        return $this->webServiceFactory->createWebService($this->getWebServiceUrl($name), $options);
76
    }
77
78
    /**
79
     * Vrací URL webové služby podle jejího jména
80
     */
81 6
    protected function getWebServiceUrl(string $name): string
82
    {
83 6
        if (!WebServiceName::isValidServiceName($name)) {
84
          throw new WsdlException("Web service '$name' not found.");
85
        }
86
87 6
        return $this->config->getBaseUrl() . 'JunakWebservice/' . rawurlencode($name) . '.asmx?WSDL';
88
    }
89
90 4
    public function isMaintenance(): bool
91
    {
92
        // Transformuje PHP error/warning do Exception
93
        // Funkce get_headers totiž používá warning když má problém aby vysvětlil co se děje
94
        // Pokud například DNS selže tak to hodí PHP warning, který nejde chytat jako exception
95
        set_error_handler(function($errno, $errstr, $errfile, $errline) {
96 1
          throw new MaintenanceErrorException($errstr, $errno, $errfile, $errline);
97 4
        });
98
99
        try {
100 4
          $headers = get_headers($this->getWebServiceUrl('UserManagement'));
101
102 3
          return !$headers || !in_array('HTTP/1.1 200 OK', $headers, true);
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...
103
        }
104
        finally {
105 4
          restore_error_handler();
106
        }
107
    }
108
109
}
110