HistoryHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Startwind\Forrest\History;
4
5
class HistoryHandler
6
{
7
    public function __construct(
8
        private readonly string $historyFilename
9
    ) {
10
    }
11
12
    /**
13
     * Add a new line to the history.
14
     */
15
    public function addEntry(string $command): void
16
    {
17
        file_put_contents($this->historyFilename, $command . "\n", FILE_APPEND);
18
    }
19
20
    /**
21
     * Get the history entries as string[]
22
     */
23
    public function getEntries(): array
24
    {
25
        if (!is_file($this->historyFilename)) {
26
            return [];
27
        }
28
29
        return file($this->historyFilename);
30
    }
31
}
32