StepsList::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace PHPKitchen\CodeSpecs\Expectation\Internal;
4
5
/**
6
 * Represents a list of steps performed during a specification.
7
 *
8
 * @package PHPKitchen\CodeSpecs\Expectation\Internal
9
 * @author Dima 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
23
        return static::$instance;
24
    }
25
26
    public function add(string $step) {
27
        $lastStep = end($this->steps);
28
        if ($lastStep) {
29
            $lastStep->check();
30
        }
31
        $this->steps[] = new Step($step);
32
    }
33
34
    public function convertToString(): string {
35
        $message = implode(PHP_EOL, $this->steps);
36
        $message = $message ? $message . PHP_EOL : $message;
37
38
        return (string)$message;
39
    }
40
41
    public function clear() {
42
        $this->steps = [];
43
    }
44
}