AbstractBehaviorExtensionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 41
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testGetClassAnalyzer() 0 8 1
A testBuildDefinitionWithNullValue() 0 4 1
A testBuildDefinition() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zenify\DoctrineBehaviors\Tests\DI;
6
7
use Knp\DoctrineBehaviors\ORM\Loggable\LoggerCallable;
8
use Knp\DoctrineBehaviors\Reflection\ClassAnalyzer;
9
use Nette\DI\Compiler;
10
use PHPUnit\Framework\TestCase;
11
use Zenify\DoctrineBehaviors\DI\AbstractBehaviorExtension;
12
use Zenify\DoctrineBehaviors\Tests\DI\AbstractBehaviorExtensionSource\SomeBehaviorExtension;
13
14
15
final class AbstractBehaviorExtensionTest extends TestCase
16
{
17
18
	/**
19
	 * @var AbstractBehaviorExtension|SomeBehaviorExtension
20
	 */
21
	private $abstractBehaviorsExtension;
22
23
24
	protected function setUp()
25
	{
26
		$this->abstractBehaviorsExtension = new SomeBehaviorExtension;
27
		$this->abstractBehaviorsExtension->setCompiler(new Compiler, 'someBehavior');
28
	}
29
30
31
	public function testGetClassAnalyzer()
32
	{
33
		$classAnalyzer = $this->abstractBehaviorsExtension->getClassAnalyzerPublic();
0 ignored issues
show
Bug introduced by
The method getClassAnalyzerPublic does only exist in Zenify\DoctrineBehaviors...e\SomeBehaviorExtension, but not in Zenify\DoctrineBehaviors...stractBehaviorExtension.

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...
34
		$this->assertSame(ClassAnalyzer::class, $classAnalyzer->getClass());
35
36
		$sameClassAnalyzer = $this->abstractBehaviorsExtension->getClassAnalyzerPublic();
37
		$this->assertSame($classAnalyzer, $sameClassAnalyzer);
38
	}
39
40
41
	public function testBuildDefinitionWithNullValue()
42
	{
43
		$this->assertNull($this->abstractBehaviorsExtension->buildDefinitionFromCallablePublic(NULL));
0 ignored issues
show
Bug introduced by
The method buildDefinitionFromCallablePublic does only exist in Zenify\DoctrineBehaviors...e\SomeBehaviorExtension, but not in Zenify\DoctrineBehaviors...stractBehaviorExtension.

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...
44
	}
45
46
47
	public function testBuildDefinition()
48
	{
49
		$definition = $this->abstractBehaviorsExtension->buildDefinitionFromCallablePublic(LoggerCallable::class);
0 ignored issues
show
Bug introduced by
The method buildDefinitionFromCallablePublic does only exist in Zenify\DoctrineBehaviors...e\SomeBehaviorExtension, but not in Zenify\DoctrineBehaviors...stractBehaviorExtension.

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...
50
51
		$this->assertSame(LoggerCallable::class, $definition->getClass());
52
		$this->assertSame(LoggerCallable::class, $definition->getFactory()->getEntity());
53
	}
54
55
}
56