Passed
Push — master ( 660cb3...58fd34 )
by Aimeos
03:38
created

Laravel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
6
 * @package Base
7
 * @subpackage View
8
 */
9
10
11
namespace Aimeos\Base\View\Helper\Url;
12
13
14
/**
15
 * View helper class for generating URLs using the Laravel 5 URL builder.
16
 *
17
 * @package Base
18
 * @subpackage View
19
 */
20
class Laravel
21
	extends \Aimeos\Base\View\Helper\Url\Base
22
	implements \Aimeos\Base\View\Helper\Url\Iface
23
{
24
	private $builder;
25
	private $fixed;
26
27
28
	/**
29
	 * Initializes the URL view helper.
30
	 *
31
	 * @param \\Aimeos\Base\View\Iface $view View instance with registered view helpers
0 ignored issues
show
Bug introduced by
The type \Aimeos\Base\View\Iface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
	 * @param \Illuminate\Contracts\Routing\UrlGenerator $builder Laravel URL builder object
33
	 * @param array Associative list of fixed parameters that should be available for all routes
0 ignored issues
show
Bug introduced by
The type Aimeos\Base\View\Helper\Url\Associative was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
	 */
35
	public function __construct( \Aimeos\Base\View\Iface $view, \Illuminate\Contracts\Routing\UrlGenerator $builder, array $fixed )
36
	{
37
		parent::__construct( $view );
38
39
		$this->builder = $builder;
40
		$this->fixed = $fixed;
41
	}
42
43
44
	/**
45
	 * Returns the URL assembled from the given arguments.
46
	 *
47
	 * @param string|null $target Route or page which should be the target of the link (if any)
48
	 * @param string|null $controller Name of the controller which should be part of the link (if any)
49
	 * @param string|null $action Name of the action which should be part of the link (if any)
50
	 * @param array $params Associative list of parameters that should be part of the URL
51
	 * @param array $trailing Trailing URL parts that are not relevant to identify the resource (for pretty URLs)
52
	 * @param array $config Additional configuration parameter per URL
53
	 * @return string Complete URL that can be used in the template
54
	 */
55
	public function transform( string $target = null, string $controller = null, string $action = null,
56
		array $params = [], array $trailing = [], array $config = [] ) : string
57
	{
58
		$values = $this->getValues( $config );
59
		$params = $this->sanitize( $params ) + $this->fixed;
60
		$fragment = ( !empty( $trailing ) ? '#' . implode( '/', $trailing ) : '' );
61
62
		return $this->builder->route( $target, $params, $values['absoluteUri'] ) . $fragment;
63
	}
64
65
66
	/**
67
	 * Returns the sanitized configuration values.
68
	 *
69
	 * @param array $config Associative list of key/value pairs
70
	 * @return array Associative list of sanitized key/value pairs
71
	 */
72
	protected function getValues( array $config ) : array
73
	{
74
		$values = array(
75
			'absoluteUri' => false,
76
		);
77
78
		if( isset( $config['absoluteUri'] ) ) {
79
			$values['absoluteUri'] = (bool) $config['absoluteUri'];
80
		}
81
82
		return $values;
83
	}
84
}
85