Passed
Branch master (fa2e2c)
by Chubarov
15:40 queued 12:39
created

Report::getNameClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace agoalofalife\Reports;
5
6
use agoalofalife\Reports\Contracts\ResourceCollectionReport;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Support\Facades\Storage;
9
use \agoalofalife\Reports\Models\Report as ReportBase;
10
11
/**
12
 * Class Report
13
 * @package agoalofalife\Reports
14
 */
15
abstract class Report implements ResourceCollectionReport
16
{
17
    /**
18
     * Status report
19
     * @var string
20
     */
21
    protected $status = ReportBase::STATUS_NEW;
22
23
    /**
24
     * Flag update report and not read
25
     * @var bool
26
     */
27
    protected $isCompleted = false;
28
29
    /**
30
     * Disk for filesystem
31
     * @var string
32
     */
33
    protected $disk = 'public';
34
35
    /**
36
     * Get file name
37
     * @return string
38
     */
39
    abstract public function getFilename() : string;
40
41
    /**
42
     * Get title report
43
     * @return string
44
     */
45
    abstract public function getTitle() : string;
46
47
    /**
48
     * Get description report
49
     * @return string
50
     */
51
    abstract public function getDescription() : string;
52
53
    /**
54
     * @return array
55
     */
56 1
    public function toArray() : array
57
    {
58
        return [
59 1
            'name' => $this->getTitle(),
60 1
            'description' => $this->getDescription(),
61 1
            'class' => $this->getNameClass(),
62 1
            'path' => $this->getPathToFile(),
63 1
            'lastModified' => $this->getDateLastModified(),
64 1
            'isCompleted' => $this->isCompleted,
65 1
            'status' => $this->status
66
        ];
67
    }
68
69
    /**
70
     * Get path to file
71
     * @return null|string
72
     */
73 1
    public function getPathToFile() : ?string
74
    {
75 1
        return Storage::disk($this->disk)->exists($this->getFileNormalize()) ?
76 1
            Storage::disk($this->disk)->url($this->getFileNormalize()) : null;
77
    }
78
79
    /**
80
     * Get date last modified file
81
     * @return null|string
82
     */
83 1
    public function getDateLastModified() : ?string
84
    {
85 1
        return Storage::disk($this->disk)->exists($this->getFileNormalize()) ?
86 1
            date('Y-m-d H:i:s', Storage::disk($this->disk)->lastModified($this->getFileNormalize())) : null;
87
    }
88
    /**
89
     * Get full class name
90
     * @return string
91
     */
92 1
    public function getNameClass() : string
93
    {
94 1
        return get_class($this);
95
    }
96
97
    /**
98
     * Change is completed
99
     * @param bool $flag
100
     */
101 1
    public function changeCompleted(bool $flag) : void
102
    {
103 1
        $this->isCompleted = $flag;
104 1
    }
105
106
    /**
107
     * @return bool
108
     */
109 1
    public function getCompleted() : bool
110
    {
111 1
        return $this->isCompleted;
112
    }
113
    /**
114
     * Change status state report
115
     * @param string $status
116
     */
117 1
    public function changeStatus(string $status) : void
118
    {
119 1
        $this->status = $status;
120 1
    }
121
122
    /**
123
     * Get Model Report
124
     * @return Model
125
     */
126 3
    public function getReportModel() : Model
127
    {
128 3
        return ReportBase::where('class_name', get_class($this))->get()->first();
129
    }
130
    /**
131
     * Get builder two parts string :
132
     * Filename
133
     * Extension
134
     * @return string
135
     */
136 2
    public function getFileNormalize() : string
137
    {
138 2
        return "{$this->getFilename()}.{$this->extension}";
0 ignored issues
show
Bug introduced by
The property extension does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
139
    }
140
}