Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
InvalidArgumentException
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 forExpectedArrayList
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 forInvalidEventSubscriber
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of php-fast-forward/event-dispatcher.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/event-dispatcher
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\EventDispatcher\Exception;
20
21use Throwable;
22
23/**
24 * Represent invalid arguments detected by the event dispatcher package.
25 */
26 class InvalidArgumentException extends \InvalidArgumentException
27{
28    /**
29     * Prevent direct instantiation outside the named factories.
30     *
31     * @param string $message exception message
32     * @param int $code exception code
33     * @param Throwable|null $previous previous exception
34     */
35    private function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
36    {
37        parent::__construct($message, $code, $previous);
38    }
39
40    /**
41     * Create an exception for an array that was expected to be a list.
42     *
43     * @param array<array-key, mixed> $array array that failed the list assertion
44     *
45     * @return self exception describing the invalid array shape
46     */
47    public static function forExpectedArrayList(array $array): self
48    {
49        return new self(\sprintf('Array must be a list, %s given', json_encode($array)));
50    }
51
52    /**
53     * Create an exception for a subscriber class that does not implement the required contract.
54     *
55     * @param string $eventSubscriber subscriber class name
56     * @param string $expectedInterface required subscriber interface
57     *
58     * @return self exception describing the invalid subscriber class
59     */
60    public static function forInvalidEventSubscriber(string $eventSubscriber, string $expectedInterface): self
61    {
62        return new self(\sprintf(
63            'Event subscriber "%s" must implement "%s"',
64            $eventSubscriber,
65            $expectedInterface,
66        ));
67    }
68}