Completed
Branch FET-10857-model-field-factory (305899)
by
unknown
57:17 queued 45:28
created

ModelFieldFactory::createDatetimeField()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
nop 9
dl 0
loc 26
rs 8.8571
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
namespace EventEspresso\core\services\database;
4
5
use EE_All_Caps_Text_Field;
6
use EE_Any_Foreign_Model_Name_Field;
7
use EE_Boolean_Field;
8
use EE_Datetime_Field;
9
use EE_DB_Only_Float_Field;
10
use EE_DB_Only_Int_Field;
11
use EE_DB_Only_Text_Field;
12
use EE_Email_Field;
13
use EE_Enum_Integer_Field;
14
use EE_Enum_Text_Field;
15
use EE_Error;
16
use EE_Float_Field;
17
use EE_Foreign_Key_Int_Field;
18
use EE_Foreign_Key_String_Field;
19
use EE_Full_HTML_Field;
20
use EE_Infinite_Integer_Field;
21
use EE_Integer_Field;
22
use EE_Maybe_Serialized_Simple_HTML_Field;
23
use EE_Maybe_Serialized_Text_Field;
24
use EE_Money_Field;
25
use EE_Plain_Text_Field;
26
use EE_Post_Content_Field;
27
use EE_Primary_Key_Int_Field;
28
use EE_Primary_Key_String_Field;
29
use EE_Serialized_Text_Field;
30
use EE_Simple_HTML_Field;
31
use EE_Slug_Field;
32
use EE_Trashed_Flag_Field;
33
use EE_WP_Post_Status_Field;
34
use EE_WP_Post_Type_Field;
35
use EE_WP_User_Field;
36
use EventEspresso\core\exceptions\InvalidDataTypeException;
37
use EventEspresso\core\exceptions\InvalidInterfaceException;
38
use EventEspresso\core\services\loaders\LoaderFactory;
39
use EventEspresso\core\services\loaders\LoaderInterface;
40
use InvalidArgumentException;
41
42
defined('EVENT_ESPRESSO_VERSION') || exit;
43
44
45
/**
46
 * Class ModelFieldFactory
47
 * Factory class for generating Model Field objects
48
 *
49
 * @package EventEspresso\core\services\database
50
 * @author  Brent Christensen
51
 * @since   4.9.45
52
 */
53
class ModelFieldFactory
54
{
55
56
    /**
57
     * @var LoaderInterface $loader
58
     */
59
    private $loader;
60
61
62
63
    /**
64
     * ModelFieldFactory constructor.
65
     *
66
     * @param LoaderInterface $loader
67
     */
68
    public function __construct(LoaderInterface $loader)
69
    {
70
        $this->loader = $loader;
71
    }
72
73
74
75
    /**
76
     * @param string $table_column
77
     * @param string $nice_name
78
     * @param bool   $nullable
79
     * @param null   $default_value
80
     * @return EE_All_Caps_Text_Field
81
     */
82 View Code Duplication
    public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null)
83
    {
84
        return $this->loader->getNew(
85
            'EE_All_Caps_Text_Field',
86
            array($table_column, $nice_name, $nullable, $default_value)
87
        );
88
    }
89
90
91
92
    /**
93
     * @param string $table_column
94
     * @param string $nice_name
95
     * @param bool   $nullable
96
     * @param null   $default_value
97
     * @param string $model_name
98
     * @return EE_Any_Foreign_Model_Name_Field
99
     */
100 View Code Duplication
    public function createAnyForeignModelNameField(
101
        $table_column,
102
        $nice_name,
103
        $nullable,
104
        $default_value = null,
105
        $model_name
106
    ) {
107
        return $this->loader->getNew(
108
            'EE_Any_Foreign_Model_Name_Field',
109
            array($table_column, $nice_name, $nullable, $default_value, $model_name)
110
        );
111
    }
112
113
114
115
    /**
116
     * @param string $table_column
117
     * @param string $nice_name
118
     * @param bool   $nullable
119
     * @param null   $default_value
120
     * @return EE_Boolean_Field
121
     */
122 View Code Duplication
    public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null)
123
    {
124
        return $this->loader->getNew(
125
            'EE_Boolean_Field',
126
            array($table_column, $nice_name, $nullable, $default_value)
127
        );
128
    }
129
130
131
132
    /**
133
     * @param string $table_column
134
     * @param string $nice_name
135
     * @param string $timezone_string
136
     * @param bool   $nullable
137
     * @param string $default_value
138
     * @param string $date_format
139
     * @param string $time_format
140
     * @param string $pretty_date_format
141
     * @param string $pretty_time_format
142
     * @throws EE_Error
143
     * @throws InvalidArgumentException
144
     * @return EE_Datetime_Field
145
     */
