Completed
Push — master ( 294889...618737 )
by Vojtěch
02:15
created

Environment::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\Application\Environment;
6
7
class Environment
8
{
9
	/** @var \SixtyEightPublishers\Application\Environment\IProfileStorage  */
10
	private $profileStorage;
11
12
	/**
13
	 * @param \SixtyEightPublishers\Application\Environment\ProfileContainer            $profileContainer
14
	 * @param \SixtyEightPublishers\Application\Environment\IEnvironmentDetector        $detector
15
	 * @param \SixtyEightPublishers\Application\Environment\IProfileStorage             $profileStorage
16
	 */
17
	public function __construct(ProfileContainer $profileContainer, IEnvironmentDetector $detector, IProfileStorage $profileStorage)
18
	{
19
		$profile = $detector->detect($profileContainer);
20
		$this->profileStorage = $profileStorage;
21
		$this->profileStorage->setProfile($profile instanceof Profile ? $profile : $profileContainer->getDefaultProfile());
0 ignored issues
show
Bug introduced by
It seems like $profile instanceof \Six...er->getDefaultProfile() can be null; however, setProfile() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
22
	}
23
24
	/**
25
	 * @return \SixtyEightPublishers\Application\Environment\ActiveProfile
26
	 */
27
	public function getProfile()
28
	{
29
		return $this->profileStorage->getProfile();
30
	}
31
}
32