Code Duplication    Length = 26-36 lines in 3 locations

core/exceptions/UnexpectedEntityException.php 1 location

@@ 18-43 (lines=26) @@
15
 * @author        Brent Christensen
16
 * 
17
 */
18
class UnexpectedEntityException extends \UnexpectedValueException {
19
20
	/**
21
	 * UnexpectedEntityException constructor
22
	 *
23
	 * @param mixed      $entity the actual object or variable that was received
24
	 * @param string     $expected_class classname of the entity we wanted
25
	 * @param string     $message
26
	 * @param int        $code
27
	 * @param \Exception $previous
28
	 */
29
	public function __construct( $entity, $expected_class, $message = '', $code = 0, \Exception $previous = null ) {
30
		if ( empty( $message ) ) {
31
			$message = sprintf(
32
				__(
33
					'The retrieved entity is an instance of "%1$s", but an instance of "%2$s" was expected.',
34
					'event_espresso'
35
				),
36
				is_object( $entity ) ? get_class( $entity ) : gettype( $entity ),
37
				$expected_class
38
			);
39
		}
40
		parent::__construct( $message, $code, $previous );
41
	}
42
43
}
44
// End of file UnexpectedEntityException.php
45
// Location: /UnexpectedEntityException.php

core/services/commands/middleware/InvalidCommandBusMiddlewareException.php 1 location

@@ 22-57 (lines=36) @@
19
 * @since         4.9.1
20
 *
21
 */
22
class InvalidCommandBusMiddlewareException extends InvalidDataTypeException
23
{
24
25
26
    /**
27
     * @access public
28
     * @param  mixed     $command_bus_middleware_object
29
     * @param  string    $message
30
     * @param int        $code
31
     * @param \Exception $previous
32
     */
33
    public function __construct($command_bus_middleware_object, $message = '', $code = 0, \Exception $previous = null)
34
    {
35
        $command_bus_middleware = is_object($command_bus_middleware_object)
36
            ? get_class($command_bus_middleware_object)
37
            : gettype($command_bus_middleware_object);
38
39
        if (empty($message)) {
40
            $message = sprintf(
41
                __('The supplied Command Bus Middleware "%1$s" does not have a valid name. It should be in the following format: "{CommandName}Handler" ',
42
                    'event_espresso'),
43
                $command_bus_middleware
44
            );
45
        }
46
        parent::__construct(
47
            '$command_bus_middleware',
48
            $command_bus_middleware,
49
            'CommandBusMiddlewareInterface',
50
            $message,
51
            $code,
52
            $previous
53
        );
54
    }
55
56
57
}
58
// End of file InvalidCommandBusMiddlewareException.php
59
// Location: /InvalidCommandBusMiddlewareException.php

core/services/request/InvalidRequestStackMiddlewareException.php 1 location

@@ 19-51 (lines=33) @@
16
 * @author  Brent Christensen
17
 * @since   $VID:$
18
 */
19
class InvalidRequestStackMiddlewareException extends InvalidDataTypeException
20
{
21
22
    /**
23
     * @param  mixed     $middleware_app_class
24
     * @param  string    $message
25
     * @param int        $code
26
     * @param Exception $previous
27
     */
28
    public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null)
29
    {
30
        if(is_array($middleware_app_class)) {
31
            $middleware_app_class = reset($middleware_app_class);
32
        }
33
        if (empty($message)) {
34
            $message = sprintf(
35
                esc_html__(
36
                    'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.',
37
                    'event_espresso'
38
                ),
39
                $middleware_app_class
40
            );
41
        }
42
        parent::__construct(
43
            '$middleware_app_class',
44
            $middleware_app_class,
45
            'EventEspresso\core\services\request\middleware\Middleware',
46
            $message,
47
            $code,
48
            $previous
49
        );
50
    }
51
}
52