Test Setup Failed
Push — master ( b0c0a2...b5c2a5 )
by Avtandil
05:28 queued 03:14
created

helpers.php ➔ lang_route()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 8
ccs 0
cts 3
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel MultiLang package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
if (!function_exists('lang_url')) {
12
    /**
13
     * Generate a url for the application.
14
     *
15
     * @param  string $path
16
     * @param  mixed  $parameters
17
     * @param  bool   $secure
18
     * @return Illuminate\Contracts\Routing\UrlGenerator|string
19
     */
20
    function lang_url($path = null, $parameters = [], $secure = null)
21
    {
22 1
        if (is_null($path)) {
23
            return app(Illuminate\Contracts\Routing\UrlGenerator::class);
24
        }
25
26 1
        $multilang = app('multilang');
27
28 1
        $path = $multilang->getUrl($path);
29
30 1
        return url($path, $parameters, $secure);
31
    }
32
}
33
34
if (!function_exists('lang_redirect')) {
35
    /**
36
     * Get an instance of the redirector.
37
     *
38
     * @param  string|null $to
39
     * @param  int         $status
40
     * @param  array       $headers
41
     * @param  bool        $secure
42
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
43
     */
44
    function lang_redirect($to = null, $status = 302, $headers = [], $secure = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
    {
46
        if (is_null($to)) {
47
            return app('redirect');
48
        }
49
50
        $multilang = app('multilang');
51
52
        $to = $multilang->getUrl($to);
53
54
        return app('redirect')->to($to, $status, $headers, $secure);
55
    }
56
}
57
58
if (! function_exists('lang_route')) {
59
    /**
60
     * Get route by name
61
     *
62
     * @param string $name
63
     * @param array $parameters
64
     * @param bool $absolute
65
     * @return string
66
     */
67
    function lang_route($name, array $parameters = [], $absolute = true)
68
    {
69
        $multilang = app('multilang');
70
71
        $name = $multilang->getRoute($name);
72
73
        return app('url')->route($name, $parameters, $absolute);
74
    }
75
}
76
77
if (!function_exists('t')) {
78
    /**
79
     * Get translated text
80
     *
81
     * @param  string $text
82
     * @param  array  $replace
83
     * @return string
84
     */
85
    function t($text, array $replace = [])
86
    {
87 1
        $text = app('multilang')->get($text, $replace);
88
89 1
        return $text;
90
    }
91
}
92