Completed
Push — master ( 83571a...9e9b74 )
by Nic
30s
created

LocatorBootstrapForm   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 6
dl 45
loc 45
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 35 35 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
if (class_exists('BootstrapForm')) {
4
5
    /**
6
     * Class LocatorForm
7
     */
8 View Code Duplication
    class LocatorBootstrapForm extends BootstrapForm
0 ignored issues
show
Duplication introduced by muskie9
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...
9
    {
10
11
        /**
12
         * LocatorForm constructor.
13
         * @param Controller $controller
14
         * @param string $name
15
         */
16
        public function __construct(Controller $controller, $name)
17
        {
18
19
            $fields = FieldList::create(
20
                TextField::create('Address')
21
                    ->setTitle('')
22
                    ->setAttribute('placeholder', 'address or zip code')
23
            );
24
25
            $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
0 ignored issues
show
Bug introduced by muskie9
The method count cannot be called on \Locator::locator_catego...controller->data()->ID) (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
26
                ? Locator::locator_categories_by_locator($controller->data()->ID)
27
                : Locator::get_all_categories();
28
29
            $categoriesField = DropdownField::create('CategoryID')
30
                ->setTitle('')
31
                ->setEmptyString('All Categories')
32
                ->setSource($categories->map());
33
34
            $fields->push($categoriesField);
35
36
            $this->extend('updateLocatorFormFields', $fields);
37
38
            $actions = FieldList::create(
39
                FormAction::create('doFilterLocations')
40
                    ->setTitle('Search')
41
            );
42
43
            $this->extend('updateLocatorFormActions', $actions);
44
45
            $validator = RequiredFields::create();
46
47
            $this->extend('updateLocatorFormRequiredFields', $validator);
48
49
            parent::__construct($controller, $name, $fields, $actions, $validator);
50
        }
51
52
    }
53
54
}