MorphedHasMany::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 12
dl 0
loc 18
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0

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 Cycle\Annotated\Annotation\Relation\Morphed;
6
7
use Cycle\Annotated\Annotation\Relation\Inverse;
8
use Cycle\Annotated\Annotation\Relation\Relation;
9
use Cycle\Annotated\Annotation\Relation\Traits\InverseTrait;
10
use JetBrains\PhpStorm\ExpectedValues;
11
use Spiral\Attributes\NamedArgumentConstructor;
12
13
/**
14
 * @Annotation
15
 * @NamedArgumentConstructor
16
 * @Target("PROPERTY")
17
 */
18
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
19
final class MorphedHasMany extends Relation
20
{
21
    use InverseTrait;
22
23
    protected const TYPE = 'morphedHasMany';
24
25
    /**
26
     * @param non-empty-string $target
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
27
     * @param bool $cascade Automatically save related data with parent entity.
28
     * @param bool $nullable Defines if the relation can be nullable (child can have no parent).
29
     * @param array|string|null $innerKey Inner key in parent entity. Defaults to the primary key.
30
     * @param array|string|null $outerKey Outer key name. Defaults to `{parentRole}_{innerKey}`.
31
     * @param string $morphKey Name of key to store related entity role. Defaults to `{relationName}_role`.
32
     * @param int $morphKeyLength The length of morph key.
33
     * @param array $where Additional where condition to be applied for the relation.
34
     * @param bool $indexCreate Create an index on morphKey and innerKey.
35
     * @param string|null $collection Collection that will contain loaded entities.
36
     * @param non-empty-string $load Relation load approach.
37
     * @param Inverse|null $inverse
38
     */
39 496
    public function __construct(
40
        string $target,
41
        protected bool $cascade = true,
42
        protected bool $nullable = false,
43
        protected array|string|null $innerKey = null,
44
        protected array|string|null $outerKey = null,
45
        protected ?string $morphKey = null,
46
        protected int $morphKeyLength = 32,
47
        protected array $where = [],
48
        protected bool $indexCreate = true,
49
        protected ?string $collection = null,
50
        #[ExpectedValues(values: ['lazy', 'eager'])]
51
        string $load = 'lazy',
52
        ?Inverse $inverse = null,
53
    ) {
54 496
        $this->inverse = $inverse;
55
56 496
        parent::__construct($target, $load);
57 496
    }
58
}
59