146
    public function createDatetimeField(
147
        $table_column,
148
        $nice_name,
149
        $nullable = false,
150
        $default_value = EE_Datetime_Field::now,
151
        $timezone_string = '',
152
        $date_format = '',
153
        $time_format = '',
154
        $pretty_date_format = '',
155
        $pretty_time_format = ''
156
    ) {
157
        return $this->loader->getNew(
158
            'EE_Datetime_Field',
159
            array(
160
                $table_column,
161
                $nice_name,
162
                $nullable,
163
                $default_value,
164
                $timezone_string,
165
                $date_format,
166
                $time_format,
167
                $pretty_date_format,
168
                $pretty_time_format,
169
            )
170
        );
171
    }
172
173
174
175
    /**
176
     * @param string $table_column
177
     * @param string $nice_name
178
     * @param bool   $nullable
179
     * @param null   $default_value
180
     * @return EE_DB_Only_Float_Field
181
     */
182 View Code Duplication
    public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null)
183
    {
184
        return $this->loader->getNew(
185
            'EE_DB_Only_Float_Field',
186
            array($table_column, $nice_name, $nullable, $default_value)
187
        );
188
    }
189
190
191
192
    /**
193
     * @param string $table_column
194
     * @param string $nice_name
195
     * @param bool   $nullable
196
     * @param null   $default_value
197
     * @return EE_DB_Only_Int_Field
198
     */
199 View Code Duplication
    public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null)
200
    {
201
        return $this->loader->getNew(
202
            'EE_DB_Only_Int_Field',
203
            array($table_column, $nice_name, $nullable, $default_value)
204
        );
205
    }
206
207
208
209
    /**
210
     * @param string $table_column
211
     * @param string $nice_name
212
     * @param bool   $nullable
213
     * @param null   $default_value
214
     * @return EE_DB_Only_Text_Field
215
     */
216 View Code Duplication
    public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null)
217
    {
218
        return $this->loader->getNew(
219
            'EE_DB_Only_Text_Field',
220
            array($table_column, $nice_name, $nullable, $default_value)
221
        );
222
    }
223
224
225
226
    /**
227
     * @param string $table_column
228
     * @param string $nice_name
229
     * @param bool   $nullable
230
     * @param string $default_value
231
     * @return EE_Email_Field
232
     */
233 View Code Duplication
    public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '')
234
    {
235
        return $this->loader->getNew(
236
            'EE_Email_Field',
237
            array($table_column, $nice_name, $nullable, $default_value)
238
        );
239
    }
240
241
242
243
    /**
244
     * @param string $table_column
245
     * @param string $nice_name
246
     * @param bool   $nullable
247
     * @param null   $default_value
248
     * @param array  $allowed_enum_values keys are values to be used in the DB,
249
     *                                    values are how they should be displayed
250
     * @return EE_Enum_Integer_Field
251
     */
252 View Code Duplication
    public function createEnumIntegerField(
253
        $table_column,
254
        $nice_name,
255
        $nullable,
256
        $default_value = null,
257
        array $allowed_enum_values
258
    ) {
259
        return $this->loader->getNew(
260
            'EE_Enum_Integer_Field',
261
            array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
262
        );
263
    }
264
265
266
267
    /**
268
     * @param string $table_column
269
     * @param string $nice_name
270
     * @param bool   $nullable
271
     * @param null   $default_value
272
     * @param array  $allowed_enum_values keys are values to be used in the DB,
273
     *                                    values are how they should be displayed
274
     * @return EE_Enum_Text_Field
275
     */
276
    public function createEnumTextField(
277
        $table_column,
278
        $nice_name,
279
        $nullable,
280
        $default_value,
281
        array $allowed_enum_values
282
    ) {
283
        return $this->loader->getNew(
284
            'EE_Enum_Text_Field',
285
            array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
286
        );
287
    }
288
289
290
291
    /**
292
     * @param string $table_column
293
     * @param string $nice_name
294
     * @param bool   $nullable
295
     * @param null   $default_value
296
     * @return EE_Float_Field
297
     */
298 View Code Duplication
    public function createFloatField($table_column, $nice_name, $nullable, $default_value = null)
299
    {
300
        return $this->loader->getNew(
301
            'EE_Float_Field',
302
            array($table_column, $nice_name, $nullable, $default_value)
303
        );
304
    }
305
306
307
308
    /**
309
     * @param string $table_column
310
     * @param string $nice_name
311
     * @param bool   $nullable
312
     * @param null   $default_value
313
     * @param string $model_name
314
     * @return EE_Foreign_Key_Int_Field
315
     */
