Completed
Push — master ( 90ac5a...649bdf )
by Amine
11s
created

Transformer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 10
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 4 1
A alias() 0 4 1
1
<?php namespace Tarsana\Tester;
2
3
use PHPUnit\Framework\TestCase;
4
use Tarsana\Command\Command;
5
use Tarsana\Command\Console\Console;
6
use Tarsana\IO\Filesystem;
7
use Tarsana\IO\Filesystem\Adapters\Memory;
8
use Tarsana\IO\Resource\Buffer;
9
use Tarsana\Tester\Mocks\Transformer;
10
11
class CommandTestCase extends TestCase {
12
13
    protected $fs;
14
    protected $cmd;
15
    protected $stdout;
16
    protected $stderr;
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
18
    public function setUp() {
19
        $adapter = new Memory;
20
        $adapter->mkdir('.', 0777, true);
21
        $this->fs = new Filesystem('.', $adapter);
22
    }
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
23
24
    public function command(
25
        Command $command, array $args = [],
26
        array $options = [], bool $rawArgs = true
27
    ) {
28
        $console = (new Console)
29
            ->stdin(new Buffer)
30
            ->stdout(new Buffer)
31
            ->stderr(new Buffer)
32
            ->outTransformer(new Transformer);
33
34
        $this->fs->dir($command->fs()->path(), true);
35
36
        $command->console($console)
37
                ->fs($this->fs)
38
                ->run($args, $options, $rawArgs);
39
0 ignored issues
show
Bug introduced by
The method stdout does only exist in Tarsana\Command\Console\Console, but not in Tarsana\IO\Resource\Reader.

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...
40
        $this->cmd    = $command;
41
        $this->stdout = $console->stdout()->read();
42
        $this->stderr = $console->stderr()->read();
43
44
        return $this;
45
    }
46
47
    public function prints(string $text) {
48
        $this->assertTrue(
49
            false !== strpos($this->stdout, $text),
50
            "Failed asserting that '{$this->stdout}' Contains '{$text}'"
51
        );
52
        return $this;
53
    }
54
55
    public function printsExactly(string $text) {
56
        $this->assertEquals($text, $this->stdout);
57
        return $this;
58
    }
59
60
    public function printsError(string $text) {
61
        $this->assertTrue(
62
            false !== strpos($this->stderr, $text),
63
            "Failed asserting that '{$this->stderr}' Contains '{$text}'"
64
        );
65
        return $this;
66
    }
67
68
    public function argsEqual($args) {
69
        $this->assertEquals($args, $this->cmd->args());
70
        return $this;
71
    }
72
73
    public function optionsEqual($options) {
74
        $this->assertEquals($options, $this->cmd->options());
75
        return $this;
76
    }
77
}
78