Completed
Pull Request — master (#1058)
by
unknown
09:38
created
core/services/commands/CommandHandler.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -14,33 +14,33 @@
 block discarded – undo
14 14
  */
15 15
 abstract class CommandHandler implements CommandHandlerInterface
16 16
 {
17
-    /**
18
-     * Verifies the inputted command is of the correct type.
19
-     * @since $VID:$
20
-     * @param CommandInterface $inputted_command
21
-     * @throws InvalidEntityException
22
-     */
23
-    protected function verifyCommand(CommandInterface $inputted_command)
24
-    {
25
-        $expected_classname = str_replace('CommandHandler', 'Command', get_class($this));
26
-        if (!is_a($inputted_command, $expected_classname, true)) {
27
-            throw new InvalidEntityException(
28
-                $inputted_command,
29
-                $expected_classname
30
-            );
31
-        }
32
-    }
17
+	/**
18
+	 * Verifies the inputted command is of the correct type.
19
+	 * @since $VID:$
20
+	 * @param CommandInterface $inputted_command
21
+	 * @throws InvalidEntityException
22
+	 */
23
+	protected function verifyCommand(CommandInterface $inputted_command)
24
+	{
25
+		$expected_classname = str_replace('CommandHandler', 'Command', get_class($this));
26
+		if (!is_a($inputted_command, $expected_classname, true)) {
27
+			throw new InvalidEntityException(
28
+				$inputted_command,
29
+				$expected_classname
30
+			);
31
+		}
32
+	}
33 33
 
34
-    /**
35
-     * Wrapper for handle method, just first verifies the command is of the correct type.
36
-     * @since $VID:$
37
-     * @param CommandInterface $command
38
-     * @return mixed
39
-     * @throws InvalidEntityException
40
-     */
41
-    public function invokeHandle(CommandInterface $command)
42
-    {
43
-        $this->verifyCommand($command);
44
-        return $this->handle($command);
45
-    }
34
+	/**
35
+	 * Wrapper for handle method, just first verifies the command is of the correct type.
36
+	 * @since $VID:$
37
+	 * @param CommandInterface $command
38
+	 * @return mixed
39
+	 * @throws InvalidEntityException
40
+	 */
41
+	public function invokeHandle(CommandInterface $command)
42
+	{
43
+		$this->verifyCommand($command);
44
+		return $this->handle($command);
45
+	}
46 46
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
     protected function verifyCommand(CommandInterface $inputted_command)
24 24
     {
25 25
         $expected_classname = str_replace('CommandHandler', 'Command', get_class($this));
26
-        if (!is_a($inputted_command, $expected_classname, true)) {
26
+        if ( ! is_a($inputted_command, $expected_classname, true)) {
27 27
             throw new InvalidEntityException(
28 28
                 $inputted_command,
29 29
                 $expected_classname
Please login to merge, or discard this patch.
core/services/commands/CommandHandlerInterface.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@
 block discarded – undo
8 8
  */
9 9
 interface CommandHandlerInterface
10 10
 {
11
-    /**
12
-     * Wrapper for handle, except it verifies the command is of the correct type.
13
-     * @since $VID:$
14
-     * @param CommandInterface $command
15
-     * @return mixed
16
-     */
17
-    public function invokeHandle(CommandInterface $command);
18
-    /**
19
-     * Performs the command handler's logic.
20
-     * Note: the command bus directly calls invokeCommand, which will verify the command is of the correct type.
21
-     * @param \EventEspresso\core\services\commands\CommandInterface $command
22
-     * @return mixed
23
-     */
24
-    public function handle(CommandInterface $command);
11
+	/**
12
+	 * Wrapper for handle, except it verifies the command is of the correct type.
13
+	 * @since $VID:$
14
+	 * @param CommandInterface $command
15
+	 * @return mixed
16
+	 */
17
+	public function invokeHandle(CommandInterface $command);
18
+	/**
19
+	 * Performs the command handler's logic.
20
+	 * Note: the command bus directly calls invokeCommand, which will verify the command is of the correct type.
21
+	 * @param \EventEspresso\core\services\commands\CommandInterface $command
22
+	 * @return mixed
23
+	 */
24
+	public function handle(CommandInterface $command);
25 25
 }
Please login to merge, or discard this patch.
core/services/commands/CommandBus.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -34,73 +34,73 @@
 block discarded – undo
34 34
 class CommandBus implements CommandBusInterface
35 35
 {
36 36
 
37
-    /**
38
-     * @type CommandHandlerManagerInterface $command_handler_manager
39
-     */
40
-    private $command_handler_manager;
37
+	/**
38
+	 * @type CommandHandlerManagerInterface $command_handler_manager
39
+	 */
40
+	private $command_handler_manager;
41 41
 
42
-    /**
43
-     * @type CommandBusMiddlewareInterface[] $command_bus_middleware
44
-     */
45
-    private $command_bus_middleware;
42
+	/**
43
+	 * @type CommandBusMiddlewareInterface[] $command_bus_middleware
44
+	 */
45
+	private $command_bus_middleware;
46 46
 
47 47
 
48
-    /**
49
-     * CommandBus constructor
50
-     *
51
-     * @param CommandHandlerManagerInterface  $command_handler_manager
52
-     * @param CommandBusMiddlewareInterface[] $command_bus_middleware
53
-     */
54
-    public function __construct(
55
-        CommandHandlerManagerInterface $command_handler_manager,
56
-        array $command_bus_middleware = array()
57
-    ) {
58
-        $this->command_handler_manager = $command_handler_manager;
59
-        $this->command_bus_middleware = is_array($command_bus_middleware)
60
-            ? $command_bus_middleware
61
-            : array($command_bus_middleware);
62
-    }
48
+	/**
49
+	 * CommandBus constructor
50
+	 *
51
+	 * @param CommandHandlerManagerInterface  $command_handler_manager
52
+	 * @param CommandBusMiddlewareInterface[] $command_bus_middleware
53
+	 */
54
+	public function __construct(
55
+		CommandHandlerManagerInterface $command_handler_manager,
56
+		array $command_bus_middleware = array()
57
+	) {
58
+		$this->command_handler_manager = $command_handler_manager;
59
+		$this->command_bus_middleware = is_array($command_bus_middleware)
60
+			? $command_bus_middleware
61
+			: array($command_bus_middleware);
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * @return CommandHandlerManagerInterface
67
-     */
68
-    public function getCommandHandlerManager()
69
-    {
70
-        return $this->command_handler_manager;
71
-    }
65
+	/**
66
+	 * @return CommandHandlerManagerInterface
67
+	 */
68
+	public function getCommandHandlerManager()
69
+	{
70
+		return $this->command_handler_manager;
71
+	}
72 72
 
73 73
 
74
-    /**
75
-     * @param CommandInterface $command
76
-     * @return mixed
77
-     * @throws InvalidDataTypeException
78
-     * @throws InvalidCommandBusMiddlewareException
79
-     */
80
-    public function execute($command)
81
-    {
82
-        if (! $command instanceof CommandInterface) {
83
-            throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface');
84
-        }
85
-        // we're going to add the Command Handler as a callable
86
-        // that will get run at the end of our middleware stack
87
-        // can't pass $this to a Closure, so use a named variable
88
-        $command_bus = $this;
89
-        $middleware = function ($command) use ($command_bus) {
90
-            return $command_bus->getCommandHandlerManager()
91
-                               ->getCommandHandler($command, $command_bus)
92
-                               ->invokeHandle($command);
93
-        };
94
-        // now build the rest of the middleware stack
95
-        while ($command_bus_middleware = array_pop($this->command_bus_middleware)) {
96
-            if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) {
97
-                throw new InvalidCommandBusMiddlewareException($command_bus_middleware);
98
-            }
99
-            $middleware = function ($command) use ($command_bus_middleware, $middleware) {
100
-                return $command_bus_middleware->handle($command, $middleware);
101
-            };
102
-        }
103
-        // and finally, pass the command into the stack and return the results
104
-        return $middleware($command);
105
-    }
74
+	/**
75
+	 * @param CommandInterface $command
76
+	 * @return mixed
77
+	 * @throws InvalidDataTypeException
78
+	 * @throws InvalidCommandBusMiddlewareException
79
+	 */
80
+	public function execute($command)
81
+	{
82
+		if (! $command instanceof CommandInterface) {
83
+			throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface');
84
+		}
85
+		// we're going to add the Command Handler as a callable
86
+		// that will get run at the end of our middleware stack
87
+		// can't pass $this to a Closure, so use a named variable
88
+		$command_bus = $this;
89
+		$middleware = function ($command) use ($command_bus) {
90
+			return $command_bus->getCommandHandlerManager()
91
+							   ->getCommandHandler($command, $command_bus)
92
+							   ->invokeHandle($command);
93
+		};
94
+		// now build the rest of the middleware stack
95
+		while ($command_bus_middleware = array_pop($this->command_bus_middleware)) {
96
+			if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) {
97
+				throw new InvalidCommandBusMiddlewareException($command_bus_middleware);
98
+			}
99
+			$middleware = function ($command) use ($command_bus_middleware, $middleware) {
100
+				return $command_bus_middleware->handle($command, $middleware);
101
+			};
102
+		}
103
+		// and finally, pass the command into the stack and return the results
104
+		return $middleware($command);
105
+	}
106 106
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -79,24 +79,24 @@
 block discarded – undo
79 79
      */
80 80
     public function execute($command)
81 81
     {
82
-        if (! $command instanceof CommandInterface) {
83
-            throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface');
82
+        if ( ! $command instanceof CommandInterface) {
83
+            throw new InvalidDataTypeException(__METHOD__.'( $command )', $command, 'CommandInterface');
84 84
         }
85 85
         // we're going to add the Command Handler as a callable
86 86
         // that will get run at the end of our middleware stack
87 87
         // can't pass $this to a Closure, so use a named variable
88 88
         $command_bus = $this;
89
-        $middleware = function ($command) use ($command_bus) {
89
+        $middleware = function($command) use ($command_bus) {
90 90
             return $command_bus->getCommandHandlerManager()
91 91
                                ->getCommandHandler($command, $command_bus)
92 92
                                ->invokeHandle($command);
93 93
         };
94 94
         // now build the rest of the middleware stack
95 95
         while ($command_bus_middleware = array_pop($this->command_bus_middleware)) {
96
-            if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) {
96
+            if ( ! $command_bus_middleware instanceof CommandBusMiddlewareInterface) {
97 97
                 throw new InvalidCommandBusMiddlewareException($command_bus_middleware);
98 98
             }
99
-            $middleware = function ($command) use ($command_bus_middleware, $middleware) {
99
+            $middleware = function($command) use ($command_bus_middleware, $middleware) {
100 100
                 return $command_bus_middleware->handle($command, $middleware);
101 101
             };
102 102
         }
Please login to merge, or discard this patch.