Covers::cropCover()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 12
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace ByTIC\MediaLibraryModule\Controllers\Traits\Async;
4
5
/**
6
 * Class Covers
7
 * @package ByTIC\MediaLibraryModule\Controllers\Traits\Async
8
 */
9
trait Covers
10
{
11
    public function uploadCover()
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
        $cover = $item->uploadCover();
16
17
        if (is_object($cover)) {
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'] = $cover->url;
20
            $response['path'] = $cover->name;
21
            $response['width'] = $cover->cropWidth;
22
            $response['height'] = $cover->cropHeight;
23
        }
24
25
        $response['message'] = $item->errors['upload'];
26
        $this->setResponseValues($response);
27
    }
28
29
    /**
30
     * @param $values
31
     * @return void
32
     */
33
    abstract public function setResponseValues($values);
34
35
    public function cropCover()
36
    {
37
        $item = $this->checkItem($_POST);
0 ignored issues
show
Bug introduced by
It seems like checkItem() 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

37
        /** @scrutinizer ignore-call */ 
38
        $item = $this->checkItem($_POST);
Loading history...
38
39
        $cover = $item->cropCovers($_POST);
40
41
        if ($cover) {
42
            $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...
43
            $response['url'] = $cover->url;
44
            $response['name'] = $cover->name;
45
        }
46
        $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...
47
    }
48
49
    public function setDefaultCover()
50
    {
51
        $item = $this->getModelFromRequest();
52
53
        if ($item->setDefaultCover($_POST)) {
54
            $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...
55
        }
56
        $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...
57
    }
58
59
    public function removeCover()
60
    {
61
        $item = $this->getModelFromRequest();
62
63
        if ($item->removeCover($_POST)) {
64
            $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...
65
        }
66
        $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...
67
    }
68
}
69