Passed
Push — master ( bb70d5...33dd6a )
by
unknown
02:16
created

LineHelper::lineWithoutDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cion\LaravelLogReader\Reader;
4
5
use Illuminate\Support\Str;
6
7
class LineHelper
8
{
9
    protected $line;
10
11
    public function __construct($line)
12
    {
13
        $this->line = $line;
14
    }
15
16
    public function getDate()
17
    {
18
        return substr($this->line, strpos($this->line, '[') + 1, strpos($this->line, ']') - 1);
19
    }
20
21
    public function hasDate()
22
    {
23
        return (bool) strtotime($this->getDate());
24
    }
25
26
    public function hasType($type)
27
    {
28
        return strpos($this->line, $this->getEnv().'.'.$type) !== false;
29
    }
30
31
    public function getLogMessageOf($type)
32
    {
33
        return Str::replaceFirst($this->getEnv().'.'.$type.': ', '', $this->lineWithoutDate());
34
    }
35
36
    public function lineWithoutDate()
37
    {
38
        return substr($this->line, strpos($this->line, ']') + 2);
39
    }
40
41
    public function getEnv()
42
    {
43
        return config('logreader.env', env('APP_ENV'));
44
    }
45
}
46