Passed
Push — master ( 81f334...c86e8c )
by Mihail
03:35
created

Content::actionGalleryupload()   C

Complexity

Conditions 13
Paths 20

Size

Total Lines 73
Code Lines 37

Duplication

Lines 3
Ratio 4.11 %

Importance

Changes 0
Metric Value
cc 13
eloc 37
nc 20
nop 1
dl 3
loc 73
rs 5.4475
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Apps\Controller\Api;
4
5
use Apps\ActiveRecord\App as AppRecord;
6
use Extend\Core\Arch\ApiController;
7
8
/**
9
 * Class Content. Content app backend json api
10
 * @package Apps\Controller\Api
11
 */
12
class Content extends ApiController
13
{
14
    public $maxSize = 512000; // in bytes, 500 * 1024
15
    public $maxResize = 150;
16
17
    public $allowedExt = ['jpg', 'png', 'gif', 'jpeg', 'bmp', 'webp'];
18
19
    // import actions from traits
20
    use Content\ActionChangeRate {
21
        changeRate as actionChangerate;
22
    }
23
24
    use Content\ActionGalleryUpload {
25
        galleryUpload as actionGalleryupload;
26
    }
27
28
    use Content\ActionGalleryList {
29
        galleryList as actionGallerylist;
30
    }
31
32
    use Content\ActionGalleryDelete {
33
        galleryDelete as actionGallerydelete;
34
    }
35
36
    /**
37
     * Prepare configurations before initialization
38
     */
39
    public function before()
40
    {
41
        parent::before();
42
        $configs = AppRecord::getConfigs('app', 'Content');
43
        // prevent null-type config data
44
        if ((int)$configs['gallerySize'] > 0) {
45
            $this->maxSize = (int)$configs['gallerySize'] * 1024;
46
        }
47
48
        if ((int)$configs['galleryResize'] > 0) {
49
            $this->maxResize = (int)$configs['galleryResize'];
50
        }
51
    }
52
}
53