hasApiResourcePersisterInstance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Apie\ApplicationInfoPlugin\ResourceFactories;
4
5
use Apie\ApplicationInfoPlugin\DataLayers\ApplicationInfoRetriever;
6
use Apie\ApplicationInfoPlugin\Guesser\AppGuesser;
7
use Apie\Core\Exceptions\BadConfigurationException;
8
use Apie\Core\Interfaces\ApiResourceFactoryInterface;
9
use Apie\Core\Interfaces\ApiResourcePersisterInterface;
10
use Apie\Core\Interfaces\ApiResourceRetrieverInterface;
11
12
class ApplicationInfoRetrieverFallbackFactory implements ApiResourceFactoryInterface
13
{
14
    /**
15
     * @var string|null
16
     */
17
    private $appName;
18
19
    /**
20
     * @var string|null
21
     */
22
    private $environment;
23
24
    /**
25
     * @var string|null
26
     */
27
    private $hash;
28
29
    /**
30
     * @var bool|null
31
     */
32
    private $debug;
33
34
    public function __construct(
35
        ?string $appName = null,
36
        ?string $environment = null,
37
        ?string $hash = null,
38
        bool $debug = true
39
    ) {
40
        $this->appName = $appName;
41
        $this->environment = $environment;
42
        $this->hash = $hash;
43
        $this->debug = $debug;
44
    }
45
46
    /**
47
     * Returns true if this factory can create this identifier.
48
     *
49
     * @param string $identifier
50
     * @return bool
51
     */
52
    public function hasApiResourceRetrieverInstance(string $identifier): bool
53
    {
54
        return $identifier === ApplicationInfoRetriever::class;
55
    }
56
57
    /**
58
     * Gets an instance of ApiResourceRetrieverInstance
59
     */
60
    public function getApiResourceRetrieverInstance(string $identifier): ApiResourceRetrieverInterface
61
    {
62
        $appName = $this->appName ?? AppGuesser::determineApp();
63
        $environment = $this->environment ?? AppGuesser::determineEnvironment($this->debug);
0 ignored issues
show
Bug introduced by
It seems like $this->debug can also be of type null; however, parameter $debug of Apie\ApplicationInfoPlug...:determineEnvironment() does only seem to accept boolean, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
        $environment = $this->environment ?? AppGuesser::determineEnvironment(/** @scrutinizer ignore-type */ $this->debug);
Loading history...
64
        $hash = $this->hash ?? AppGuesser::determineHash();
65
        return new ApplicationInfoRetriever($appName, $environment, $hash, $this->debug);
0 ignored issues
show
Bug introduced by
It seems like $this->debug can also be of type null; however, parameter $debug of Apie\ApplicationInfoPlug...etriever::__construct() does only seem to accept boolean, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        return new ApplicationInfoRetriever($appName, $environment, $hash, /** @scrutinizer ignore-type */ $this->debug);
Loading history...
66
    }
67
68
    /**
69
     * Returns true if this factory can create this identifier.
70
     *
71
     * @param string $identifier
72
     * @return bool
73
     */
74
    public function hasApiResourcePersisterInstance(string $identifier): bool
75
    {
76
        return false;
77
    }
78
79
    /**
80
     * Gets an instance of ApiResourceRetrieverInstance
81
     * @param string $identifier
82
     * @return ApiResourcePersisterInterface
83
     */
84
    public function getApiResourcePersisterInstance(string $identifier): ApiResourcePersisterInterface
85
    {
86
        throw new BadConfigurationException('This method is not supposed to be called');
87
    }
88
}
89