DebugLogger::log()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Thomas Whiston
5
 * Date: 16/02/2016
6
 * Time: 00:45
7
 */
8
9
namespace twhiston\twLib\Testing;
10
11
use Psr\Log\AbstractLogger;
12
13
class DebugLogger extends AbstractLogger
14
{
15
16
    /** @var  \PHPUnit_Framework_TestCase */
17
    private $owner;
18
19
    private $expected;
20
21
    private $index;
22
23
    public function __construct(\PHPUnit_Framework_TestCase $test)
24
    {
25
        $this->owner = $test;
26
        $this->index = 0;
27
    }
28
29
    public function reset()
30
    {
31
        $index = 0;
0 ignored issues
show
Unused Code introduced by
$index 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...
32
    }
33
34
    /**
35
     * Logs with an arbitrary level.
36
     *
37
     * @param mixed $level
38
     * @param string $message
39
     * @param array $context
40
     * @return null
41
     */
42
    public function log($level, $message, array $context = array())
43
    {
44
45
        $this->owner->assertArrayHasKey($this->index, $this->expected);
46
        $this->owner->assertStringStartsWith($this->expected[$this->index++], $message);
47
    }
48
49
    public function setExpectedMessages(array $messages)
50
    {
51
        $this->expected = $messages;
52
    }
53
}