HasMany::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
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 14
dl 0
loc 28
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 JetBrains\PhpStorm\ExpectedValues;
9
use Spiral\Attributes\NamedArgumentConstructor;
10
11
/**
12
 * @Annotation
13
 * @NamedArgumentConstructor
14
 * @Target("PROPERTY")
15
 */
16
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
17
final class HasMany extends Relation
18
{
19
    use InverseTrait;
20
21
    protected const TYPE = 'hasMany';
22
23
    /**
24
     * @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...
25
     * @param array|non-empty-string|null $innerKey Inner key in parent entity. Defaults to the primary key.
26
     * @param array|non-empty-string|null $outerKey Outer key name. Defaults to {parentRole}_{innerKey}.
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 $where Additional where condition to be applied for the relation.
30
     * @param array $orderBy Additional sorting rules.
31
     * @param bool $fkCreate Set to true to automatically create FK on outerKey.
32
     * @param non-empty-string|null $fkAction FK onDelete and onUpdate action.
33
     * @param non-empty-string|null $fkOnDelete FK onDelete action. It has higher priority than {@see $fkAction}.
34
     *        Defaults to {@see $fkAction}.
35
     * @param bool $indexCreate Create an index on outerKey.
36
     * @param non-empty-string|null $collection Collection that will contain loaded entities.
37
     * @param non-empty-string $load Relation load approach.
38
     */
39 544
    public function __construct(
40
        string $target,
41
        protected array|string|null $innerKey = null,
42
        protected array|string|null $outerKey = null,
43
        protected bool $cascade = true,
44
        protected bool $nullable = false,
45
        protected array $where = [],
46
        protected array $orderBy = [],
47
        protected bool $fkCreate = true,
48
        /**
49
         * @Enum({"NO ACTION", "CASCADE", "SET NULL"})
50
         */
51
        #[ExpectedValues(values: ['NO ACTION', 'CASCADE', 'SET NULL'])]
52
        protected ?string $fkAction = 'CASCADE',
53
        /**
54
         * @Enum({"NO ACTION", "CASCADE", "SET NULL"})
55
         */
56
        #[ExpectedValues(values: ['NO ACTION', 'CASCADE', 'SET NULL'])]
57
        protected ?string $fkOnDelete = null,
58
        protected bool $indexCreate = true,
59
        protected ?string $collection = null,
60
        #[ExpectedValues(values: ['lazy', 'eager'])]
61
        string $load = 'lazy',
62
        ?Inverse $inverse = null,
63
    ) {
64 544
        $this->inverse = $inverse;
65
66 544
        parent::__construct($target, $load);
67 544
    }
68
}
69