Passed
Branch v2 (d444af)
by Pieter
02:38
created

ApplicationInfoRetriever   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A retrieveAll() 0 10 2
A __construct() 0 6 1
A retrieve() 0 11 2
1
<?php
2
3
namespace W2w\Lib\Apie\Retrievers;
4
5
use W2w\Lib\Apie\ApiResources\ApplicationInfo;
6
use W2w\Lib\Apie\Exceptions\ResourceNotFoundException;
7
use W2w\Lib\Apie\SearchFilters\SearchFilterRequest;
8
9
/**
10
 * Retrieves instances of api resource ApplicationInfo. This is always one record with id 'name'.
11
 */
12
class ApplicationInfoRetriever implements ApiResourceRetrieverInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $appName;
18
19
    /**
20
     * @var string
21
     */
22
    private $environment;
23
24
    /**
25
     * @var string
26
     */
27
    private $hash;
28
29
    /**
30
     * @var bool
31
     */
32
    private $debug;
33
34
    /**
35
     * @param string $appName
36
     * @param string $environment
37
     * @param string $hash
38
     * @param bool $debug
39
     */
40
    public function __construct(string $appName, string $environment, string $hash, bool $debug)
41
    {
42
        $this->appName = $appName;
43
        $this->environment = $environment;
44
        $this->hash = $hash;
45
        $this->debug = $debug;
46
    }
47
48
    /**
49
     * @param string $resourceClass
50
     * @param string $id
51
     * @param array $context
52
     * @return ApplicationInfo
53
     */
54
    public function retrieve(string $resourceClass, $id, array $context)
55
    {
56
        if ($id !== 'name') {
57
            throw new ResourceNotFoundException($id);
58
        }
59
60
        return new ApplicationInfo(
61
            $this->appName,
62
            $this->environment,
63
            $this->hash,
64
            $this->debug
65
        );
66
    }
67
68
    /**
69
     * @param string $resourceClass
70
     * @param array $context
71
     * @param SearchFilterRequest $searchFilterRequest
72
     * @return ApplicationInfo[]
73
     */
74
    public function retrieveAll(
75
        string $resourceClass,
76
        array $context,
77
        SearchFilterRequest $searchFilterRequest
78
    ): iterable {
79
        if ($searchFilterRequest->getPageIndex() > 0) {
80
            return [];
81
        }
82
83
        return [$this->retrieve($resourceClass, 'name', $context)];
84
    }
85
}
86