Passed
Push — master ( 3949e5...920751 )
by Maurício
08:08
created

libraries/classes/Triggers/Trigger.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Triggers;
6
7
use PhpMyAdmin\Dbal\TableName;
8
use Webmozart\Assert\Assert;
9
use Webmozart\Assert\InvalidArgumentException;
10
11
final class Trigger
12
{
13 24
    public function __construct(
14
        public readonly TriggerName $name,
15
        public readonly Timing $timing,
16
        public readonly Event $event,
17
        public readonly TableName $table,
18
        public readonly string $statement,
19
        public readonly string $definer,
20
    ) {
21 24
    }
22
23
    /** @param mixed[] $trigger */
24 36
    public static function tryFromArray(array $trigger): self|null
25
    {
26
        try {
27 36
            $name = $trigger['Trigger'] ?? $trigger['TRIGGER_NAME'] ?? null;
28 36
            $timing = $trigger['Timing'] ?? $trigger['ACTION_TIMING'] ?? null;
29 36
            $event = $trigger['Event'] ?? $trigger['EVENT_MANIPULATION'] ?? null;
30 36
            $table = $trigger['Table'] ?? $trigger['EVENT_OBJECT_TABLE'] ?? null;
31 36
            $statement = $trigger['Statement'] ?? $trigger['ACTION_STATEMENT'] ?? null;
32 36
            $definer = $trigger['Definer'] ?? $trigger['DEFINER'] ?? null;
33 36
            Assert::string($name);
34 24
            $name = TriggerName::tryFromValue($name);
35 24
            Assert::notNull($name);
36 24
            Assert::string($timing);
37 24
            $timing = Timing::tryFrom($timing);
38 24
            Assert::notNull($timing);
39 24
            Assert::string($event);
40 24
            $event = Event::tryFrom($event);
41 24
            Assert::notNull($event);
42 24
            Assert::string($table);
43 24
            $table = TableName::tryFromValue($table);
44 24
            Assert::notNull($table);
45 24
            Assert::string($statement);
46 24
            Assert::string($definer);
47
48 24
            return new self($name, $timing, $event, $table, $statement, $definer);
0 ignored issues
show
It seems like $name can also be of type null; however, parameter $name of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept PhpMyAdmin\Triggers\TriggerName, 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

48
            return new self(/** @scrutinizer ignore-type */ $name, $timing, $event, $table, $statement, $definer);
Loading history...
49 12
        } catch (InvalidArgumentException) {
50 12
            return null;
51
        }
52
    }
53
}
54