Completed
Push — master ( fbfc98...86fc64 )
by Jason
9s
created

PhotoGalleryBlock   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 51
loc 51
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A singular_name() 4 4 1
A plural_name() 4 4 1
A getCMSFields() 22 22 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3 View Code Duplication
class PhotoGalleryBlock extends Block
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
4
{
5
    /**
6
     * @return string
7
     */
8 10
    public function singular_name()
9
    {
10 10
        return _t('PhotoGalleryBlock.SINGULARNAME', 'Photo Gallery Block');
11
    }
12
13
    /**
14
     * @return string
15
     */
16 1
    public function plural_name()
17
    {
18 1
        return _t('PhotoGalleryBlock.PLURALNAME', 'Photo Gallery Blocks');
19
    }
20
21
    /**
22
     * @var array
23
     */
24
    private static $has_many = array(
25
        'Images' => 'PhotoGalleryBlockImage'
26
    );
27
28
    /**
29
     * @return FieldList
30
     */
31 1
    public function getCMSFields()
32
    {
33 1
        $fields = parent::getCMSFields();
34
35 1
        $fields->removeByName([
36 1
            'Images',
37 1
        ]);
38
39 1
        if ($this->owner->ID) {
0 ignored issues
show
Documentation introduced by
The property owner does not exist on object<PhotoGalleryBlock>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
40 1
            $config = GridFieldConfig_RecordEditor::create();
41 1
            $config->addComponent(new GridFieldOrderableRows('SortOrder'));
42 1
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
43 1
            $config->removeComponentsByType('GridFieldDeleteAction');
44 1
            $config->addComponent(new GridFieldDeleteAction(false));
45 1
            $imagesField = GridField::create('Images', 'Images', $this->Images()->sort('SortOrder'), $config);
0 ignored issues
show
Documentation Bug introduced by
The method Images does not exist on object<PhotoGalleryBlock>? 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...
46
47 1
            $fields->addFieldToTab('Root.Photos', $imagesField);
48
49 1
        }
50
51 1
        return $fields;
52
    }
53
}
54
55
class PhotoGalleryBlock_Controller extends Block_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
56
{
57
    /**
58
     *
59
     */
60
    public function init()
61
    {
62
        Requirements::css('dynamic-blocks/thirdparty/lightbox/lightbox.css');
63
        Requirements::javascript('dynamic-blocks/thirdparty/lightbox/lightbox.min.js');
64
    }
65
}