316
    public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name)
317
    {
318
        return $this->loader->getNew(
319
            'EE_Foreign_Key_Int_Field',
320
            array($table_column, $nice_name, $nullable, $default_value, $model_name)
321
        );
322
    }
323
324
325
326
    /**
327
     * @param string $table_column
328
     * @param string $nice_name
329
     * @param bool   $nullable
330
     * @param null   $default_value
331
     * @param string $model_name
332
     * @return EE_Foreign_Key_String_Field
333
     */
334
    public function createForeignKeyStringField(
335
        $table_column,
336
        $nice_name,
337
        $nullable,
338
        $default_value,
339
        $model_name
340
    ) {
341
        return $this->loader->getNew(
342
            'EE_Foreign_Key_String_Field',
343
            array($table_column, $nice_name, $nullable, $default_value, $model_name)
344
        );
345
    }
346
347
348
349
    /**
350
     * @param string $table_column
351
     * @param string $nice_name
352
     * @param bool   $nullable
353
     * @param null   $default_value
354
     * @return EE_Full_HTML_Field
355
     */
356 View Code Duplication
    public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null)
357
    {
358
        return $this->loader->getNew(
359
            'EE_Full_HTML_Field',
360
            array($table_column, $nice_name, $nullable, $default_value)
361
        );
362
    }
363
364
365
366
    /**
367
     * @param string $table_column
368
     * @param string $nice_name
369
     * @param bool   $nullable
370
     * @param null   $default_value
371
     * @return EE_Infinite_Integer_Field
372
     */
373 View Code Duplication
    public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null)
374
    {
375
        return $this->loader->getNew(
376
            'EE_Infinite_Integer_Field',
377
            array($table_column, $nice_name, $nullable, $default_value)
378
        );
379
    }
380
381
382
383
    /**
384
     * @param string $table_column
385
     * @param string $nice_name
386
     * @param bool   $nullable
387
     * @param null   $default_value
388
     * @return EE_Integer_Field
389
     */
390 View Code Duplication
    public function createIntegerField($table_column, $nice_name, $nullable, $default_value = null)
391
    {
392
        return $this->loader->getNew(
393
            'EE_Integer_Field',
394
            array($table_column, $nice_name, $nullable, $default_value)
395
        );
396
    }
397
398
399
400
    /**
401
     * @param string $table_column
402
     * @param string $nice_name
403
     * @param bool   $nullable
404
     * @param null   $default_value
405
     * @return EE_Maybe_Serialized_Simple_HTML_Field
406
     */
407 View Code Duplication
    public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null)
408
    {
409
        return $this->loader->getNew(
410
            'EE_Maybe_Serialized_Simple_HTML_Field',
411
            array($table_column, $nice_name, $nullable, $default_value)
412
        );
413
    }
414
415
416
417
    /**
418
     * @param string $table_column
419
     * @param string $nice_name
420
     * @param bool   $nullable
421
     * @param null   $default_value
422
     * @return EE_Maybe_Serialized_Text_Field
423
     */
424 View Code Duplication
    public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null)
425
    {
426
        return $this->loader->getNew(
427
            'EE_Maybe_Serialized_Text_Field',
428
            array($table_column, $nice_name, $nullable, $default_value)
429
        );
430
    }
431
432
433
434
    /**
435
     * @param string $table_column
436
     * @param string $nice_name
437
     * @param bool   $nullable
438
     * @param null   $default_value
439
     * @return EE_Money_Field
440
     */
441 View Code Duplication
    public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null)
442
    {
443
        return $this->loader->getNew(
444
            'EE_Money_Field',
445
            array($table_column, $nice_name, $nullable, $default_value)
446
        );
447
    }
448
449
450
451
    /**
452
     * @param string $table_column
453
     * @param string $nice_name
454
     * @param bool   $nullable
455
     * @param string $default_value
456
     * @return EE_Plain_Text_Field
457
     */
458 View Code Duplication
    public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '')
459
    {
460
        return $this->loader->getNew(
461
            'EE_Plain_Text_Field',
462
            array($table_column, $nice_name, $nullable, $default_value)
463
        );
464
    }
465
466
467
468
    /**
469
     * @param string $table_column
470
     * @param string $nice_name
471
     * @param bool   $nullable
472
     * @param null   $default_value
473
     * @return EE_Post_Content_Field
474
     */
475 View Code Duplication
    public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null)
476
    {
477
        return $this->loader->getNew(
478
            'EE_Post_Content_Field',
479
            array($table_column, $nice_name, $nullable, $default_value)
480
        );
481
    }
