Files   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
dl 0
loc 35
rs 10
c 1
b 0
f 1
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A uploadAttachment() 0 17 2
A removeFile() 0 8 2
1
<?php
2
3
namespace ByTIC\MediaLibraryModule\Controllers\Traits\Async;
4
5
/**
6
 * Class Files
7
 * @package ByTIC\MediaLibraryModule\Controllers\Traits\Async
8
 */
9
trait Files
10
{
11
    public function uploadAttachment()
12
    {
13
        $item = $this->getModelFromRequest();
0 ignored issues
show
Bug introduced by
It seems like getModelFromRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        /** @scrutinizer ignore-call */ 
14
        $item = $this->getModelFromRequest();
Loading history...
14
15
        $file = $item->uploadFile($_FILES['Filedata']);
16
17
        if ($file) {
18
            $response['type'] = 'success';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.
Loading history...
19
            $response['url'] = $file->getURL();
20
            $response['name'] = $file->getName();
21
            $response['extension'] = $file->getExtension();
22
            $response['size'] = $file->formatSize();
23
            $response['time'] = date("d.m.Y H:i", $file->getTime());
24
        } else {
25
            $response['type'] = 'error';
26
        }
27
        $this->setResponseValues($response);
28
    }
29
30
    /**
31
     * @param $values
32
     * @return void
33
     */
34
    abstract public function setResponseValues($values);
35
36
    public function removeFile()
37
    {
38
        $item = $this->getModelFromRequest();
39
40
        if ($item->removeFile($_POST)) {
41
            $response['type'] = 'success';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.
Loading history...
42
        }
43
        $this->setResponseValues($response);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $response does not seem to be defined for all execution paths leading up to this point.
Loading history...
44
    }
45
}
46