GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — bugfix/5.4build ( 31a631 )
by Szurovecz
08:38
created

CommandBus   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 0
cbo 3
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A builder() 0 4 1
A callableWrappersFor() 0 10 1
1
<?php
2
/*
3
 * Copyright (c) 2013 Janos Szurovecz
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6
 * this software and associated documentation files (the "Software"), to deal in
7
 * the Software without restriction, including without limitation the rights to
8
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
 * of the Software, and to permit persons to whom the Software is furnished to do
10
 * so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in all
13
 * copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
 * SOFTWARE.
22
 */
23
24
namespace predaddy\commandhandling;
25
26
use precore\util\Preconditions;
27
use predaddy\messagehandling\SimpleMessageBus;
28
29
/**
30
 * A typical command bus has the following behaviours:
31
 *  - all command handler methods are wrapped by a unique transaction
32
 *  - the type of the message must be exactly the same as the parameter in the handler method
33
 *
34
 * Only one command handler can process a particular command, otherwise a runtime exception will be thrown.
35
 *
36
 * @author Janos Szurovecz <[email protected]>
37
 */
38
class CommandBus extends SimpleMessageBus
39
{
40
    /**
41
     * @param CommandBusBuilder $builder
42
     */
43
    public function __construct(CommandBusBuilder $builder = null)
44
    {
45
        if ($builder === null) {
46
            $builder = self::builder();
47
        }
48
        parent::__construct($builder);
49
    }
50
51
    /**
52
     * @return CommandBusBuilder
53
     */
54
    public static function builder()
55
    {
56
        return new CommandBusBuilder();
57
    }
58
59
    protected function callableWrappersFor($message)
60
    {
61
        $wrappers = parent::callableWrappersFor($message);
62
        Preconditions::checkState(
63
            count($wrappers) <= 1,
64
            "More than one command handler is registered for message '%s'",
65
            get_class($message)
66
        );
67
        return $wrappers;
68
    }
69
}
70