Passed
Push — master ( c8fc29...ea1130 )
by F
03:55
created

LanguageRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 15
dl 0
loc 113
rs 10
c 1
b 1
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findByLocale() 0 9 2
A model() 0 3 1
A getFieldsSearchable() 0 3 1
A getAllActive() 0 3 1
1
<?php
2
namespace PWWEB\Localisation\Repositories;
3
4
use App\Repositories\BaseRepository;
0 ignored issues
show
Bug introduced by
The type App\Repositories\BaseRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use PWWEB\Localisation\Contracts\Language as LanguageContract;
6
use PWWEB\Localisation\Exceptions\LanguageDoesNotExist;
7
use PWWEB\Localisation\Models\Language;
8
9
/**
10
 * PWWEB\Localisation\Repositories\LanguageRepository LanguageRepository.
11
 *
12
 * The repository for Language.
13
 * Class LanguageRepository
14
 *
15
 * @package   pwweb/localisation
16
 * @author    Frank Pillukeit <[email protected]>
17
 * @author    Richard Browne <[email protected]
18
 * @copyright 2020 pw-websolutions.com
19
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
20
 */
21
class LanguageRepository extends BaseRepository
22
{
23
    /**
24
     * @var array
25
     */
26
    protected $fieldSearchable = [
27
        'name',
28
        'locale',
29
        'abbreviation',
30
        'installed',
31
        'active',
32
        'standard'
33
    ];
34
35
    /**
36
     * Return searchable fields.
37
     *
38
     * @return array
39
     */
40
    public function getFieldsSearchable()
41
    {
42
        return $this->fieldSearchable;
43
    }
44
45
    /**
46
     * Configure the Model.
47
     **/
48
    public function model()
49
    {
50
        return Language::class;
51
    }
52
    //
53
    // /**
54
    //  * Get the current cached languages.
55
    //  *
56
    //  * @param array $params additional parameters for the database query
57
    //  *
58
    //  * @return \Illuminate\Database\Eloquent\Collection collection of languages
59
    //  */
60
    // protected static function get(array $params = []): Collection
61
    // {
62
    //     returrn parent::get($params);
63
    //     // Cached: return app(LocalisationRegistrar::class)->setLanguageClass(static::class)->getLanguages($params);
64
    // }
65
    //
66
    /**
67
     * Retrieve all active languages.
68
     *
69
     * @return \Illuminate\Database\Eloquent\Collection
70
     */
71
    public function getAllActive()
72
    {
73
        return Language::where('active', 1)->get();
74
    }
75
    //
76
    // /**
77
    //  * Find a language by its name.
78
    //  *
79
    //  * @param string $name language name to be used to retrieve the language
80
    //  *
81
    //  * @throws \PWWEB\Localisation\Exceptions\LanguageDoesNotExist
82
    //  *
83
    //  * @return \PWWEB\Localisation\Contracts\Language
84
    //  */
85
    // public static function findByName(string $name): LanguageContract
86
    // {
87
    //     $language = static::getLanguages(['name' => $name])->first();
88
    //
89
    //     if (null === $language) {
90
    //         throw LanguageDoesNotExist::create($name);
91
    //     }
92
    //
93
    //     return $language;
94
    // }
95
    //
96
    // /**
97
    //  * Find a language by its id.
98
    //  *
99
    //  * @param int $id ID to be used to retrieve the language
100
    //  *
101
    //  * @throws \PWWEB\Localisation\Exceptions\LanguageDoesNotExist
102
    //  *
103
    //  * @return \PWWEB\Localisation\Contracts\Language
104
    //  */
105
    // public static function findById(int $id): LanguageContract
106
    // {
107
    //     $language = static::getLanguages(['id' => $id])->first();
108
    //
109
    //     if (null === $language) {
110
    //         throw LanguageDoesNotExist::withId($id);
111
    //     }
112
    //
113
    //     return $language;
114
    // }
115
    //
116
    /**
117
     * Find a language by its locale, e.g. en-gb.
118
     *
119
     * @param string $locale locale to be used to retrieve the language
120
     *
121
     * @throws \PWWEB\Localisation\Exceptions\LanguageDoesNotExist
122
     *
123
     * @return \PWWEB\Localisation\Contracts\Language
124
     */
125
    public function findByLocale(string $locale): LanguageContract
126
    {
127
        $language = Language::where(['locale' => $locale])->first();
128
129
        if (null === $language) {
130
            throw LanguageDoesNotExist::create($locale);
131
        }
132
133
        return $language;
134
    }
135
    //
136
    // /**
137
    //  * Obtain the available locales.
138
    //  *
139
    //  * @param array $params Set of additional params for querying.
140
    //  *
141
    //  * @return array
142
    //  */
143
    // protected static function getLocales(array $params = []): array
144
    // {
145
    //     $locales = [];
146
    //     $languages = self::getLanguages($params);
147
    //
148
    //     foreach ($languages as $language) {
149
    //         $locales[] = $language->locale;
150
    //     }
151
    //
152
    //     return $locales;
153
    // }
154
}
155