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

CacheDecorator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 67
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A call() 0 23 4
A hashCall() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Skaut\Skautis\Wsdl\Decorator\Cache;
5
6
use Psr\SimpleCache\CacheInterface;
7
use Skaut\Skautis\User;
8
use Skaut\Skautis\Wsdl\Decorator\AbstractDecorator;
9
use Skaut\Skautis\Wsdl\WebServiceInterface;
10
11
class CacheDecorator extends AbstractDecorator
12
{
13
    /**
14
     * @var CacheInterface
15
     */
16
    protected $cache;
17
18
    /**
19
     * @var array<int, string>
20
     */
21
    protected static $checkedLoginIds = [];
22
23
    /**
24
     * @var int
25
     */
26
    private $ttl;
27
28
  /**
29
   * @param WebServiceInterface $webService
30
   * @param CacheInterface $cache
31
   * @param int $ttlSeconds
32
   */
33 2
    public function __construct(
34
      WebServiceInterface $webService,
35
      CacheInterface $cache,
36
      int $ttlSeconds
37
    ) {
38 2
        $this->webService = $webService;
39 2
        $this->cache = $cache;
40 2
        $this->ttl = $ttlSeconds;
41 2
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 2
    public function call(string $functionName, array $arguments = [])
47
    {
48 2
        $callHash = $this->hashCall($functionName, $arguments);
49
50
        // Pozaduj alespon 1 upesny request na server (zadna Exception) - Kontrola prihlaseni
51 2
        if (isset($arguments[User::ID_LOGIN]) && !in_array($arguments[User::ID_LOGIN], static::$checkedLoginIds, true)) {
52 1
            $response = $this->webService->call($functionName, $arguments);
53 1
            $this->cache->set($callHash, $response, $this->ttl);
54 1
            static::$checkedLoginIds[] = $arguments[User::ID_LOGIN];
55
56 1
            return $response;
57
        }
58
59 2
        $cachedResponse = $this->cache->get($callHash, null);
60 2
        if ($cachedResponse !== null) {
61 2
            return $cachedResponse;
62
        }
63
64 1
        $response = $this->webService->call($functionName, $arguments);
65 1
        $this->cache->set($callHash, $response, $this->ttl);
66
67 1
        return $response;
68
    }
69
70
	/**
71
	 * @param array<string, mixed> $arguments
72
	 */
73 2
    protected function hashCall(string $functionName, array $arguments): string
74
    {
75 2
        return $functionName . '?' . http_build_query($arguments);
76
    }
77
}
78