ImageSliderItem   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A singular_name() 0 3 1
A plural_name() 0 3 1
A getCMSFields() 0 18 1
A getSliderImage() 0 7 2
1
<?php
2
3
/**
4
 * @author    Donatas Navidonskis <[email protected]>
5
 * @since     2017
6
 * @class     ImageSliderItem
7
 *
8
 * @property int PictureID
9
 *
10
 * @method Image Picture
11
 */
12
class ImageSliderItem extends BaseSliderItem {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
14
    /**
15
     * @var array
16
     * @config
17
     */
18
    private static $has_one = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'Picture' => 'Image',
20
    ];
21
22
    /**
23
     * @return string
24
     */
25
    public function singular_name() {
26
        return _t('ImageSliderItem.SINGULARNAME', 'Image slider');
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function plural_name() {
33
        return _t('ImageSliderItem.PLURALNAME', 'Image sliders');
34
    }
35
36
    /**
37
     * @return \FieldList
38
     */
39
    public function getCMSFields() {
40
        $fields = parent::getCMSFields();
41
        $fields->removeByName(['Picture']);
42
        $fields->findOrMakeTab('Root.Media', $this->fieldLabel('Media'));
43
44
        $fields->addFieldToTab('Root.Media', $uploadField = UploadField::create('Picture', $this->fieldLabel('Picture')));
45
46
        $uploadField
47
            ->setAllowedMaxFileNumber(1)
48
            ->setAllowedFileCategories('image')
49
            ->setFolderName(
50
                sprintf('%s/Sliders', BaseBlock::config()->upload_directory)
51
            );
52
53
        $this->extend('updateCMSFields', $fields);
54
55
        return $fields;
56
    }
57
58
    /**
59
     * @return Image|false
60
     */
61
    public function getSliderImage() {
62
        if ($this->Picture()->exists()) {
0 ignored issues
show
Documentation Bug introduced by
The method Picture does not exist on object<ImageSliderItem>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
63
            return $this->Picture();
0 ignored issues
show
Documentation Bug introduced by
The method Picture does not exist on object<ImageSliderItem>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
64
        }
65
66
        return false;
67
    }
68
}