mindtwo /
laravel-multilingual
| 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
|
|||
| 49 | }) |
||
| 50 | ->toArray(); |
||
| 51 | } |
||
| 52 | } |
||
| 53 |
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.