ControllerActionProxy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 3
Metric Value
wmc 4
c 5
b 1
f 3
cbo 1
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A instantiate() 0 6 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\Application;
36
37
/**
38
 * ActionProxy to a Controller class
39
 *
40
 * @category ActionProxy
41
 * @package  Fwk\Core
42
 * @author   Julien Ballestracci <[email protected]>
43
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
44
 * @link     http://www.fwk.pw
45
 */
46
class ControllerActionProxy extends AbstractControllerActionProxy
47
{
48
    /**
49
     * Controller's full class name
50
     * 
51
     * @var string
52
     */
53
    protected $className;
54
    
55
    /**
56
     * Controller's method
57
     * 
58
     * @var string
59
     */
60
    protected $method;
61
62
    /**
63
     * Constructor
64
     * 
65
     * @param string $className Controller's full class name
66
     * @param string $method    Controller's method
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 $className or $method is empty
70
     */
71 20
    public function __construct($className, $method)
72
    {
73 20
        if (empty($className) || empty($method)) {
74 1
            throw new \InvalidArgumentException(
75
                "Controller class name and method cannot be empty"
76 1
            );
77
        }
78
        
79 19
        $this->className    = $className;
80 19
        $this->method       = $method;
81 19
    }
82
    
83
    /**
84
     * Instanciates the controller class
85
     * 
86
     * @param Application $app The running application
87
     * 
88
     * @return mixed Controller's instance
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use object.

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...
89
     */
90 4
    protected function instantiate(Application $app)
91
    {
92 4
        $refClass = new \ReflectionClass($this->className);
93
        
94 4
        return $refClass->newInstanceArgs();
95
    }
96
}
97