Driver_Kohana::response()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Openbuildings\Spiderling;
4
5
/**
6
 * Kohana driver, tries to use Kohana's internal Request methods to load urls.
7
 * Use this to very efficiently load kohana actions.
8
 * No Javascript
9
 *
10
 * @package    Openbuildings\Spiderling
11
 * @author     Ivan Kerin
12
 * @copyright  (c) 2013 OpenBuildings Ltd.
13
 * @license    http://spdx.org/licenses/BSD-3-Clause
14
 */
15
class Driver_Kohana extends Driver_Simple {
16
17
	public $name = 'kohana';
18
19 4
	function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
	{
21 4
		parent::__construct();
22 4
		$this->_request_factory = new Driver_Kohana_RequestFactory_Kohana();
23 4
	}
24
25
	/**
26
	 * Return a Response object of the last request operation
27
	 * @return Response
28
	 */
29 2
	public function response()
30
	{
31 2
		return $this->request_factory()->response();
0 ignored issues
show
Bug introduced by
The method response does only exist in Openbuildings\Spiderling\Driver_Kohana, but not in Openbuildings\Spiderling...r_Simple_RequestFactory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
32
	}
33
}
34