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

LocatorForm::__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
/**
4
 * Class LocatorForm
5
 */
6 View Code Duplication
class LocatorForm extends Form
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...
7
{
8
9
    /**
10
     * LocatorForm constructor.
11
     * @param Controller $controller
12
     * @param string $name
13
     */
14
    public function __construct(Controller $controller, $name)
15
    {
16
17
        $fields = FieldList::create(
18
            TextField::create('Address')
19
                ->setTitle('')
20
                ->setAttribute('placeholder', 'address or zip code')
21
        );
22
23
        $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...
24
            ? Locator::locator_categories_by_locator($controller->data()->ID)
25
            : Locator::get_all_categories();
26
27
        $categoriesField = DropdownField::create('CategoryID')
28
            ->setTitle('')
29
            ->setEmptyString('All Categories')
30
            ->setSource($categories->map());
31
32
        $fields->push($categoriesField);
33
34
        $this->extend('updateLocatorFormFields', $fields);
35
36
        $actions = FieldList::create(
37
            FormAction::create('doFilterLocations')
38
                ->setTitle('Search')
39
        );
40
41
        $this->extend('updateLocatorFormActions', $actions);
42
43
        $validator = RequiredFields::create();
44
45
        $this->extend('updateLocatorFormRequiredFields', $validator);
46
47
        parent::__construct($controller, $name, $fields, $actions, $validator);
48
    }
49
50
}