StepsList::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PHPKitchen\CodeSpecsCore\Expectation\Internal;
4
5
/**
6
 * Represents a list of steps performed during a specification.
7
 *
8
 * @package PHPKitchen\CodeSpecsCore\Expectation\Internal
9
 * @author Dmitry Kolodko <[email protected]>
10
 */
11
class StepsList {
12
    /**
13
     * @var Step[] steps storage.
14
     */
15
    private $steps = [];
16
    private static $instance;
17
18
    public static function getInstance(): self {
19
        if (null === static::$instance) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $instance to at least protected.
Loading history...
20
            static::$instance = new static();
21
        }
22
        return static::$instance;
23
    }
24
25
    public function add(string $step) {
26
        $lastStep = end($this->steps);
27
        if ($lastStep) {
28
            $lastStep->check();
29
        }
30
        $this->steps[] = new Step($step);
31
    }
32
33
    public function convertToString(): string {
34
        $message = implode(PHP_EOL, $this->steps);
35
        $message = $message ? $message . PHP_EOL : $message;
36
        return (string)$message;
37
    }
38
39
    public function clear() {
40
        $this->steps = [];
41
    }
42
}