Completed
Push — master ( 10f95b...bf15d4 )
by Michael
09:02
created

Router   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 37
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fetchController() 0 22 3
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
 * @since  1.0
21
 */
22
class Router extends RestRouter implements ContainerAwareInterface
23
{
24
	use ContainerAwareTrait;
25
26
	/**
27
	 * Get a controller object for a given name.
28
	 *
29
	 * @param   string  $name  The controller name (excluding prefix) for which to fetch and instance.
30
	 *
31
	 * @return  ControllerInterface
32
	 *
33
	 * @since   1.0
34
	 * @throws  \RuntimeException
35
	 */
36 1
	protected function fetchController($name)
37
	{
38
		// Derive the controller class name.
39 1
		$class = $this->controllerPrefix . ucfirst($name);
40
41
		// If the controller class does not exist panic.
42 1
		if (!class_exists($class))
43
		{
44
			throw new \RuntimeException(sprintf('Unable to locate controller `%s`.', $class), 404);
45
		}
46
47
		// If the controller does not follows the implementation.
48 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...
49
		{
50
			throw new \RuntimeException(
51
				sprintf('Invalid Controller. Controllers must implement Joomla\Controller\ControllerInterface. `%s`.', $class), 500
52
			);
53
		}
54
55
		// Instantiate the controller.
56 1
		return $this->getContainer()->get($class);
57
	}
58
}
59