SearchForm::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace KGzocha\Bundle\SearcherBundle\Form;
4
5
use KGzocha\Searcher\Criteria\Collection\NamedCriteriaCollection;
6
use Symfony\Component\Form\AbstractType;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
/**
10
 * @author Krzysztof Gzocha <[email protected]>
11
 */
12
abstract class SearchForm extends AbstractType
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function configureOptions(OptionsResolver $resolver)
18
    {
19
        $resolver->setDefault(
20
            'data_class',
21
            NamedCriteriaCollection::class
22
        );
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getName()
29
    {
30
        return '';
31
    }
32
33
    /**
34
     * Will return string that can be used to configure "property_path" parameter
35
     * of single field in a form.
36
     *
37
     * @param string      $criteriaName is a name of criteria
38
     * @param string|null $propertyName is a name of parameter inside criteria.
39
     *                                  If null $modelName will be used
40
     *
41
     * @return string
42
     */
43
    protected function getPath($criteriaName, $propertyName = null)
44
    {
45
        if (!$propertyName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $propertyName of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
46
            $propertyName = $criteriaName;
47
        }
48
49
        return sprintf('criteria[%s].%s', $criteriaName, $propertyName);
50
    }
51
}
52