Completed
Pull Request — master (#924)
by Greg
02:10
created

ConcatTest::testConcat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Robo;
3
4
use PHPUnit\Framework\TestCase;
5
use Robo\Traits\TestTasksTrait;
6
7
class ConcatTest extends TestCase
8
{
9
    use TestTasksTrait;
10
    use Task\File\loadTasks;
11
12
    protected $fixtures;
13
14
    public function setUp()
15
    {
16
        $this->fixtures = new Fixtures();
17
        $this->initTestTasksTrait();
18
    }
19
20
    public function tearDown()
21
    {
22
        $this->fixtures->cleanup();
23
    }
24
25 View Code Duplication
    public function testConcat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $this->fixtures->createAndCdToSandbox();
28
29
        $result = $this->taskConcat(['a.txt', 'b.txt'])
0 ignored issues
show
Bug introduced by
The method to does only exist in Robo\Task\File\Concat, but not in Robo\Collection\CollectionBuilder.

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...
30
            ->to('merged.txt')
31
            ->run();
32
        $this->assertTrue($result->wasSuccessful());
33
        $this->assertFileExists('merged.txt');
34
        $expected = "A\nB\n";
35
        $actual = file_get_contents('merged.txt');
36
        $this->assertEquals($expected, $actual);
37
38
39
    }
40
41
}
42