Issues (10)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Report.php (4 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
152
        }
153 1
        return [];
154
    }
155
156
    /**
157
     * Send notification
158
     */
159 2
    public function send() : void
160
    {
161 2
        if ($this instanceof NotificationReport) {
162 2
            Notification::send($this->getNotifiable(), $this->getNotification());
0 ignored issues
show
The method getNotifiable() does not seem to exist on object<agoalofalife\Reports\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
The method getNotification() does not seem to exist on object<agoalofalife\Reports\Report>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
163
        }
164
    }
165
}