BelongsTo::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
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 25
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 BelongsTo extends Relation
19
{
20
    use InverseTrait;
21
22
    protected const TYPE = 'belongsTo';
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 array|non-empty-string|null $innerKey Inner key in source entity. Defaults to {relationName}_{outerKey}.
27
     * @param array|non-empty-string|null $outerKey Outer key in the related entity. Defaults to the primary key.
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 bool $fkCreate Set to true to automatically create FK on innerKey.
31
     * @param non-empty-string $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 innerKey.
35
     * @param non-empty-string $load Relation load approach.
36
     */
37 616
    public function __construct(
38
        string $target,
39
        protected array|string|null $innerKey = null,
40
        protected array|string|null $outerKey = null,
41
        protected bool $cascade = true,
42
        protected bool $nullable = false,
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 616
        $this->inverse = $inverse;
60
61 616
        parent::__construct($target, $load);
62 616
    }
63
}
64