Passed
Push — feature/second-release ( 1bd67c )
by Andrea Marco
16:09 queued 42s
created

Translates::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Cerbero\LaravelEnum\Concerns;
4
5
use Illuminate\Support\Facades\Lang;
6
use ValueError;
7
8
/**
9
 * The trait to translate enum keys.
10
 *
11
 */
12
trait Translates
13
{
14
    /**
15
     * Retrieve the translated key
16
     *
17
     * @param string $name
18
     * @param array $parameters
19
     * @return string
20
     * @throws ValueError
21
     */
22
    public function __call(string $name, array $parameters): string
23
    {
24
        $translation = Lang::get(sprintf('enums.%s.%s.%s', static::class, $this->name, $name), ...$parameters);
0 ignored issues
show
Bug introduced by
$parameters is expanded, but the parameter $replace of Illuminate\Support\Facades\Lang::get() does not expect variable arguments. ( Ignorable by Annotation )

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

24
        $translation = Lang::get(sprintf('enums.%s.%s.%s', static::class, $this->name, $name), /** @scrutinizer ignore-type */ ...$parameters);
Loading history...
25
26
        if ($translation === $name) {
27
            throw new ValueError(sprintf('"%s" is not a valid key for enum "%s"', $name, static::class));
28
        }
29
30
        return $translation;
31
    }
32
}
33