MappedProperty::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 11
c 1
b 1
f 0
nc 1
nop 11
dl 0
loc 24
rs 9.9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Metadata\Property;
6
7
class MappedProperty extends AbstractProperty
8
{
9
    public function __construct(
10
        string $name,
11
        ?string $propertyPath,
12
        ?string $label = null,
13
        ?string $template = '@LAGAdmin/grid/properties/mapped.html.twig',
14
        bool $mapped = true,
15
        bool $sortable = true,
16
        bool $translation = false,
17
        ?string $translationDomain = 'admin',
18
        array $attr = [],
19
        array $headerAttr = [],
20
        private array $map = [],
21
    ) {
22
        parent::__construct(
23
            $name,
24
            $propertyPath,
25
            $label,
26
            $template,
27
            $mapped,
28
            $sortable,
29
            $translation,
30
            $translationDomain,
31
            $attr,
32
            $headerAttr,
33
        );
34
    }
35
36
    public function getMap(): array
37
    {
38
        return $this->map;
39
    }
40
41
    public function withMap(array $map): self
42
    {
43
        $self = clone $this;
44
        $self->map = $map;
45
46
        return $self;
47
    }
48
}
49