Passed
Push — feature-FRAM-47-bench ( 315ed6 )
by Vincent
19:59
created

EntityNotTypedArrayMapper::buildFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Bdf\Prime\Bench;
4
5
use Bdf\Prime\Entity\Extensions\ArrayInjector;
6
use Bdf\Prime\Entity\Model;
7
use Bdf\Prime\Mapper\Builder\FieldBuilder;
8
use Bdf\Prime\Mapper\Mapper;
9
use Bdf\Prime\Relations\Builder\RelationBuilder;
10
11
class UserRole
12
{
13
    const ADMINISTRATIVE_MANAGER = '1';
14
    const PROCUREMENT_MANAGER    = '2';
15
    const CHARTERER              = '3';
16
    const CARRIER                = '4';
17
    const MULTISITE_MANAGER      = '5';
18
}
19
20
class Customer extends Model
21
{
22
    use ArrayInjector;
23
    
24
    public $id;
25
    public $name;
26
    public $packs;
27
    
28
    public function __construct(array $attributes = [])
29
    {
30
        $this->import($attributes);
31
    }
32
}
33
34
class Pack extends Model
35
{
36
    use ArrayInjector;
37
    
38
    public $id;
39
    public $label;
40
    
41
    public function __construct(array $attributes = [])
42
    {
43
        $this->import($attributes);
44
    }
45
}
46
47
class CustomerPack extends Model
48
{
49
    use ArrayInjector;
50
    
51
    public $customerId;
52
    public $packId;
53
    
54
    public function __construct(array $attributes = [])
55
    {
56
        $this->import($attributes);
57
    }
58
}
59
60
class User extends Model
61
{
62
    use ArrayInjector;
63
    
64
    public $id;
65
    public $name;
66
    public $customer;
67
    public $roles;
68
    
69
    public function __construct(array $attributes = [])
70
    {
71
        $this->import($attributes);
72
    }
73
}
74
75
class UserMapper extends Mapper
76
{
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function schema(): array
81
    {
82
        return [
83
            'connection' => 'test',
84
            'table'      => 'user',
85
        ];
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function buildFields(FieldBuilder $builder): void
92
    {
93
        $builder
94
            ->bigint('id')
95
                ->primary()
96
                
97
            ->string('name')
98
                
99
            ->searchableArray('roles')
100
                
101
            ->embedded('customer', 'Bdf\Prime\Bench\Customer', function($builder) {
102
                $builder->bigint('id')->alias('customer_id');
103
            })
104
        ;
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function buildRelations(RelationBuilder $builder): void
111
    {
112
        $builder->on('customer')
113
            ->belongsTo('Bdf\Prime\Bench\Customer', 'customer.id');
114
    }
115
}
116
117
class CustomerMapper extends Mapper
118
{
119
    /**
120
     * {@inheritdoc}
121
     */
122
    public function schema(): array
123
    {
124
        return [
125
            'connection' => 'test',
126
            'table'      => 'customer',
127
        ];
128
    }
129
    
130
    /**
131
     * {@inheritdoc}
132
     */
133
    public function buildFields(FieldBuilder $builder): void
134
    {
135
        $builder
136
            ->bigint('id')
137
                ->autoincrement()
138
                
139
            ->string('name')
140
        ;
141
    }
142
    
143
    /**
144
     * {@inheritdoc}
145
     */
146
    public function buildRelations(RelationBuilder $builder): void
147
    {
148
        $builder->on('packs')
149
            ->belongsToMany('Bdf\Prime\Bench\Pack')
150
            ->through('Bdf\Prime\Bench\CustomerPack', 'customerId', 'packId');
151
    }
152
}
153
154
class PackMapper extends Mapper
155
{
156
    /**
157
     * {@inheritdoc}
158
     */
159
    public function schema(): array
160
    {
161
        return [
162
            'connection' => 'test',
163
            'table'      => 'pack',
164
        ];
165
    }
166
    
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function buildFields(FieldBuilder $builder): void
171
    {
172
        $builder
173
            ->integer('id')
174
                ->primary()
175
                
176
            ->string('label')
177
        ;
178
    }
179
}
180
181
class CustomerPackMapper extends Mapper
182
{
183
    /**
184
     * {@inheritdoc}
185
     */
186
    public function schema(): array
187
    {
188
        return [
189
            'connection' => 'test',
190
            'table'      => 'customer_pack',
191
        ];
192
    }
193
    
194
    /**
195
     * {@inheritdoc}
196
     */
197
    public function buildFields(FieldBuilder $builder): void
198
    {
199
        $builder
200
            ->bigint('customerId')
201
                ->primary()->alias('customer_id')
202
                
203
            ->integer('packId')
204
                ->primary()->alias('pack_id')
205
        ;
206
    }
207
}
208
209
class EntityArrayOf extends Model
210
{
211
    use ArrayInjector;
212
213
    public $id;
214
    public $floats = [];
215
    public $booleans = [];
216
    public $dates = [];
217
218
    public function __construct(array $attributes = [])
219
    {
220
        $this->import($attributes);
221
    }
222
}
223
224
class EntityArrayOfMapper extends Mapper
225
{
226
    /**
227
     * @inheritDoc
228
     */
229
    public function schema(): array
230
    {
231
        return [
232
            'connection' => 'test',
233
            'table' => 'array_of_entity'
234
        ];
235
    }
236
237
    /**
238
     * @inheritDoc
239
     */
240
    public function buildFields(FieldBuilder $builder): void
241
    {
242
        $builder
243
            ->integer('id')->autoincrement()
244
            ->arrayOfDouble('floats')
245
            ->arrayOfDateTime('dates')
246
            ->arrayOf('booleans', 'boolean')
247
        ;
248
    }
249
}
250
251
class EntityNotTypedArray extends Model
252
{
253
    use ArrayInjector;
254
255
    public $id;
256
    public $floats = [];
257
    public $booleans = [];
258
    public $dates = [];
259
260
    public function __construct(array $attributes = [])
261
    {
262
        $this->import($attributes);
263
    }
264
}
265
266
class EntityNotTypedArrayMapper extends Mapper
267
{
268
    /**
269
     * @inheritDoc
270
     */
271
    public function schema(): array
272
    {
273
        return [
274
            'connection' => 'test',
275
            'table' => 'array_not_typed_entity'
276
        ];
277
    }
278
279
    /**
280
     * @inheritDoc
281
     */
282
    public function buildFields(FieldBuilder $builder): void
283
    {
284
        $builder
285
            ->integer('id')->autoincrement()
286
            ->simpleArray('floats')
287
            ->simpleArray('dates')
288
            ->simpleArray('booleans')
289
        ;
290
    }
291
}
292