Completed
Push — master ( d006f2...210521 )
by Maurício
01:50 queued 29s
created

Trigger::tryFromArray()   A

Complexity

Conditions 2
Paths 14

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 16
nc 14
nop 1
dl 0
loc 19
rs 9.7333
c 1
b 0
f 0
ccs 16
cts 16
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Triggers;
6
7
use Webmozart\Assert\Assert;
8
use Webmozart\Assert\InvalidArgumentException;
9
10
final class Trigger
11
{
12 24
    public function __construct(
13
        public readonly string $name,
14
        public readonly string $timing,
15
        public readonly string $event,
16
        public readonly string $table,
17
        public readonly string $statement,
18
        public readonly string $definer,
19
    ) {
20 24
    }
21
22
    /** @param mixed[] $trigger */
23 36
    public static function tryFromArray(array $trigger): self|null
24
    {
25
        try {
26 36
            $name = $trigger['Trigger'] ?? $trigger['TRIGGER_NAME'] ?? null;
27 36
            $timing = $trigger['Timing'] ?? $trigger['ACTION_TIMING'] ?? null;
28 36
            $event = $trigger['Event'] ?? $trigger['EVENT_MANIPULATION'] ?? null;
29 36
            $table = $trigger['Table'] ?? $trigger['EVENT_OBJECT_TABLE'] ?? null;
30 36
            $statement = $trigger['Statement'] ?? $trigger['ACTION_STATEMENT'] ?? null;
31 36
            $definer = $trigger['Definer'] ?? $trigger['DEFINER'] ?? null;
32 36
            Assert::string($name);
33 24
            Assert::string($timing);
34 24
            Assert::string($event);
35 24
            Assert::string($table);
36 24
            Assert::string($statement);
37 24
            Assert::string($definer);
38
39 24
            return new self($name, $timing, $event, $table, $statement, $definer);
0 ignored issues
show
Bug introduced by
It seems like $table can also be of type null; however, parameter $table of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

39
            return new self($name, $timing, $event, /** @scrutinizer ignore-type */ $table, $statement, $definer);
Loading history...
Bug introduced by
It seems like $name can also be of type null; however, parameter $name of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

39
            return new self(/** @scrutinizer ignore-type */ $name, $timing, $event, $table, $statement, $definer);
Loading history...
Bug introduced by
It seems like $definer can also be of type null; however, parameter $definer of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

39
            return new self($name, $timing, $event, $table, $statement, /** @scrutinizer ignore-type */ $definer);
Loading history...
Bug introduced by
It seems like $timing can also be of type null; however, parameter $timing of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

39
            return new self($name, /** @scrutinizer ignore-type */ $timing, $event, $table, $statement, $definer);
Loading history...
Bug introduced by
It seems like $event can also be of type null; however, parameter $event of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

39
            return new self($name, $timing, /** @scrutinizer ignore-type */ $event, $table, $statement, $definer);
Loading history...
Bug introduced by
It seems like $statement can also be of type null; however, parameter $statement of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

39
            return new self($name, $timing, $event, $table, /** @scrutinizer ignore-type */ $statement, $definer);
Loading history...
40 12
        } catch (InvalidArgumentException) {
41 12
            return null;
42
        }
43
    }
44
}
45