Passed
Branch main (db7939)
by Michael
04:16 queued 10s
created

HelpsLoopFunctions::ignoredPropertyNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\LoopFunctions\Traits;
6
7
trait HelpsLoopFunctions
8
{
9
    /**
10
     * Assign the value to the property or rescue.
11
     *
12
     * @param int|string $key
13
     * @param mixed      $value
14
     * @param mixed|null $rescue
15
     *
16
     * @return void
17
     */
18 15
    private function assignValue(int|string $key, mixed $value, mixed $rescue = null): void
19
    {
20 15
        if ($this->canAssignValue($key)) {
21 15
            rescue(
22 15
                fn () => $this->{$key} = $value,
23
                $rescue,
24 15
                config('loop-functions.log') ?? false
25
            );
26
        }
27
    }
28
29
    /**
30
     * @return array
31
     */
32 15
    private function ignoredPropertyNames(): array
33
    {
34 15
        return config('loop-functions.ignore_keys', ['id', 'password']);
35
    }
36
37
    /**
38
     * @param int|string $key
39
     *
40
     * @return bool
41
     */
42 15
    private function canAssignValue(int|string $key): bool
43
    {
44 15
        return is_string($key) && property_exists($this, $key);
45
    }
46
}
47