Completed
Push — master ( 3828e0...4c70fb )
by Aitor Riba
01:44
created

Builder   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 29.85 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 20
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B trans() 0 15 5
A toLanguages() 10 10 2
A fromLanguages() 10 10 2
A allLanguages() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Aitor24\Laralang;
4
5
use Aitor24\Laralang\Builder\ApertiumTrans;
6
use Aitor24\Laralang\Builder\MymemoryTrans;
7
use Aitor24\Laralang\Builder\GoogleTrans;
8
use Aitor24\Laralang\Models\DB_Translation;
9
10
class Builder
11
{
12
    /**
13
     * Get the trnaslation.
14
     *
15
     * @param string $string
16
     *
17
     * @return object
18
     */
19
    public static function trans($string)
20
    {
21
        $translator = config('laralang.default.translator');
22
        if (!in_array(config('laralang.default.translator'), ['apertium', 'mymemory', 'google'])) {
23
            return "<font style='color:red;'>Laralang doesn't support $translator translator. Check config</font>";
24
        } else {
25
            if (config('laralang.default.translator') == 'mymemory') {
26
                return new MymemoryTrans($string);
27
            } elseif (config('laralang.default.translator') == 'apertium') {
28
                return new ApertiumTrans($string);
29
            } elseif (config('laralang.default.translator') == 'google') {
30
                return new GoogleTrans($string);
31
            }
32
        }
33
    }
34
35
    /**
36
     * Get the languages that translations has been translated.
37
     *
38
     * @return array
39
     */
40 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...
41
    {
42
        $locales = [];
43
        $translations = DB_Translation::distinct()->select('to_lang')->get();
44
        foreach ($translations as $object) {
45
            array_push($locales, $object->to_lang);
46
        }
47
48
        return $locales;
49
    }
50
51
    /**
52
     * Get the languages from translations has been translated.
53
     *
54
     * @return array
55
     */
56 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...
57
    {
58
        $locales = [];
59
        $translations = DB_Translation::distinct()->select('from_lang')->get();
60
        foreach ($translations as $object) {
61
            array_push($locales, $object->from_lang);
62
        }
63
64
        return $locales;
65
    }
66
67
    /**
68
     * Get all the available languages.
69
     *
70
     * @return array
71
     */
72
    public static function allLanguages()
73
    {
74
        return ['English' => 'en', 'Spanish' => 'es', 'Catalan' => 'ca', 'Portuguese' => 'pt', 'Chinese' => 'zh', 'Japanese' => 'ja', 'German' => 'de', 'French' => 'fr'];
75
    }
76
}
77