Completed
Push — master ( 2d40eb...7a12ad )
by Aimeos
13:43
created

Laravel5   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 1 Features 2
Metric Value
wmc 4
c 6
b 1
f 2
lcom 1
cbo 2
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getClientAddress() 0 4 1
A getTarget() 0 6 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package MW
7
 * @subpackage View
8
 */
9
10
11
namespace Aimeos\MW\View\Helper\Request;
12
13
14
/**
15
 * View helper class for retrieving request data.
16
 *
17
 * @package MW
18
 * @subpackage View
19
 */
20
class Laravel5
21
	extends \Aimeos\MW\View\Helper\Request\Standard
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Standard" and comma; 1 found
Loading history...
22
	implements \Aimeos\MW\View\Helper\Request\Iface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
23
{
24
	private $request;
25
26
27
	/**
28
	 * Initializes the request view helper.
29
	 *
30
	 * @param \\Aimeos\MW\View\Iface $view View instance with registered view helpers
31
	 * @param \Illuminate\Http\Request $request Laravel request object
32
	 */
33
	public function __construct( \Aimeos\MW\View\Iface $view, \Illuminate\Http\Request $request )
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
34
	{
35
		$this->request = $request;
36
37
		$factory = new \Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory();
38
		$psr7request = $factory->createRequest( $request );
39
40
		parent::__construct( $view, $psr7request );
41
	}
42
43
44
	/**
45
	 * Returns the client IP address.
46
	 *
47
	 * @return string Client IP address
48
	 */
49
	public function getClientAddress()
50
	{
51
		return $this->request->ip();
52
	}
53
54
55
	/**
56
	 * Returns the current page or route name
57
	 *
58
	 * @return string|null Current page or route name
59
	 */
60
	public function getTarget()
61
	{
62
		if( ( $route = $this->request->route() ) !== null ) {
63
			return $route->getName();
64
		}
65
	}
66
}
67