TranslationLoaderManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTranslationsForTranslationLoaders() 0 13 1
A load() 0 11 3
1
<?php
2
3
namespace mindtwo\LaravelMultilingual\Services;
4
5
use Illuminate\Translation\FileLoader;
6
7
class TranslationLoaderManager extends FileLoader
8
{
9
    /**
10
     * Load the messages for the given locale.
11
     *
12
     * @param string $locale
13
     * @param string $group
14
     * @param string $namespace
15
     *
16
     * @return array
17
     */
18
    public function load($locale, $group, $namespace = null): array
19
    {
20
        $fileTranslations = parent::load($locale, $group, $namespace);
21
22
        if (! is_null($namespace) && '*' !== $namespace) {
23
            return $fileTranslations;
24
        }
25
26
        $loaderTranslations = $this->getTranslationsForTranslationLoaders($locale, $group, $namespace);
27
28
        return array_replace_recursive($fileTranslations, $loaderTranslations);
29
    }
30
31
    /**
32
     * @param string      $locale
33
     * @param string      $group
34
     * @param string|null $namespace
35
     *
36
     * @return array
37
     */
38
    protected function getTranslationsForTranslationLoaders(
39
        string $locale,
40
        string $group,
41
        string $namespace = null
42
    ): array {
43
        return collect(config('laravel-multilingual.translation_loaders'))
44
            ->map(function (string $className) {
45
                return app($className);
46
            })
47
            ->mapWithKeys(function (TranslationLoader $translationLoader) use ($locale, $group, $namespace) {
48
                return $translationLoader->loadTranslations($locale, $group, $namespace);
0 ignored issues
show
Unused Code introduced by
The call to mindtwo\LaravelMultiling...der::loadTranslations() has too many arguments starting with $namespace. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
                return $translationLoader->/** @scrutinizer ignore-call */ loadTranslations($locale, $group, $namespace);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
49
            })
50
            ->toArray();
51
    }
52
}
53