LocatorFormExtension::updateLocatorFormFields()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Dynamic\Locator\React\Extensions;
4
5
use Dynamic\Locator\LocatorForm;
6
use SilverStripe\Core\Extension;
7
use SilverStripe\Forms\FieldList;
8
9
/**
10
 * Class LocatorFormExtension
11
 * @package Dynamic\Locator\React\Extensions
12
 *
13
 * @property-read LocatorForm|LocatorFormExtension $owner
14
 */
15
class LocatorFormExtension extends Extension
16
{
17
    /**
18
     * @param FieldList $fields
19
     */
20
    public function updateLocatorFormFields($fields)
21
    {
22
        if (!$fields->fieldByName('Address')) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $fields->fieldByName('Address') targeting SilverStripe\Forms\FieldList::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
23
            return;
24
        }
25
26
        $address = $fields->fieldByName('Address');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $address is correct as $fields->fieldByName('Address') targeting SilverStripe\Forms\FieldList::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
27
        if ($this->owner->getController()->Autocomplete) {
0 ignored issues
show
Bug introduced by
The method getController() does not exist on Dynamic\Locator\React\Ex...ns\LocatorFormExtension. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        if ($this->owner->/** @scrutinizer ignore-call */ getController()->Autocomplete) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
            $address->setSchemaComponent('AutoComplete');
29
        }
30
    }
31
}
32