FilesystemHelperFactoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testCallingFactoryReturnsHelperInstance() 0 9 1
1
<?php
2
3
/**
4
 * Aist Filesystem Component (http://mateuszsitek.com/projects/filesystem)
5
 *
6
 * @copyright Copyright (c) 2017 DIGITAL WOLVES LTD (http://digitalwolves.ltd) All rights reserved.
7
 * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
8
 */
9
10
namespace Test\Aist\Filesystem\Console\Helper;
11
12
use Aist\Filesystem\Console\Helper\FilesystemHelper;
13
use Aist\Filesystem\Console\Helper\FilesystemHelperFactory;
14
use Interop\Container\ContainerInterface;
15
use PHPUnit\Framework\TestCase;
16
use Prophecy\Prophecy\ProphecyInterface;
17
18
class FilesystemHelperFactoryTest extends TestCase
19
{
20
    /**
21
     * @var ContainerInterface|ProphecyInterface
22
     */
23
    private $container;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function setUp()
29
    {
30
        $this->container = $this->prophesize(ContainerInterface::class);
31
    }
32
33
    public function testCallingFactoryReturnsHelperInstance()
34
    {
35
        $factory = new FilesystemHelperFactory();
36
        $this->assertInstanceOf(FilesystemHelperFactory::class, $factory);
37
38
        $class = $factory($this->container->reveal());
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ProphecyInterface, but not in Interop\Container\ContainerInterface.

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...
39
40
        $this->assertInstanceOf(FilesystemHelper::class, $class);
41
    }
42
}
43