Completed
Push — master ( 55fd67...58e48c )
by Aimeos
06:16
created

Laravel5::getTarget()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015
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
		\Aimeos\MW\View\Helper\Request\Standard::__construct( $view, null, null, null, $request->file() );
36
37
		$this->request = $request;
38
	}
39
40
41
	/**
42
	 * Returns the request body.
43
	 *
44
	 * @return string Request body
45
	 */
46
	public function getBody()
47
	{
48
		return $this->request->getContent();
49
	}
50
51
52
	/**
53
	 * Returns the client IP address.
54
	 *
55
	 * @return string Client IP address
56
	 */
57
	public function getClientAddress()
58
	{
59
		return $this->request->ip();
60
	}
61
62
63
	/**
64
	 * Returns the current page or route name
65
	 *
66
	 * @return string|null Current page or route name
67
	 */
68
	public function getTarget()
69
	{
70
		if( ( $route = $this->request->route() ) !== null ) {
71
			return $route->getName();
72
		}
73
	}
74
75
76
	/**
77
	 * Creates a normalized file upload data from the given array.
78
	 *
79
	 * @param \Traversable|array $files File upload data
80
	 * @return array Multi-dimensional list of file objects
81
	 */
82
	protected function createUploadedFiles( $files )
83
	{
84
		$files = array();
85
86
		foreach( $files as $key => $value )
87
		{
88
			if( $value instanceof UploadedFile )
0 ignored issues
show
Bug introduced by
The class Aimeos\MW\View\Helper\Request\UploadedFile does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
89
			{
90
				$files[$key] = new \Aimeos\MW\View\Helper\Request\File\Standard(
91
					$value->getRealPath(),
92
					$value->getClientOriginalName(),
93
					$value->getSize(),
94
					$value->getClientMimeType(),
95
					$value->getError()
96
				);
97
			}
98
			else
99
			{
100
				$files[$key] = $this->createUploadedFiles($value);
101
			}
102
		}
103
104
		return $files;
105
	}
106
}
107