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.

MessageCallbackClosures   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 53
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A builder() 0 4 1
A build() 0 7 1
A onSuccess() 0 6 2
A onFailure() 0 6 2
1
<?php
2
/*
3
 * Copyright (c) 2012-2014 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\messagehandling\util;
25
26
use Closure;
27
use Exception;
28
use precore\lang\Object;
29
use predaddy\messagehandling\MessageCallback;
30
31
/**
32
 * Simple MessageCallback implementation which forwards message handler return values and thrown Exceptions
33
 * to the appropriate Closure if exists.
34
 *
35
 * You can build an instance with the builder() method which provides a builder
36
 * in order to be able to define optional callbacks.
37
 *
38
 * $messageCallback = MessageCallbackClosures::builder()
39
 *     ->successClosure($callback1)
40
 *     ->failureClosure($callback2)
41
 *     ->build();
42
 *
43
 * @author Janos Szurovecz <[email protected]>
44
 */
45
final class MessageCallbackClosures extends Object implements MessageCallback
46
{
47
    /**
48
     * @var Closure|null
49
     */
50
    private $onSuccessClosure;
51
52
    /**
53
     * @var Closure|null
54
     */
55
    private $onFailureClosure;
56
57
    /**
58
     * Use builder() method instead.
59
     */
60
    private function __construct()
61
    {
62
    }
63
64
    /**
65
     * @return MessageCallbackClosuresBuilder
66
     */
67
    public static function builder()
68
    {
69
        return new MessageCallbackClosuresBuilder();
70
    }
71
72
    /**
73
     * @param MessageCallbackClosuresBuilder $builder
74
     * @return MessageCallbackClosures
75
     */
76
    public static function build(MessageCallbackClosuresBuilder $builder)
77
    {
78
        $callback = new MessageCallbackClosures();
79
        $callback->onSuccessClosure = $builder->getSuccessClosure();
80
        $callback->onFailureClosure = $builder->getFailureClosure();
81
        return $callback;
82
    }
83
84
    public function onSuccess($result)
85
    {
86
        if ($this->onSuccessClosure !== null) {
87
            call_user_func($this->onSuccessClosure, $result);
88
        }
89
    }
90
91
    public function onFailure(Exception $exception)
92
    {
93
        if ($this->onFailureClosure !== null) {
94
            call_user_func($this->onFailureClosure, $exception);
95
        }
96
    }
97
}
98