Completed
Push — mysql_improvements ( 2e95ce...dedbef )
by Michael
03:52
created

Router   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 63.64%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 3
c 7
b 0
f 0
lcom 1
cbo 3
dl 0
loc 37
ccs 7
cts 11
cp 0.6364
rs 10
1
<?php
2
/**
3
 * Joomla! Statistics Server
4
 *
5
 * @copyright  Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved.
6
 * @license    http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
7
 */
8
9
namespace Joomla\StatsServer;
10
11
use Joomla\Controller\ControllerInterface;
12
use Joomla\DI\{
13
	ContainerAwareInterface, ContainerAwareTrait
14
};
15
use Joomla\Router\RestRouter;
16
17
/**
18
 * Stats application router
19
 */
20
class Router extends RestRouter implements ContainerAwareInterface
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Router\RestRouter has been deprecated with message: 2.0 Use the base Router class instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
21
{
22
	use ContainerAwareTrait;
23
24
	/**
25
	 * Get a controller object for a given name.
26
	 *
27
	 * @param   string  $name  The controller name (excluding prefix) for which to fetch and instance.
28
	 *
29
	 * @return  ControllerInterface
30
	 *
31
	 * @throws  \RuntimeException
32
	 */
33 1
	protected function fetchController($name)
34
	{
35
		// Derive the controller class name.
36 1
		$class = $this->controllerPrefix . ucfirst($name);
0 ignored issues
show
Deprecated Code introduced by
The property Joomla\Router\Router::$controllerPrefix has been deprecated with message: 2.0 Deprecated without replacement

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
37
38
		// If the controller class does not exist panic.
39 1
		if (!class_exists($class))
40
		{
41
			throw new \RuntimeException(sprintf('Unable to locate controller `%s`.', $class), 404);
42
		}
43
44
		// If the controller does not follows the implementation.
45 1
		if (!is_subclass_of($class, 'Joomla\\Controller\\ControllerInterface'))
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
46
		{
47
			throw new \RuntimeException(
48
				sprintf('Invalid Controller. Controllers must implement Joomla\Controller\ControllerInterface. `%s`.', $class), 500
49
			);
50
		}
51
52
		// Instantiate the controller.
53 1
		return $this->getContainer()->get($class);
54
	}
55
}
56