BelongsToMorphed::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
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 10
dl 0
loc 16
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 Doctrine\Common\Annotations\Annotation\Target;
11
use JetBrains\PhpStorm\ExpectedValues;
12
use Spiral\Attributes\NamedArgumentConstructor;
13
14
/**
15
 * @Annotation
16
 * @NamedArgumentConstructor
17
 * @Target("PROPERTY")
18
 */
19
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
20
final class BelongsToMorphed extends Relation
21
{
22
    use InverseTrait;
23
24
    protected const TYPE = 'belongsToMorphed';
25
26
    /**
27
     * @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...
28
     * @param bool $cascade Automatically save related data with source entity.
29
     * @param bool $nullable Defines if the relation can be nullable (child can have no parent).
30
     * @param array|string|null $innerKey Inner key in source entity. Defaults to `{relationName}_{outerKey}`.
31
     * @param array|string|null $outerKey Outer key in the related entity. Defaults to primary key.
32
     * @param string $morphKey Name of key to store related entity role. Defaults to `{relationName}_role`.
33
     * @param int $morphKeyLength The length of morph key.
34
     * @param bool $indexCreate Create an index on morphKey and innerKey.
35
     * @param non-empty-string $load Relation load approach.
36
     */
37 592
    public function __construct(
38
        string $target,
39
        protected bool $cascade = true,
40
        protected bool $nullable = true,
41
        protected array|string|null $innerKey = null,
42
        protected array|string|null $outerKey = null,
43
        protected ?string $morphKey = null,
44
        protected int $morphKeyLength = 32,
45
        protected bool $indexCreate = true,
46
        #[ExpectedValues(values: ['lazy', 'eager'])]
47
        string $load = 'lazy',
48
        ?Inverse $inverse = null
49
    ) {
50 592
        $this->inverse = $inverse;
51
52 592
        parent::__construct($target, $load);
53 592
    }
54
}
55