Failed Conditions
Pull Request — master (#75)
by Malte
03:57
created

Application   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 92%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 10
c 6
b 1
f 0
lcom 0
cbo 1
dl 0
loc 102
ccs 23
cts 25
cp 0.92
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getObject() 0 4 1
A __clone() 0 4 1
A __construct() 0 9 2
A getInstance() 0 10 2
A getTestSuiteFactory() 0 4 1
A replaceObject() 0 12 3
1
<?php
2
/**
3
 * This file is part of the phpunit-mink library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/aik099/phpunit-mink
9
 */
10
11
namespace aik099\PHPUnit;
12
13
14
use aik099\PHPUnit\TestSuite\TestSuiteFactory;
15
16
/**
17
 * Main application class.
18
 *
19
 * @method \Mockery\Expectation shouldReceive(string $name)
20
 */
21
class Application
22
{
23
24
	/**
25
	 * Dependency injection container.
26
	 *
27
	 * @var DIContainer
28
	 */
29
	protected $container;
30
31
	/**
32
	 * Returns instance of strategy manager.
33
	 *
34
	 * @param DIContainer $container Dependency injection container.
35
	 *
36
	 * @return self
37
	 */
38 3
	public static function getInstance(DIContainer $container = null)
39
	{
40 3
		static $instance = null;
41
42 3
		if ( null === $instance ) {
43
			$instance = new static($container);
44
		}
45
46 3
		return $instance;
47
	}
48
49
	/**
50
	 * Prevents direct instantiation.
51
	 *
52
	 * @param DIContainer $container Dependency injection container.
53
	 */
54 19
	public function __construct(DIContainer $container = null)
55
	{
56 19
		if ( !isset($container) ) {
57 19
			$container = new DIContainer();
58 19
		}
59
60 19
		$this->container = $container;
61 19
		$this->container->setApplication($this);
1 ignored issue
show
Unused Code introduced by
The call to the method aik099\PHPUnit\DIContainer::setApplication() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
62 19
	}
63
64
	/**
65
	 * Returns test suite builder.
66
	 *
67
	 * @return TestSuiteFactory
68
	 * @see    BrowserTestCase::suite()
69
	 */
70 19
	public function getTestSuiteFactory()
71 19
	{
72 3
		return $this->getObject('test_suite_factory');
73
	}
74
75
	/**
76
	 * Returns object from the container.
77
	 *
78
	 * @param string $service_id Name of the object in the container.
79
	 *
80
	 * @return \stdClass
81
	 */
82 5
	public function getObject($service_id)
83
	{
84 5
		return $this->container[$service_id];
85
	}
86
87
	/**
88
	 * Replaces object in the container.
89
	 *
90
	 * @param string   $service_id Name of the object in the container.
91
	 * @param callable $callable   The callable that will return the object.
92
	 * @param boolean  $is_factory The callable should be considered as a factory.
93
	 *
94
	 * @return callable Previous service version.
95
	 * @throws \InvalidArgumentException When attempt is made to replace non-existing service.
96
	 */
97 19
	public function replaceObject($service_id, $callable, $is_factory = false)
1 ignored issue
show
introduced by
Type hint "callable" missing for $callable
Loading history...
98
	{
99 2
		if ( !isset($this->container[$service_id]) ) {
100 19
			throw new \InvalidArgumentException('Service "' . $service_id . '" not found');
101
		}
102
103 1
		$backup = $this->container->raw($service_id);
104 19
		unset($this->container[$service_id]);
105 1
		$this->container[$service_id] = $is_factory ? $this->container->factory($callable) : $callable;
106
107 1
		return $backup;
108
	}
109
110
	/**
111
	 * Prevents cloning.
112
	 *
113
	 * @return void
114
	 *
115
	 * @codeCoverageIgnore
116
	 */
117
	private function __clone()
118
	{
119
120
	}
121
122
}
123