Completed
Pull Request — master (#62)
by Jason
15:39
created

PhotoGalleryBlockImage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 110
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 16 1
A canCreate() 0 4 1
A canView() 0 4 1
A canEdit() 0 4 1
A canDelete() 0 4 1
1
<?php
2
3
namespace Dynamic\DynamicBlocks\Model;
4
5
use Dynamic\DynamicBlocks\Block\PhotoGalleryBlock;
6
use SilverStripe\Assets\Image;
7
use SilverStripe\ORM\DataObject;
8
9
class PhotoGalleryBlockImage extends DataObject
10
{
11
    /**
12
     * @var string
13
     */
14
    private static $singular_name = 'Gallery Image';
15
16
    /**
17
     * @var string
18
     */
19
    private static $plural_name = 'Gallery Images';
20
21
    /**
22
     * @var array
23
     */
24
    private static $db = array(
25
        'Title' => 'Varchar(255)',
26
        'Content' => 'HTMLText',
27
        'SortOrder' => 'Int',
28
    );
29
30
    /**
31
     * @var array
32
     */
33
    private static $has_one = array(
34
        'PhotoGallery' => PhotoGalleryBlock::class,
35
        'Image' => Image::class,
36
    );
37
38
    /**
39
     * @var array
40
     */
41
    private static $summary_fields = array(
42
        'Image.CMSThumbnail' => 'Image',
43
        'Title' => 'Title',
44
    );
45
46
    /**
47
     * @var array
48
     */
49
    private static $searchable_fields = array(
50
        'Title',
51
        'Content',
52
    );
53
54
    /**
55
     * @return \SilverStripe\Forms\FieldList
56
     */
57
    public function getCMSFields()
58 1
    {
59
        $fields = parent::getCMSFields();
60 1
61
        $fields->removeByName(array(
62 1
            'SortOrder',
63 1
            'PhotoGalleryID',
64 1
        ));
65 1
66
        $image = $fields->dataFieldByName('Image')
67 1
        //    ->setFolderName('Uploads/Blocks/PhotoGallery/')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
68 1
        ;
69
        $fields->insertBefore($image, 'Content');
0 ignored issues
show
Documentation introduced by
$image is of type object<SilverStripe\Forms\FormField>|null, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'Content' is of type string, but the function expects a object<SilverStripe\Forms\FormField>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70 1
71
        return $fields;
72
    }
73
74
    /**
75
     * @param null $member
76
     *
77
     * @return bool
78 1
     */
79
    public function canCreate($member = null, $context = [])
80 1
    {
81
        return true;
82
    }
83
84
    /**
85
     * @param null $member
86
     *
87
     * @return bool
88 1
     */
89
    public function canView($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90 1
    {
91
        return true;
92
    }
93
94
    /**
95
     * @param null $member
96
     *
97
     * @return bool
98 1
     */
99
    public function canEdit($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100 1
    {
101
        return true;
102
    }
103
104
    /**
105
     * @param null $member
106
     *
107
     * @return bool
108 1
     */
109
    public function canDelete($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
110 1
    {
111
        return true;
112
    }
113
}
114