translator()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 9.6111
cc 5
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
use Illuminate\Contracts\Foundation\Application;
6
7
if (!\function_exists('translator')) {
8
    /**
9
     * @param string|null $translator
10
     * @param string|null $key
11
     *
12
     * @throws Exception
13
     *
14
     * @return Application|mixed|string|null
15
     */
16
    function translator(string $translator = null, string $key = null)
17
    {
18
        if ($translator !== null && $key === null) {
19
            throw new Exception(
20
                'Please set translation key'
21
            );
22
        }
23
24
        if ($translator === null && $key === null) {
25
            throw new Exception(
26
                'Please provide translator and translation key'
27
            );
28
        }
29
30
        return app($translator)->get($key);
31
    }
32
}
33