RefersTo::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
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 11
dl 0
loc 24
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;
6
7
use Cycle\Annotated\Annotation\Relation\Traits\InverseTrait;
8
use Doctrine\Common\Annotations\Annotation\Enum;
9
use JetBrains\PhpStorm\ExpectedValues;
10
use Spiral\Attributes\NamedArgumentConstructor;
11
12
/**
13
 * @Annotation
14
 * @NamedArgumentConstructor
15
 * @Target("PROPERTY")
16
 */
17
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
18
final class RefersTo extends Relation
19
{
20
    use InverseTrait;
21
22
    protected const TYPE = 'refersTo';
23
24
    /**
25
     * @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...
26
     * @param bool $cascade Automatically save related data with parent entity.
27
     * @param bool $nullable Defines if the relation can be nullable (child can have no parent).
28
     * @param array|non-empty-string|null $innerKey Inner key in parent entity.
29
     * @param array|non-empty-string|null $outerKey Outer key name. Defaults to {parentRole}_{innerKey}.
30
     * @param bool $fkCreate Set to true to automatically create FK on outerKey.
31
     * @param non-empty-string|null $fkAction FK onDelete and onUpdate action.
32
     * @param non-empty-string|null $fkOnDelete FK onDelete action. It has higher priority than {@see $fkAction}.
33
     *        Defaults to {@see $fkAction}.
34
     * @param bool $indexCreate Create an index on outerKey.
35
     * @param non-empty-string $load Relation load approach.
36
     */
37 520
    public function __construct(
38
        string $target,
39
        protected bool $cascade = true,
40
        protected bool $nullable = false,
41
        protected array|string|null $innerKey = null,
42
        protected array|string|null $outerKey = null,
43
        protected bool $fkCreate = true,
44
        /**
45
         * @Enum({"NO ACTION", "CASCADE", "SET NULL"})
46
         */
47
        #[ExpectedValues(values: ['NO ACTION', 'CASCADE', 'SET NULL'])]
48
        protected ?string $fkAction = 'CASCADE',
49
        /**
50
         * @Enum({"NO ACTION", "CASCADE", "SET NULL"})
51
         */
52
        #[ExpectedValues(values: ['NO ACTION', 'CASCADE', 'SET NULL'])]
53
        protected ?string $fkOnDelete = null,
54
        protected bool $indexCreate = true,
55
        #[ExpectedValues(values: ['lazy', 'eager'])]
56
        string $load = 'lazy',
57
        ?Inverse $inverse = null
58
    ) {
59 520
        $this->inverse = $inverse;
60 520
        parent::__construct($target, $load);
61 520
    }
62
}
63