482
483
484
485
    /**
486
     * @param string $table_column
487
     * @param string $nice_name
488
     * @return EE_Primary_Key_Int_Field
489
     */
490
    public function createPrimaryKeyIntField($table_column, $nice_name)
491
    {
492
        return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name));
493
    }
494
495
496
497
    /**
498
     * @param string $table_column
499
     * @param string $nice_name
500
     * @return EE_Primary_Key_String_Field
501
     */
502
    public function createPrimaryKeyStringField($table_column, $nice_name)
503
    {
504
        return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name));
505
    }
506
507
508
509
    /**
510
     * @param string $table_column
511
     * @param string $nice_name
512
     * @param bool   $nullable
513
     * @param null   $default_value
514
     * @return EE_Serialized_Text_Field
515
     */
516 View Code Duplication
    public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null)
517
    {
518
        return $this->loader->getNew(
519
            'EE_Serialized_Text_Field',
520
            array($table_column, $nice_name, $nullable, $default_value)
521
        );
522
    }
523
524
525
526
    /**
527
     * @param string $table_column
528
     * @param string $nice_name
529
     * @param bool   $nullable
530
     * @param null   $default_value
531
     * @return EE_Simple_HTML_Field
532
     */
533 View Code Duplication
    public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null)
534
    {
535
        return $this->loader->getNew(
536
            'EE_Simple_HTML_Field',
537
            array($table_column, $nice_name, $nullable, $default_value)
538
        );
539
    }
540
541
542
543
    /**
544
     * @param string $table_column
545
     * @param string $nice_name
546
     * @param bool   $nullable
547
     * @param null   $default_value
548
     * @return EE_Slug_Field
549
     */
550 View Code Duplication
    public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null)
551
    {
552
        return $this->loader->getNew(
553
            'EE_Slug_Field',
554
            array($table_column, $nice_name, $nullable, $default_value)
555
        );
556
    }
557
558
559
560
    /**
561
     * @param string $table_column
562
     * @param string $nice_name
563
     * @param bool   $nullable
564
     * @param null   $default_value
565
     * @return EE_Trashed_Flag_Field
566
     */
567 View Code Duplication
    public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null)
568
    {
569
        return $this->loader->getNew(
570
            'EE_Trashed_Flag_Field',
571
            array($table_column, $nice_name, $nullable, $default_value)
572
        );
573
    }
574
575
576
577
    /**
578
     * @param string $table_column
579
     * @param string $nice_name
580
     * @param bool   $nullable
581
     * @param mixed  $default_value
582
     * @param array  $values        If additional stati are to be used other than the default WP statuses,
583
     *                              then they can be registered via this property.
584
     *                              The format of the array should be as follows:
585
     *  array(
586
     *      'status_reference' => array(
587
     *          'label' => __('Status Reference Label', 'event_espresso'),
588
     *          'public' => true,                 // whether this status should be shown on the frontend of the site
589
     *          'exclude_from_search' => false,   // whether this status should be excluded from wp searches
590
     *          'show_in_admin_all_list' => true, // whether this status is included in queries
591
     *                                               for the admin "all" view in list table views.
592
     *          'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top
593
     *                                                  of the admin list tables (i.e. Status Reference(2) )
594
     *          'label_count' => _n_noop(
595
     *              'Status Reference <span class="count">(%s)</span>',
596
     *              'Status References <span class="count">(%s)</span>'
597
     *          ),                                   // the text to display on the admin screen
598
     *                                                  ( or you won't see your status count ).
599
     *      )
600
     *  )
601
     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
602
     * @return EE_WP_Post_Status_Field
603
     */
604 View Code Duplication
    public function createWpPostStatusField(
605
        $table_column,
606
        $nice_name,
607
        $nullable,
608
        $default_value = null,
609
        array $values = array()
610
    ) {
611
        return $this->loader->getNew(
612
            'EE_WP_Post_Status_Field',
613
            array($table_column, $nice_name, $nullable, $default_value, $values)
614
        );
615
    }
616
617
618
619
    /**
620
     * @param string $post_type
621
     * @return EE_WP_Post_Type_Field
622
     */
623
    public function createWpPostTypeField($post_type)
624
    {
625
        return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type));
626
    }
627
628
629
630
    /**
631
     * @param string $table_column
632
     * @param string $nice_name
633
     * @param bool   $nullable
634
     * @return EE_WP_User_Field
635
     */
636
    public function createWpUserField($table_column, $nice_name, $nullable)
637
    {
638
        return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable));
639
    }
640
641
642
643
}
644
// Location: core/services/database/ModelFieldFactory.php
645