LogFile::timestamp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spiral\LogViewer\Entities;
4
5
use Symfony\Component\Finder\SplFileInfo;
6
7
class LogFile
8
{
9
    /** @var SplFileInfo */
10
    private $file;
11
12
    /**
13
     * Log constructor.
14
     *
15
     * @param $file
16
     */
17
    public function __construct($file)
18
    {
19
        if ($file instanceof SplFileInfo) {
20
            $this->file = $file;
21
        } elseif (is_string($file)) {
22
            $this->file = new SplFileInfo($file, dirname($file), basename($file));
23
        } else {
24
            throw new \InvalidArgumentException(sprintf(
25
                'Unsupported file, string or "%s" instance is waiting.',
26
                SplFileInfo::class
27
            ));
28
        }
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function filename(): string
35
    {
36
        return $this->file->getRealPath();
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function name(): string
43
    {
44
        return $this->file->getFilename();
45
    }
46
47
    /**
48
     * @return int
49
     */
50
    public function size(): int
51
    {
52
        return $this->file->getSize();
53
    }
54
55
    /**
56
     * @return LogTimestamp
57
     */
58
    public function timestamp(): LogTimestamp
59
    {
60
        return new LogTimestamp($this->file->getMTime(), []);
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function content(): string
67
    {
68
        return $this->file->getContents();
69
    }
70
}