FillFromArrayTrait::fill()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.3731

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0
cc 4
nc 5
nop 3
crap 4.3731
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Greenplugin\TelegramBot\Method\Traits;
6
7
use Greenplugin\TelegramBot\Exception\BadArgumentException;
8
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
9
10
/**
11
 * Trait FillFromArrayTrait.
12
 */
13
trait FillFromArrayTrait
14
{
15
    /**
16
     * @param array                       $data
17
     * @param array|null                  $exclude
18
     * @param NameConverterInterface|null $converter
19
     *
20
     * @throws BadArgumentException
21
     */
22 2
    private function fill(array $data, array $exclude = null, NameConverterInterface $converter = null)
0 ignored issues
show
Unused Code introduced by
The parameter $exclude is not used and could be removed. ( Ignorable by Annotation )

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

22
    private function fill(array $data, /** @scrutinizer ignore-unused */ array $exclude = null, NameConverterInterface $converter = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24 2
        foreach ($data as $key => $value) {
25 2
            if ($converter) {
26
                $key = $converter->denormalize($key);
27
            }
28 2
            if (!\property_exists($this, $key)) {
29
                throw new BadArgumentException(\sprintf('Argument %s not found in %s', $key, self::class));
30
            }
31 2
            $this->{$key} = $value;
32
        }
33 2
    }
34
}
35