HistoryHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getEntries() 0 7 2
A addEntry() 0 3 1
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