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

LocatorBootstrapForm::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 35
Code Lines 21

Duplication

Lines 35
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 35
loc 35
rs 8.8571
cc 2
eloc 21
nc 2
nop 2
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
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
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
}