AbstractRelation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 18
rs 10
cc 1
nc 1
nop 8

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
 *
4
 * This file is part of the Aura project for PHP.
5
 *
6
 * @package Aura.Marshal
7
 *
8
 * @license https://opensource.org/licenses/mit-license.php MIT
9
 *
10
 */
11
namespace Aura\Marshal\Relation;
12
13
use Aura\Marshal\Exception;
14
use Aura\Marshal\Manager;
15
use Aura\Marshal\Type\GenericType;
16
17
/**
18
 *
19
 * Represents a relationship definition between two types.
20
 *
21
 * @package Aura.Marshal
22
 *
23
 */
24
abstract class AbstractRelation
25
{
26
    /**
27
     *
28
     * The field in the native entity to match against.
29
     *
30
     * @var string
31
     *
32
     */
33
    protected $native_field;
34
35
    /**
36
     *
37
     * The foreign type object.
38
     *
39
     * @var GenericType
40
     *
41
     */
42
    protected $foreign;
43
44
    /**
45
     *
46
     * The name of the foreign type.
47
     *
48
     * @var string
49
     *
50
     */
51
    protected $foreign_type;
52
53
    /**
54
     *
55
     * The field in the foreign entity to match against.
56
     *
57
     * @var string
58
     *
59
     */
60
    protected $foreign_field;
61
62
    /**
63
     *
64
     * The through type object.
65
     *
66
     * @var ?GenericType
67
     *
68
     */
69
    protected $through;
70
71
    /**
72
     *
73
     * Native and foreign entities are mapped to each other through this
74
     * association type.
75
     *
76
     * @var ?string
77
     *
78
     */
79
    protected $through_type;
80
81
    /**
82
     *
83
     * The field name for the native side of the association mapping in the
84
     * "through" type.
85
     *
86
     * @var ?string
87
     *
88
     */
89
    protected $through_native_field;
90
91
    /**
92
     *
93
     * The field name for the foreign side of the association mapping in the
94
     * "through" type.
95
     *
96
     * @var ?string
97
     *
98
     */
99
    protected $through_foreign_field;
100
101
    /**
102
     *
103
     * Constructor.
104
     *
105
     * @param string $native_field The name of the native field.
106
     *
107
     * @param GenericType $foreign The foreign type object.
108
     *
109
     * @param string $foreign_type The manager name of the foreign type.
110
     *
111
     * @param string $foreign_field The name of the foreign field.
112
     *
113
     * @param GenericType $through The through type object.
114
     *
115
     * @param ?string $through_type The manager name of the through type.
116
     *
117
     * @param ?string $through_native_field The name of the native field in
118
     * the through type.
119
     *
120
     * @param ?string $through_foreign_field The name of the foreign field in
121
     * the through type.
122
     *
123
     */
124
    public function __construct(
125
        $native_field,
126
        GenericType $foreign,
127
        $foreign_type,
128
        $foreign_field,
129
        ?GenericType $through = null,
130
        $through_type = null,
131
        $through_native_field = null,
132
        $through_foreign_field = null
133
    ) {
134
        $this->native_field          = $native_field;
135
        $this->foreign               = $foreign;
136
        $this->foreign_type          = $foreign_type;
137
        $this->foreign_field         = $foreign_field;
138
        $this->through               = $through;
139
        $this->through_type          = $through_type;
140
        $this->through_native_field  = $through_native_field;
141
        $this->through_foreign_field = $through_foreign_field;
142
    }
143
144
    /**
145
     *
146
     * Gets the name of the foreign type in the manager.
147
     *
148
     * @return string
149
     *
150
     */
151
    public function getForeignType()
152
    {
153
        return $this->foreign_type;
154
    }
155
}
156