Completed
Push — master ( 76efee...bc6801 )
by Avtandil
13s
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 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 1
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
     * @param  string $locale
19
     * @return Illuminate\Contracts\Routing\UrlGenerator|string
20
     */
21
    function lang_url($path = null, $parameters = [], $secure = null, $locale = null)
22
    {
23 2
        if (is_null($path)) {
24 1
            return app(Illuminate\Contracts\Routing\UrlGenerator::class);
25
        }
26
27 1
        $multilang = app('multilang');
28
29 1
        $path = $multilang->getUrl($path, $locale);
30
31 1
        return url($path, $parameters, $secure);
32
    }
33
}
34
35
if (! function_exists('lang_redirect')) {
36
    /**
37
     * Get an instance of the redirector.
38
     *
39
     * @param  string|null $to
40
     * @param  int $status
41
     * @param  array $headers
42
     * @param  bool $secure
43
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
44
     */
45
    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...
46
    {
47 2
        if (is_null($to)) {
48 1
            return app('redirect');
49
        }
50
51 1
        $multilang = app('multilang');
52
53 1
        $to = $multilang->getUrl($to);
54
55 1
        return app('redirect')->to($to, $status, $headers, $secure);
56
    }
57
}
58
59
if (! function_exists('lang_route')) {
60
    /**
61
     * Get route by name
62
     *
63
     * @param string $name
64
     * @param array $parameters
65
     * @param bool $absolute
66
     * @return string
67
     */
68
    function lang_route($name, array $parameters = [], $absolute = true)
69
    {
70 1
        $multilang = app('multilang');
71
72 1
        $name = $multilang->getRoute($name);
73
74 1
        return app('url')->route($name, $parameters, $absolute);
75
    }
76
}
77
78
if (! function_exists('t')) {
79
    /**
80
     * Get translated text
81
     *
82
     * @param  string $text
83
     * @param  array $replace
84
     * @return string
85
     */
86
    function t($text, array $replace = [])
87
    {
88 1
        $text = app('multilang')->get($text, $replace);
89
90 1
        return $text;
91
    }
92
}
93