TranslatableAttributeProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A translatable() 0 17 3
A translatableName() 0 6 1
1
<?php
2
3
namespace ChinLeung\LaravelFakerProviders;
4
5
use Closure;
6
7
class TranslatableAttributeProvider extends Base
8
{
9
    /**
10
     * Execute a closure for every locale of the application.
11
     *
12
     * @param  \Closure  $callable
13
     * @param  array  $locales
14
     * @return array
15
     */
16
    public function translatable(Closure $callable, array $locales = null): array
17
    {
18
        if (! $locales) {
19
            $locales = function_exists('locales')
20
                ? locales()
21
                : config('app.locales', [config('app.locale')]);
22
        }
23
24
        return call_user_func_array(
25
            'array_merge',
26
            array_map(static function ($locale) use ($callable) {
27
                return [
28
                    $locale => call_user_func($callable, $locale),
29
                ];
30
            }, $locales)
31
        );
32
    }
33
34
    /**
35
     * Generate a name for every locale of the application.
36
     *
37
     * @param  array  $locales
38
     * @return array
39
     */
40
    public function translatableName(array $locales = null): array
41
    {
42
        return $this->translatable(function () {
43
            return $this->generator->name;
44
        }, $locales);
45
    }
46
}
47