Logos   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 25
c 1
b 0
f 1
dl 0
loc 45
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A uploadLogo() 0 19 3
A removeLogo() 0 15 2
1
<?php
2
3
namespace ByTIC\MediaLibraryModule\Controllers\Traits\Async;
4
5
/**
6
 * Class Logos
7
 * @package ByTIC\MediaLibraryModule\Controllers\Traits\Async
8
 */
9
trait Logos
10
{
11
    public function uploadLogo()
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
        $type = $_REQUEST['type'];
16
        if (in_array($type, $item->logoTypes)) {
17
            $image = $item->uploadLogo($type);
18
19
            if (is_object($image)) {
20
                $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...
21
                $response['url'] = $image->getUrl();
22
                $response['path'] = $image->getPath();
23
                $response['imageType'] = $image->getImageType();
24
                $this->setResponseValues($response);
25
            } else {
26
                $this->sendError($item->errors['upload']);
0 ignored issues
show
Bug introduced by
It seems like sendError() 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

26
                $this->/** @scrutinizer ignore-call */ 
27
                       sendError($item->errors['upload']);
Loading history...
27
            }
28
        } else {
29
            $this->sendError('bad logo type');
30
        }
31
    }
32
33
    /**
34
     * @param $values
35
     * @return void
36
     */
37
    abstract public function setResponseValues($values);
38
39
    public function removeLogo()
40
    {
41
        $item = $this->getModelFromRequest();
42
43
        if ($item->removeLogo($_REQUEST)) {
44
            $response['message'] = 'Logo sters';
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...
45
        } else {
46
            $response['message'] = 'Logo-ul convertit la default';
47
        }
48
49
        $image = $item->getLogo($_REQUEST['type']);
50
        $response['type'] = 'success';
51
        $response['url'] = $image->getUrl();
52
        $response['path'] = $image->getPath();
53
        $this->setResponseValues($response);
54
    }
55
}
56