Completed
Push — master ( b4e56c...1b6c56 )
by Avtandil
04:39
created

helpers.php ➔ lang_url()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 12
ccs 4
cts 5
cp 0.8
crap 2.032
rs 9.4285
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('t')) {
59
    /**
60
     * Get translated text
61
     *
62
     * @param  string $text
63
     * @param  array  $replace
64
     * @return string
65
     */
66
    function t($text, array $replace = [])
67
    {
68 1
        $text = app('multilang')->get($text, $replace);
69
70 1
        return $text;
71
    }
72
}
73