Completed
Push — master ( 437185...b9fa04 )
by Michael
05:34
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 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 37
ccs 5
cts 8
cp 0.625
rs 10

1 Method

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