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

Translates   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 9 2
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