Completed
Push — master ( c48bbf...8a5b09 )
by Michael
04:49
created

WebApplication   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 70
ccs 5
cts 11
cp 0.4545
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A doExecute() 0 12 2
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\Application\AbstractWebApplication;
12
use Joomla\Application\Controller\ControllerResolverInterface;
13
use Joomla\Application\Web\WebClient;
14
use Joomla\Input\Input;
15
use Joomla\Registry\Registry;
16
use Joomla\Router\Router;
17
use Psr\Http\Message\ResponseInterface;
18
19
/**
20
 * A basic web application class for handing HTTP requests.
21
 *
22
 * @since  __DEPLOY_VERSION__
23
 */
24
class WebApplication extends AbstractWebApplication
25
{
26
	/**
27
	 * The application's controller resolver.
28
	 *
29
	 * @var    ControllerResolverInterface
30
	 * @since  __DEPLOY_VERSION__
31
	 */
32
	protected $controllerResolver;
33
34
	/**
35
	 * The application's router.
36
	 *
37
	 * @var    Router
38
	 * @since  __DEPLOY_VERSION__
39
	 */
40
	protected $router;
41
42
	/**
43
	 * Class constructor.
44
	 *
45
	 * @param   ControllerResolverInterface  $controllerResolver  The application's controller resolver
46
	 * @param   Router                       $router              The application's router
47
	 * @param   Input                        $input               An optional argument to provide dependency injection for the application's
48
	 *                                                            input object.
49
	 * @param   Registry                     $config              An optional argument to provide dependency injection for the application's
50
	 *                                                            config object.
51
	 * @param   WebClient                    $client              An optional argument to provide dependency injection for the application's
52
	 *                                                            client object.
53
	 * @param   ResponseInterface            $response            An optional argument to provide dependency injection for the application's
54
	 *                                                            response object.
55
	 *
56
	 * @since   __DEPLOY_VERSION__
57
	 */
58 9
	public function __construct(
59
		ControllerResolverInterface $controllerResolver,
60
		Router $router,
61
		Input $input = null,
62
		Registry $config = null,
63
		WebClient $client = null,
64
		ResponseInterface $response = null
65
	)
66
	{
67 9
		$this->controllerResolver = $controllerResolver;
68 9
		$this->router             = $router;
69
70
		// Call the constructor as late as possible (it runs `initialise`).
71 9
		parent::__construct($input, $config, $client, $response);
72 9
	}
73
74
	/**
75
	 * Method to run the application routines.
76
	 *
77
	 * @return  void
78
	 *
79
	 * @since   __DEPLOY_VERSION__
80
	 */
81
	protected function doExecute(): void
82
	{
83
		$route = $this->router->parseRoute($this->get('uri.route'), $this->input->getMethod());
84
85
		// Add variables to the input if not already set
86
		foreach ($route->getRouteVariables() as $key => $value)
87
		{
88
			$this->input->def($key, $value);
89
		}
90
91
		\call_user_func($this->controllerResolver->resolve($route));
92
	}
93
}
94