AnnotatedSagaManager::extractAssociationValues()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4286
cc 2
eloc 8
nc 2
nop 2
crap 2
1
<?php
2
3
/*
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * The software is based on the Axon Framework project which is
17
 * licensed under the Apache 2.0 license. For more information on the Axon Framework
18
 * see <http://www.axonframework.org/>.
19
 * 
20
 * This software consists of voluntary contributions made by many individuals
21
 * and is licensed under the MIT license. For more information, see
22
 * <http://www.governor-framework.org/>.
23
 */
24
25
namespace Governor\Framework\Saga\Annotation;
26
27
use Governor\Framework\Saga\SagaInitializationPolicy;
28
use Governor\Framework\Saga\SagaCreationPolicy;
29
use Governor\Framework\Domain\EventMessageInterface;
30
use Governor\Framework\Saga\AbstractSagaManager;
31
use Governor\Framework\Saga\SagaInterface;
32
33
/**
34
 * Implementation of the SagaManager that uses annotations on the Sagas to describe the lifecycle management. Unlike
35
 * the SimpleSagaManager, this implementation can manage several types of Saga in a single AnnotatedSagaManager.
36
 *
37
 * @author    "David Kalosi" <[email protected]>  
38
 * @license   <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> 
39
 */
40
class AnnotatedSagaManager extends AbstractSagaManager
41
{
42
43
    private $parameterResolverFactory;
44
45 13
    protected function getSagaCreationPolicy($sagaType,
46
            EventMessageInterface $event)
47
    {
48 13
        $inspector = new SagaMethodMessageHandlerInspector($sagaType);
49 13
        $handlers = $inspector->getMessageHandlers($event);
50
51 13
        foreach ($handlers as $handler) {
52 13
            if ($handler->getCreationPolicy() !== SagaCreationPolicy::NONE) {
53 11
                return new SagaInitializationPolicy($handler->getCreationPolicy(),
54 11
                        $handler->getAssociationValue($event));
55
            }
56 6
        }
57
58 6
        return new SagaInitializationPolicy(SagaCreationPolicy::NONE, null);
59
    }
60
61 15
    protected function extractAssociationValues($sagaType,
62
            EventMessageInterface $event)
63
    {
64 15
        $inspector = new SagaMethodMessageHandlerInspector($sagaType);
65 15
        $handlers = $inspector->getMessageHandlers($event);
66 15
        $values = array();
67
68 15
        foreach ($handlers as $handler) {
69 13
            $values[] = $handler->getAssociationValue($event);
70 15
        }
71
72 15
        return $values;
73
    }
74
75 11
    protected function preProcessSaga(SagaInterface $saga)
76
    {
77 11
        if (null !== $this->parameterResolverFactory) {
78
            $saga->registerParameterResolverFactory($this->parameterResolverFactory);
0 ignored issues
show
Bug introduced by
The method registerParameterResolverFactory() does not seem to exist on object<Governor\Framework\Saga\SagaInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
        }
80 11
    }
81
82
    public function getTargetType()
83
    {
84
        return current($this->getManagedSagaTypes());        
85
    }
86
87
}
88