FlattenDirTest::testFlattenDir()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.7333
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 FlattenDirTest extends TestCase
8
{
9
    use TestTasksTrait;
10
    use Task\Filesystem\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 testFlattenDir()
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->taskFlattenDir([
30
            'some/deeply/nested/*.re' => 'flattened',
31
            '*.txt' => 'flattened'
32
            ])
33
            ->run();
34
        $this->assertTrue($result->wasSuccessful(), $result->getMessage());
35
36
        $this->assertFileExists('flattened');
37
        $this->assertFileExists('flattened/structu.re');
38
        $this->assertFileExists('flattened/a.txt');
39
        $this->assertFileExists('flattened/b.txt');
40
    }
41
42
    public function testFlattenDirIncludingParents()
43
    {
44
        $this->fixtures->createAndCdToSandbox();
45
46
        $result = $this->taskFlattenDir('some/deeply/nested/*.re')
0 ignored issues
show
Bug introduced by
The method includeParents does only exist in Robo\Task\Filesystem\FlattenDir, 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...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
            ->includeParents([1,1])
48
            ->parentDir('some')
49
            ->to('flattened')
50
            ->run();
51
52
        $this->assertFileExists('flattened/deeply/nested');
53
        $this->assertFileExists('flattened/deeply/nested/structu.re');
54
55
    }
56
}
57