ServiceActionProxy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Test Coverage

Coverage 88.24%

Importance

Changes 4
Bugs 1 Features 3
Metric Value
wmc 6
c 4
b 1
f 3
cbo 2
dl 0
loc 64
ccs 15
cts 17
cp 0.8824
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A execute() 0 10 2
A getActionData() 0 4 1
A setActionData() 0 4 1
1
<?php
2
/**
3
 * Fwk
4
 *
5
 * Copyright (c) 2011-2014, Julien Ballestracci <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
15
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
17
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
21
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
 * POSSIBILITY OF SUCH DAMAGE.
23
 *
24
 * PHP Version 5.3
25
 *
26
 * @category  Core
27
 * @package   Fwk\Core
28
 * @author    Julien Ballestracci <[email protected]>
29
 * @copyright 2011-2014 Julien Ballestracci <[email protected]>
30
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
31
 * @link      http://www.fwk.pw
32
 */
33
namespace Fwk\Core\Action;
34
35
use Fwk\Core\ActionProxy;
36
use Fwk\Core\Application;
37
use Fwk\Core\Context;
38
39
/**
40
 * ActionProxy to a Service. Allows a developper to use a Service as an Action.
41
 *
42
 * @category ActionProxy
43
 * @package  Fwk\Core
44
 * @author   Julien Ballestracci <[email protected]>
45
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
46
 * @link     http://www.fwk.pw
47
 */
48
class ServiceActionProxy implements ActionProxy
49
{
50
    /**
51
     * Service name
52
     * 
53
     * @var string
54
     */
55
    protected $serviceName;
56
    
57
    /**
58
     *
59
     * @var array
60
     */
61
    protected $actionData = array();
62
    
63
    /**
64
     * Constructor
65
     * 
66
     * @param string $serviceName Service name
67
     * 
68
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
69
     * @throws \InvalidArgumentException if $serviceName is empty
70
     */
71 20
    public function __construct($serviceName)
72
    {
73 20
        if (empty($serviceName)) {
74 1
            throw new \InvalidArgumentException(
75
                "You must specify a Service Name"
76 1
            );
77
        }
78
        
79 19
        $this->serviceName = $serviceName;
80 19
    }
81
    
82
    /**
83
     * Executes the service and eventually return the result (if any) or an
84
     * instance.
85
     *  
86
     * @param Application $app     The running Application
87
     * @param Context     $context Actual context
88
     * 
89
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use object|integer|double|string|null|boolean|array.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
90
     */
91 3
    public function execute(Application $app, Context $context)
92
    {
93 3
        $result = $app->getServices()->get($this->serviceName);
94
        
95 3
        if (is_array($result)) {
96
            $this->actionData = array_merge($result, $this->actionData);
97
        }
98
        
99 3
        return $result;
100
    }
101
    
102 2
    public function getActionData()
103
    {
104 2
        return $this->actionData;
105
    }
106
    
107 2
    public function setActionData(array $data)
108
    {
109 2
        $this->actionData = $data;
110
    }
111
}