TranslatableAttributeProvider::translatable()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 3
nc 3
nop 2
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