Passed
Push — master ( f3fe09...4b8aef )
by Aimeos
04:04
created

airoute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2017
6
 * @package laravel
7
 */
8
9
10
if (! function_exists('airoute')) {
11
    /**
12
     * Generate the URL to a named route.
13
     *
14
     * @param  array|string  $name
15
     * @param  mixed  $parameters
16
     * @param  bool  $absolute
17
     * @return string
18
     */
19
    function airoute( $name, $parameters = [], $absolute = true )
20
    {
21
		if( $current = Route::current() )
22
		{
23
			$parameters['site'] = $current->parameter( 'site', Request::get( 'site' ) );
24
			$parameters['locale'] = $current->parameter( 'locale', Request::get( 'locale' ) );
25
			$parameters['currency'] = $current->parameter( 'currency', Request::get( 'currency' ) );
26
		}
27
28
        return app('url')->route( $name, array_filter( $parameters ), $absolute );
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type array; however, parameter $name of Illuminate\Routing\UrlGenerator::route() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        return app('url')->route( /** @scrutinizer ignore-type */ $name, array_filter( $parameters ), $absolute );
Loading history...
29
    }
30
}
31
32
33
if( !function_exists( 'aiconfig' ) )
34
{
35
	/**
36
	 * Returns the configuration setting for the given key
37
	 *
38
	 * @param string $key Configuration key
39
	 * @param mixed $default Default value if the configuration key isn't found
40
	 * @return mixed Configuration value
41
	 */
42
	function aiconfig( $key, $default = null )
43
	{
44
		return app( 'aimeos.config' )->get()->get( $key, $default );
45
	}
46
}
47
48
49
if( !function_exists( 'aitrans' ) )
50
{
51
	/**
52
	 * Translates the given message
53
	 *
54
	 * @param string $singular Message to translate
55
	 * @param array $params List of paramters for replacing the placeholders in that order
56
	 * @param string $domain Translation domain
57
	 * @param string $locale ISO language code, maybe combine with ISO currency code, e.g. "en_US"
58
	 * @return string Translated string
59
	 */
60
	function aitrans( $singular, array $params = array(), $domain = 'client', $locale = null )
61
	{
62
		$i18n = app( 'aimeos.context' )->get()->getI18n( $locale );
63
64
		return vsprintf( $i18n->dt( $domain, $singular ), $params );
65
	}
66
}
67
68
69
if( !function_exists( 'aitransplural' ) )
70
{
71
	/**
72
	 * Translates the given messages based on the number
73
	 *
74
	 * @param string $singular Message to translate
75
	 * @param string $plural Message for plural translations
76
	 * @param integer $number Count of items to chose the correct plural translation
77
	 * @param array $params List of paramters for replacing the placeholders in that order
78
	 * @param string $domain Translation domain
79
	 * @param string $locale ISO language code, maybe combine with ISO currency code, e.g. "en_US"
80
	 * @return string Translated string
81
	 */
82
	function aitransplural( $singular, $plural, $number, array $params = array(), $domain = 'client', $locale = null )
83
	{
84
		$i18n = app( 'aimeos.context' )->get()->getI18n( $locale );
85
86
		return vsprintf( $i18n->dn( $domain, $singular, $plural, $number ), $params );
87
	}
88
}
89