Completed
Push — master ( 5118b9...50529d )
by Aitor Riba
01:45
created

Builder::checkRoute()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 2
1
<?php
2
3
namespace Aitor24\Laralang;
4
5
use Aitor24\Laralang\Builder\ApertiumTrans;
6
use Aitor24\Laralang\Builder\GoogleTrans;
7
use Aitor24\Laralang\Builder\MymemoryTrans;
8
use Aitor24\Laralang\Models\DB_Translation;
9
use URL;
10
11
class Builder
12
{
13
    /**
14
     * Get the trnaslation.
15
     *
16
     * @param string $string
17
     *
18
     * @return object
19
     */
20
    public static function trans($string)
21
    {
22
        $translator = config('laralang.default.translator');
23
        if (!in_array(config('laralang.default.translator'), ['apertium', 'mymemory', 'google'])) {
24
            return "<font style='color:red;'>Laralang doesn't support $translator translator. Check config</font>";
25
        } else {
26
            if (config('laralang.default.translator') == 'mymemory') {
27
                return new MymemoryTrans($string);
28
            } elseif (config('laralang.default.translator') == 'apertium') {
29
                return new ApertiumTrans($string);
30
            } elseif (config('laralang.default.translator') == 'google') {
31
                return new GoogleTrans($string);
32
            }
33
        }
34
    }
35
36
    /**
37
     * Get the languages that translations has been translated.
38
     *
39
     * @return array
40
     */
41 View Code Duplication
    public static function toLanguages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $locales = [];
44
        $translations = DB_Translation::distinct()->select('to_lang')->get();
45
        foreach ($translations as $object) {
46
            array_push($locales, $object->to_lang);
47
        }
48
49
        return $locales;
50
    }
51
52
    /**
53
     * Get the languages from translations has been translated.
54
     *
55
     * @return array
56
     */
57 View Code Duplication
    public static function fromLanguages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $locales = [];
60
        $translations = DB_Translation::distinct()->select('from_lang')->get();
61
        foreach ($translations as $object) {
62
            array_push($locales, $object->from_lang);
63
        }
64
65
        return $locales;
66
    }
67
68
    /**
69
     * Get all the available languages.
70
     *
71
     * @return array
72
     */
73
    public static function allLanguages()
74
    {
75
        return [
76
            'en' => 'English',
77
            'es' => 'Spanish',
78
            'ca' => 'Catalan',
79
            'pt' => 'Portuguese',
80
            'zh' => 'Chinese',
81
            'ja' => 'Japanese',
82
            'de' => 'German',
83
            'fr' => 'French',
84
            'eu' => 'Basque',
85
            'ru' => 'Russian',
86
        ];
87
    }
88
89
90
    /**
91
     * Return secure_asset method or asset method depending on config https
92
     *
93
     * @param string $asset
94
     *
95
     * @return string
96
     */
97
    public static function checkAsset($asset)
98
    {
99
        if (config('laralang.default.https')) {
100
            return secure_asset($asset);
101
        }
102
        return asset($asset);
103
    }
104
105
    /**
106
     * Return secure_url method or url method depending on config https
107
     *
108
     * @param string $url
109
     *
110
     * @return string
111
     */
112
    public static function checkUrl($url)
113
    {
114
        if (config('laralang.default.https')) {
115
            return secure_url($url);
116
        }
117
        return url($url);
118
    }
119
120
    /**
121
     * Return secure_url method or url method depending on config https
122
     *
123
     * @param string $url
0 ignored issues
show
Bug introduced by
There is no parameter named $url. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
124
     *
125
     * @return string
126
     */
127
    public static function checkRoute($routeName, $routeArgs = NULL)
128
    {
129
        if (config('laralang.default.https')) {
130
            if (isset($routeArgs)) {
131
                return secure_url(URL::route($routeName,$routeArgs,false));
132
            }
133
            return secure_url(URL::route($routeName,[],false));
134
        }
135
        if (isset($routeArgs)) {
136
            return route($routeName, $routeArgs);
137
        }
138
        return route($routeName);
139
    }
140
}
141