Passed
Push — master ( 210521...1582b6 )
by Maurício
14:48 queued 06:32
created

libraries/classes/Triggers/Trigger.php (5 issues)

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 string $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
            Assert::string($timing);
35 24
            $timing = Timing::tryFrom($timing);
0 ignored issues
show
It seems like $timing can also be of type null; however, parameter $value of PhpMyAdmin\Triggers\Timing::tryFrom() 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

35
            $timing = Timing::tryFrom(/** @scrutinizer ignore-type */ $timing);
Loading history...
36 24
            Assert::notNull($timing);
37 24
            Assert::string($event);
38 24
            $event = Event::tryFrom($event);
0 ignored issues
show
It seems like $event can also be of type null; however, parameter $value of PhpMyAdmin\Triggers\Event::tryFrom() 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

38
            $event = Event::tryFrom(/** @scrutinizer ignore-type */ $event);
Loading history...
39 24
            Assert::notNull($event);
40 24
            Assert::string($table);
41 24
            $table = TableName::tryFromValue($table);
42 24
            Assert::notNull($table);
43 24
            Assert::string($statement);
44 24
            Assert::string($definer);
45
46 24
            return new self($name, $timing, $event, $table, $statement, $definer);
0 ignored issues
show
It seems like $event can also be of type null; however, parameter $event of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept PhpMyAdmin\Triggers\Event, 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

46
            return new self($name, $timing, /** @scrutinizer ignore-type */ $event, $table, $statement, $definer);
Loading history...
It seems like $table can also be of type null; however, parameter $table of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept PhpMyAdmin\Dbal\TableName, 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

46
            return new self($name, $timing, $event, /** @scrutinizer ignore-type */ $table, $statement, $definer);
Loading history...
It seems like $timing can also be of type null; however, parameter $timing of PhpMyAdmin\Triggers\Trigger::__construct() does only seem to accept PhpMyAdmin\Triggers\Timing, 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

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