Issues (19)

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/Models/ManagesPortfolio.php (2 issues)

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
3
namespace Larafolio\Models;
4
5
use Illuminate\Support\Facades\Storage;
6
7
trait ManagesPortfolio
8
{
9
    /**
10
     * Add a project to the portfolio.
11
     *
12
     * @param array $data Array of data to save.
13
     *
14
     * @return Project
15
     */
16
    public function addProject(array $data)
17
    {
18
        $data['order'] = Project::all()->pluck('order')->max() + 1;
19
20
        $project = Project::create($data);
21
22
        foreach (collect($data)->get('blocks', []) as $block) {
23
            $this->addBlockToProject($project, $block);
24
        }
25
26
        foreach (collect($data)->get('links', []) as $link) {
27
            $this->addLinkToProject($project, $link);
28
        }
29
30
        return $project;
31
    }
32
33
    /**
34
     * Update a project in the portfolio.
35
     *
36
     * @param Project $project Project to update.
37
     * @param array   $data    Array of data to save.
38
     *
39
     * @return Project
40
     */
41
    public function updateProject(Project $project, array $data)
42
    {
43
        $project->update($data);
44
45
        $this->updateProjectTextBlocks($project, $data);
46
47
        $this->updateProjectLinks($project, $data);
48
49
        return $project;
50
    }
51
52
    /**
53
     * Remove a project from the portfolio.
54
     *
55
     * @param Project $project Project to remove.
56
     *
57
     * @return bool|null
58
     */
59
    public function removeProject(Project $project)
60
    {
61
        return $project->delete();
62
    }
63
64
    /**
65
     * Restore a soft deleted project.
66
     *
67
     * @param Project $project Project to restore.
68
     *
69
     * @return bool|null
70
     */
71
    public function restoreProject(Project $project)
72
    {
73
        $this->updateProject($project, ['visible' => false]);
74
75
        return $project->restore();
76
    }
77
78
    /**
79
     * Hard delete a project from the portfolio.
80
     *
81
     * @param Project $project Project to purge.
82
     *
83
     * @return bool|null
84
     */
85
    public function purgeProject(Project $project)
86
    {
87
        foreach ($project->images as $image) {
88
            $this->removeImage($image);
89
        }
90
91
        $project->restore();
92
93
        return $project->forceDelete();
94
    }
95
96
    /**
97
     * Update the order of projects in the portfolio.
98
     *
99
     * @param array $data Array of data for projects.
100
     */
101
    public function updateProjectOrder(array $data)
102
    {
103
        $projectData = $this->setOrder($data);
104
105
        foreach ($projectData as $singleProjectData) {
106
            $project = Project::find($singleProjectData['id']);
107
108
            $project->update($singleProjectData);
109
        }
110
    }
111
112
    /**
113
     * Set order of data based on order value.
114
     *
115
     * @param array $data Data array containing 'order' index.
116
     *
117
     * @return \Illuminate\Support\Collection
118
     */
119
    protected function setOrder(array $data)
120
    {
121
        return collect($data)->sortBy('order')
122
            ->map(function ($item, $key) {
123
                $item['order'] = $key;
124
125
                return $item;
126
            });
127
    }
128
129
    /**
130
     * Add a text block to a project.
131
     *
132
     * @param Project $project   Project to add text block to.
133
     * @param array   $blockData Array of text block data.
134
     *
135
     * @return \Illuminate\Database\Eloquent\Model
136
     */
137
    public function addBlockToProject(Project $project, array $blockData)
138
    {
139
        return $project->blocks()->create($blockData);
140
    }
141
142
    /**
143
     * Update a text block.
144
     *
145
     * @param TextBlock $textBlock Text block to update.
146
     * @param array     $blockData Array of text block data.
147
     *
148
     * @return TextBlock
149
     */
150
    public function updateTextBlock(TextBlock $textBlock, array $blockData)
151
    {
152
        $textBlock->update($blockData);
153
154
        return $textBlock;
155
    }
156
157
    /**
158
     * Update project text blocks by adding new ones and updating existing ones.
159
     *
160
     * @param Project $project Project that blocks belong to.
161
     * @param array   $data    Array of project information.
162
     */
163 View Code Duplication
    public function updateProjectTextBlocks(Project $project, array $data)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
    {
165
        $blockData = collect($data)->get('blocks', []);
166
167
        $blockData = $this->setOrder($blockData);
168
169
        foreach ($blockData as $singleBlockData) {
170
            if (isset($singleBlockData['project_id'])) {
171
                $block = TextBlock::find($singleBlockData['id']);
172
173
                $this->updateTextBlock($block, $singleBlockData);
174
            } else {
175
                $this->addBlockToProject($project, $singleBlockData);
176
            }
177
        }
178
    }
179
180
    /**
181
     * Remove a text block from a project.
182
     *
183
     * @param TextBlock $textBlock The text block to delete.
184
     *
185
     * @return bool|null
186
     */
187
    public function removeTextBlock(TextBlock $textBlock)
188
    {
189
        return $textBlock->delete();
190
    }
191
192
    /**
193
     * Add image to a project.
194
     *
195
     * @param Project $project   Project to add image to.
196
     * @param array   $imageData Array of image infomation.
197
     *
198
     * @return \Illuminate\Database\Eloquent\Model
199
     */
200
    public function addImageToProject(Project $project, array $imageData)
201
    {
202
        return $project->images()->create($imageData);
203
    }
204
205
    /**
206
     * Update image name and caption.
207
     *
208
     * @param Image $image     Image to update.
209
     * @param array $imageData Array of inmage information.
210
     *
211
     * @return Image
212
     */
213
    public function updateImageInfo(Image $image, array $imageData)
214
    {
215
        $image->update($imageData);
216
217
        return $image;
218
    }
219
220
    /**
221
     * Remove image from storage and delete database info.
222
     *
223
     * @param Image $image Image to remove.
224
     *
225
     * @return bool|null
226
     */
227
    public function removeImage(Image $image)
228
    {
229
        Storage::delete($image->path());
230
231
        return $image->delete();
232
    }
233
234
    /**
235
     * Add a link to a project.
236
     *
237
     * @param Project $project  Project to add link to.
238
     * @param array   $linkData Array of link info.
239
     */
240
    public function addLinkToProject(Project $project, array $linkData)
241
    {
242
        return $project->links()->create($linkData);
243
    }
244
245
    /**
246
     * Update a link.
247
     *
248
     * @param Link  $link     Link to update.
249
     * @param array $linkData Array of link data.
250
     *
251
     * @return Link
252
     */
253
    public function updateLink(Link $link, array $linkData)
254
    {
255
        $link->update($linkData);
256
257
        return $link;
258
    }
259
260
    /**
261
     * Update project links by adding new ones and updating existing ones.
262
     *
263
     * @param Project $project Project that links belong to.
264
     * @param array   $data    Array of project information.
265
     */
266 View Code Duplication
    public function updateProjectLinks(Project $project, array $data)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
267
    {
268
        $linkData = collect($data)->get('links', []);
269
270
        $linkData = $this->setOrder($linkData);
271
272
        foreach ($linkData as $singleLinkData) {
273
            if (isset($singleLinkData['project_id'])) {
274
                $link = Link::find($singleLinkData['id']);
275
276
                $this->updateLink($link, $singleLinkData);
277
            } else {
278
                $this->addLinkToProject($project, $singleLinkData);
279
            }
280
        }
281
    }
282
283
    /**
284
     * Remove link from a project.
285
     *
286
     * @param Link $link Link to remove.
287
     *
288
     * @return bool|null
289
     */
290
    public function removeLink(Link $link)
291
    {
292
        return $link->delete();
293
    }
294
}
295