Test Failed
Push — master ( d0a4ef...acab14 )
by Josh
03:29
created

Blendable::loadFromArray()   C

Complexity

Conditions 13
Paths 29

Size

Total Lines 40
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 20
nc 29
nop 1
dl 0
loc 40
rs 6.6166
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: joshgulledge
5
 * Date: 3/5/18
6
 * Time: 11:14 AM
7
 */
8
9
namespace LCI\Blend\Blendable;
10
11
use LCI\Blend\Blender;
12
use LCI\Blend\Exception\BlendableException;
13
14
abstract class Blendable implements BlendableInterface
15
{
16
    /** @var  \modx */
0 ignored issues
show
Bug introduced by
The type modx was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
    protected $modx;
18
19
    /** @var  Blender */
20
    protected $blender;
21
22
    /** @var string ~ blend or revert */
23
    protected $type = 'blend';
24
25
    /** @var string  */
26
    protected $opt_cache_key = '';
27
28
    /** @var array  */
29
    protected $seedCacheOptions = [];
30
31
    /** @var array  */
32
    protected $historyCacheOptions = [];
33
34
    /** @var string */
35
    protected $seeds_dir = '';
36
37
    /** @var int $cache_life in seconds, 0 is forever */
38
    protected $cache_life = 0;
39
40
    /** @var bool  */
41
    protected $error = false;
42
43
    /** @var array  */
44
    protected $error_messages = [];
45
46
    /** @var null|\xPDOSimpleObject  */
0 ignored issues
show
Bug introduced by
The type xPDOSimpleObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
    protected $xPDOSimpleObject = null;
48
49
    /** @var string ex: modResource */
50
    protected $xpdo_simple_object_class = '';
51
52
    /** @var string  */
53
    protected $unique_key_column = 'name';
54
55
    /** @var array set when a change of name/alias has been done */
56
    protected $unique_key_history = [];
57
58
    /** @var array ~ this should match data to be inserted via xPDO, ex [column_name => value, ...] */
59
    protected $blendable_xpdo_simple_object_data = [
60
        'name' => ''
61
    ];
62
63
    /** @var array ~ ['setMethodName' => 'setMethodActualName', 'setDoNotUseMethod' => false] overwrite in child classes */
64
    protected $load_from_array_aliases = [];
65
66
    /** @var array ~ list any fields/columns to be ignored on making seeds, like id */
67
    protected $ignore_seed_fields = ['id'];
68
69
    /** @var array ~ xPDOSimpleObject->fromArray() */
70
    protected $current_xpdo_simple_object_data = [];
71
72
    /** @var array  */
73
    protected $related_data = [];
74
75
    /** @var bool  */
76
    protected $exists = false;
77
78
    /** @var bool  */
79
    protected $debug = false;
80
81
    /**
82
     * Blendable constructor.
83
     *
84
     * @param \modx $modx
85
     * @param Blender $blender
86
     * @param string|array $unique_value
87
     */
88
    public function __construct(\modx $modx, Blender $blender, $unique_value = '')
89
    {
90
        $this->modx = $modx;
91
        $this->blender = $blender;
92
        if (method_exists($this, 'loadProperties')) {
93
            $this->loadProperties();
94
        }
95
96
        $this->seedCacheOptions = [
97
            \xPDO::OPT_CACHE_KEY => $this->opt_cache_key,
0 ignored issues
show
Bug introduced by
The type xPDO was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
98
            \xPDO::OPT_CACHE_PATH => $this->blender->getSeedsPath()
99
        ];
100
101
        $this->historyCacheOptions = [
102
            \xPDO::OPT_CACHE_KEY => $this->opt_cache_key,
103
            \xPDO::OPT_CACHE_PATH => $this->blender->getHistoryPath()
104
        ];
105
106
        $this->setUniqueCriteria($unique_value);
107
        if (!empty($unique_value)) {
108
            $this->loadObject();
109
        }
110
    }
111
112
    /**
113
     * @return bool
114
     */
115
    public function isDebug()
116
    {
117
        return $this->debug;
118
    }
119
120
    /**
121
     * @param bool $debug
122
     *
123
     * @return $this
124
     */
125
    public function setDebug($debug)
126
    {
127
        $this->debug = $debug;
128
        return $this;
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public function getSeedsDir()
135
    {
136
        return $this->seeds_dir;
137
    }
138
139
    /**
140
     * @param string $dir ~ will be the directory name for seeds and history
141
     *
142
     * @return $this
143
     */
144
    public function setSeedsDir($dir)
145
    {
146
        $this->seeds_dir = (string)$dir;
147
        if (!empty($this->seeds_dir)) {
148
            $this->seedCacheOptions[\xPDO::OPT_CACHE_PATH] = $this->blender->getSeedsPath().$dir.'/';
149
            $this->historyCacheOptions[\xPDO::OPT_CACHE_PATH] = $this->blender->getHistoryPath().$dir.'/';
150
        }
151
        return $this;
152
    }
153
154
    /**
155
     * @return bool
156
     */
157
    public function isExists()
158
    {
159
        return $this->exists;
160
    }
161
162
    /**
163
     * @return bool
164
     */
165
    public function isError()
166
    {
167
        return $this->error;
168
    }
169
170
    /**
171
     * @return array
172
     */
173
    public function getErrorMessages()
174
    {
175
        return $this->error_messages;
176
    }
177
178
    /**
179
     * @param string $type ~ seed or revert
180
     * @return string
181
     */
182
    public function getSeedKey($type = 'seed')
183
    {
184
        $name = $this->blendable_xpdo_simple_object_data[$this->unique_key_column];
185
        if (method_exists($this, 'getFieldName')) {
186
            $name = $this->getFieldName();
187
        }
188
        $key = $this->blender->getSeedKeyFromName($name);
189
190
        switch ($type) {
191
            case 'revert':
192
                $seed_key = 'revert-'.$key;
193
                break;
194
195
            case 'seed':
196
                // no break
197
            default:
198
                $seed_key = $key;
199
        }
200
201
        return $seed_key;
202
    }
203
204
    /**
205
     * @return null|\xPDOSimpleObject
206
     */
207
    public function getXPDOSimpleObject()
208
    {
209
        return $this->xPDOSimpleObject;
210
    }
211
212
    /**
213
     * @param array $data ~ must be in the format: array('columns' => [], 'primaryKeyHistory' => [], 'related' => [])
214
     * @param bool $overwrite
215
     * @return bool
216
     */
217
    public function blendFromArray($data, $overwrite = false)
218
    {
219
        if (isset($data['columns'])) {
220
            $this->blendable_xpdo_simple_object_data = $data['columns'];
221
        }
222
        if (isset($data['primaryKeyHistory']) && $data['primaryKeyHistory']) {
223
            $this->unique_key_history = $data['primaryKeyHistory'];
224
        } else {
225
            $this->unique_key_history = [];
226
        }
227
228
        if (isset($data['related']) && $data['related']) {
229
            $this->related_data = $data['related'];
230
        } else {
231
            $this->related_data = [];
232
        }
233
234
        return $this->blend($overwrite);
235
    }
236
    /**
237
     * @param string $seed_key
238
     * @param bool $overwrite
239
     *
240
     * @return bool
241
     * @throws BlendableException
242
     */
243
    public function blendFromSeed($seed_key, $overwrite = false)
244
    {
245
        $this->loadObjectDataFromSeed($seed_key);
246
        return $this->blend($overwrite);
247
    }
248
249
    /**
250
     * @param bool $overwrite
251
     *
252
     * @return bool
253
     */
254
    public function blend($overwrite = false)
255
    {
256
        if ($this->type == 'blend') {
257
            /** @var \LCI\Blend\Blendable\Blendable $currentVersion */
258
            $currentVersion = $this->getCurrentVersion();
259
            $currentVersion
260
                ->setRelatedData($this->related_data)
261
                ->makeHistory();
262
        }
263
264
        $this->modx->invokeEvent(
265
            'OnBlendBeforeSave',
266
            [
267
                'blender' => $this->blender,
268
                'blendable' => $this,
269
                'data' => &$this->blendable_xpdo_simple_object_data,
270
                'type' => $this->type,
271
                'xPDOClass' => $this->xpdo_simple_object_class,
272
                'xPDOSimpleObject' => &$this->xPDOSimpleObject
273
            ]
274
        );
275
276
        $save = $this->save($overwrite);
277
278
        if ($save) {
279
            $this->modx->invokeEvent(
280
                'OnBlendAfterSave',
281
                [
282
                    'blender' => $this->blender,
283
                    'blendable' => $this,
284
                    'data' => &$this->blendable_xpdo_simple_object_data,
285
                    'type' => $this->type,
286
                    'xPDOClass' => $this->xpdo_simple_object_class,
287
                    'xPDOSimpleObject' => &$this->xPDOSimpleObject
288
                ]
289
            );
290
        }
291
292
        return $save;
293
    }
294
295
    /**
296
     * @param bool $make_revert_seed
297
     * @return bool
298
     */
299
    public function delete($make_revert_seed = true)
300
    {
301
        if ($make_revert_seed) {
302
            $this->makeHistory();
303
        }
304
        $removed = false;
305
        if (!is_object($this->xPDOSimpleObject)) {
306
            $this->blender->out($this->blendable_xpdo_simple_object_data[$this->unique_key_column].' of xPDO class '.
307
                $this->xpdo_simple_object_class.' was not found, could not be removed/deleted', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type integer expected by parameter $verbose of LCI\Blend\Blender::out(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

307
                $this->xpdo_simple_object_class.' was not found, could not be removed/deleted', /** @scrutinizer ignore-type */ true);
Loading history...
308
309
        } elseif ($this->xPDOSimpleObject->remove()) {
310
            $this->onDeleteRevertRelatedPieces();
311
            if ($this->isDebug()) {
312
                $this->blender->out($this->blendable_xpdo_simple_object_data[$this->unique_key_column].' has been removed/deleted');
313
            }
314
            $removed = true;
315
316
        } else {
317
            if ($this->isDebug()) {
318
                $this->blender->out($this->blendable_xpdo_simple_object_data[$this->unique_key_column].' did not remove/delete', true);
319
            }
320
        }
321
322
        return $removed;
323
    }
324
325
    /**
326
     * @return bool
327
     */
328
    public function revertBlend()
329
    {
330
        $seed_key = $this->getSeedKey('revert');
331
        $this->type = 'revert';
332
        if (!$this->loadObjectDataFromHistorySeed($seed_key) || !$this->blendable_xpdo_simple_object_data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->blendable_xpdo_simple_object_data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
333
            return $this->delete(false);
334
        }
335
336
        return $this->blend(true);
337
    }
338
339
    /**
340
     * @return string ~ the related seed key
341
     */
342
    public function seed()
343
    {
344
        // No IDs! must get the alias and get a seed key,
345
        $seed_key = $this->getSeedKey();
346
347
        $data = $this->seedToArray('seed', $seed_key);
348
349
        // now cache it:
350
        $this->modx->cacheManager->set(
351
            $seed_key,
352
            $data,
353
            $this->cache_life,
354
            $this->seedCacheOptions
355
        );
356
357
        return $seed_key;
358
    }
359
360
    /**
361
     * @return string ~ the related seed key
362
     */
363
    public function makeHistory()
364
    {
365
        $seed_key = $this->getSeedKey('revert');
366
367
        $data = $this->seedToArray('revert', $seed_key);
368
369
        // now cache it:
370
        $this->modx->cacheManager->set(
371
            $seed_key,
372
            $data,
373
            $this->cache_life,
374
            $this->historyCacheOptions
375
        );
376
377
        return $seed_key;
378
    }
379
380
    /**
381
     * @param string $type ~ seed or revert
382
     * @param string $seed_key
383
     * @return array
384
     */
385
    public function seedToArray($type = 'seed', $seed_key = '')
386
    {
387
        if (is_object($this->xPDOSimpleObject)) {
388
            $this->current_xpdo_simple_object_data = $this->xPDOSimpleObject->toArray();
389
390
            foreach ($this->current_xpdo_simple_object_data as $column => $value) {
391
                if (in_array($column, $this->ignore_seed_fields)) {
392
                    continue;
393
                }
394
                // Any child class can create a seed method, an example for modResource:
395
                // seedTemplate(1) and would return the string name
396
                $method = 'seed'.$this->makeStudyCase($column);
397
                if (method_exists($this, $method)) {
398
                    $value = $this->$method($value);
399
                }
400
                $this->blendable_xpdo_simple_object_data[$column] = $value;
401
            }
402
403
            $this->seedRelated($type);
404
405
            $data = [
406
                'columns' => $this->blendable_xpdo_simple_object_data,
407
                'primaryKeyHistory' => $this->unique_key_history,
408
                'related' => $this->related_data
409
            ];
410
411
        } elseif ($type == 'revert') {
412
413
            $data = [
414
                'columns' => false,
415
                'primaryKeyHistory' => [],
416
                'related' => []
417
            ];
418
419
            if ($this->isDebug()) {
420
                $this->blender->out('Data not found to make seed: '.$seed_key);
421
            }
422
423
        } elseif ($type == 'seed') {
424
            if ($this->isDebug()) {
425
                $this->blender->out('Data not found to make seed: '.$seed_key);
426
            }
427
        }
428
429
        // https://docs.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.invokeevent
430
        $this->modx->invokeEvent(
431
            'OnBlendSeed',
432
            [
433
                'blender' => $this->blender,
434
                'blendable' => $this,
435
                'type' => $type,
436
                'xPDOClass' => $this->xpdo_simple_object_class,
437
                'xPDOSimpleObject' => &$this->xPDOSimpleObject,
438
                'data' => &$data
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $data does not seem to be defined for all execution paths leading up to this point.
Loading history...
439
            ]
440
        );
441
442
        return $data;
443
    }
444
445
    /**
446
     * @param bool $overwrite
447
     *
448
     * @return bool
449
     */
450
    protected function save($overwrite = false)
451
    {
452
        $saved = false;
453
454
        if (is_object($this->xPDOSimpleObject)) {
455
            if (!$overwrite) {
456
                $this->error = true;
457
                $this->error_messages['exits'] = $this->xpdo_simple_object_class.': '.
458
                    $this->blendable_xpdo_simple_object_data[$this->unique_key_column].' already exists ';
459
                return $saved;
460
            }
461
        } else {
462
            $this->xPDOSimpleObject = $this->modx->newObject($this->xpdo_simple_object_class);
463
        }
464
465
        $this->xPDOSimpleObject->set($this->unique_key_column, $this->blendable_xpdo_simple_object_data[$this->unique_key_column]);
466
467
        foreach ($this->blendable_xpdo_simple_object_data as $column => $value) {
468
            // Any child class can create a convert method, an example for modResource:
469
            // convertTemplate('String name') and would return the numeric ID
470
            $method = 'convert'.$this->makeStudyCase($column);
471
            if (method_exists($this, $method)) {
472
                $value = $this->$method($value);
473
            }
474
            $this->xPDOSimpleObject->set($column, $value);
475
        }
476
477
        if (method_exists($this, 'getPropertiesData')) {
478
            $this->xPDOSimpleObject->set('properties', $this->getPropertiesData());
479
        }
480
481
        $this->attachRelatedPieces();
482
483
        if ($this->xPDOSimpleObject->save()) {
484
            $this->attachRelatedPiecesAfterSave();
485
            if ($this->isDebug()) {
486
                $this->blender->out($this->blendable_xpdo_simple_object_data[$this->unique_key_column].' has been installed/saved');
487
            }
488
            $saved = true;
489
490
        } else {
491
            if ($this->isDebug()) {
492
                $this->blender->out($this->blendable_xpdo_simple_object_data[$this->unique_key_column].' did not install/update', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type integer expected by parameter $verbose of LCI\Blend\Blender::out(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

492
                $this->blender->out($this->blendable_xpdo_simple_object_data[$this->unique_key_column].' did not install/update', /** @scrutinizer ignore-type */ true);
Loading history...
493
            }
494
495
        }
496
497
        return $saved;
498
    }
499
500
    protected function getUniqueCriteria()
501
    {
502
        return [
503
            $this->unique_key_column => $this->blendable_xpdo_simple_object_data[$this->unique_key_column]
504
        ];
505
    }
506
507
    /**
508
     * @param string|array $criteria
509
     */
510
    protected function setUniqueCriteria($criteria)
511
    {
512
        $this->blendable_xpdo_simple_object_data[$this->unique_key_column] = $criteria;
513
    }
514
515
    /**
516
     * Will load an existing xPDOSimpleObject if it exists, child class needs to class this one
517
     * @return $this
518
     */
519
    protected function loadObject()
520
    {
521
        $this->xPDOSimpleObject = $this->modx->getObject($this->xpdo_simple_object_class, $this->getUniqueCriteria());
522
523
        if (is_object($this->xPDOSimpleObject)) {
524
            $this->exists = true;
525
            $this->current_xpdo_simple_object_data = $this->xPDOSimpleObject->toArray();
526
            $this->loadFromArray($this->current_xpdo_simple_object_data);
527
            // load related data:
528
            $this->loadRelatedData();
529
        }
530
531
        return $this;
532
    }
533
534
    /**
535
     * @param array $data ~ convert the db data object to blend portable data
536
     *
537
     * @return $this
538
     */
539
    protected function loadFromArray($data = [])
540
    {
541
        foreach ($data as $column => $value) {
542
543
            if ($column == 'content_type' && $this->xpdo_simple_object_class == 'modResource') {
544
                // modResource has both contentType and content_type, ignore the 2nd
545
                continue;
546
            }
547
548
            $method_name = 'seed'.$this->makeStudyCase($column);
549
550
            if (method_exists($this, $method_name) && !is_null($value)) {
551
                if ($this->isDebug()) {
552
                    $this->blender->out(__METHOD__.' call: '.$method_name.' V: '.$value);
553
                }
554
                $value = $this->$method_name($value);
555
            }
556
557
            $method_name = 'setField'.$this->makeStudyCase($column);
558
559
            if (isset($this->load_from_array_aliases[$method_name])) {
560
                $method_name = $this->load_from_array_aliases[$method_name];
561
562
                if (!$method_name) {
563
                    continue;
564
                }
565
            }
566
567
            if (method_exists($this, $method_name) && !is_null($value)) {
568
                if ($this->isDebug()) {
569
                    $this->blender->out(__METHOD__.' call: '.$method_name.' V: '.$value);
570
                }
571
                $this->$method_name($value);
572
                
573
            } elseif ($this->isDebug()) {
574
                $this->blender->out(__METHOD__.' missing: '.$method_name.' V: '.print_r($value, true), true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type integer expected by parameter $verbose of LCI\Blend\Blender::out(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

574
                $this->blender->out(__METHOD__.' missing: '.$method_name.' V: '.print_r($value, true), /** @scrutinizer ignore-type */ true);
Loading history...
575
            }
576
        }
577
578
        return $this;
579
    }
580
581
    /**
582
     * Override in child classes
583
     */
584
    protected function loadRelatedData()
585
    {
586
        $this->modx->invokeEvent(
587
            'OnBlendLoadRelatedData',
588
            [
589
                'blender' => $this->blender,
590
                'blendable' => $this,
591
                'data' => &$this->blendable_xpdo_simple_object_data,
592
                'type' => $this->type,
593
                'xPDOClass' => $this->xpdo_simple_object_class,
594
                'xPDOSimpleObject' => &$this->xPDOSimpleObject
595
            ]
596
        );
597
    }
598
599
    /**
600
     * @param string $seed_key
601
     *
602
     * @return bool|array
603
     * @throws BlendableException
604
     */
605
    protected function loadObjectDataFromSeed($seed_key)
606
    {
607
        $data = $this->modx->cacheManager->get($seed_key, $this->seedCacheOptions);
608
        if ($data == false) {
609
            if ($this->type == 'blend') {
610
                $this->blender->outError('Error: Seed could not be found: '.$seed_key);
611
                throw new BlendableException('Error: Seed could not be found: '.$seed_key . ' in '. print_r($this->seedCacheOptions, true));
612
            }
613
614
        } else {
615
            $this->blendable_xpdo_simple_object_data = $data['columns'];
616
            $this->unique_key_history = $data['primaryKeyHistory'];
617
            $this->related_data = $data['related'];
618
        }
619
620
        return $data;
621
    }
622
623
    /**
624
     * @param string $seed_key
625
     * @return mixed
626
     */
627
    protected function loadObjectDataFromHistorySeed($seed_key)
628
    {
629
        $data = $this->modx->cacheManager->get($seed_key, $this->historyCacheOptions);
630
631
        if (is_array($data)) {
632
            $this->blendable_xpdo_simple_object_data = $data['columns'];
633
            $this->unique_key_history = $data['primaryKeyHistory'];
634
            $this->related_data = $data['related'];
635
        }
636
637
        return $data;
638
    }
639
640
    /**
641
     * @param string $name
642
     * @return string
643
     */
644
    protected function makeStudyCase($name)
645
    {
646
        if ($name == 'templatename') {
647
            $name = 'templateName';
648
        }
649
650
        $StudyName = '';
651
        $parts = explode('_', $name);
652
        foreach ($parts as $part) {
653
            $StudyName .= ucfirst($part);
654
        }
655
656
        return $StudyName;
657
    }
658
659
    /**
660
     * This method is called just before blend/save()
661
     */
662
    protected function attachRelatedPieces()
663
    {
664
665
    }
666
667
    /**
668
     * This method is called just after a successful blend/save()
669
     */
670
    protected function attachRelatedPiecesAfterSave()
671
    {
672
673
    }
674
675
    /**
676
     *
677
     */
678
    protected function onDeleteRevertRelatedPieces()
679
    {
680
681
    }
682
683
    /**
684
     * @var string $type blend or revert
685
     */
686
    protected function seedRelated($type = 'blend')
687
    {
688
        // load related data:
689
        $this->loadRelatedData();
690
691
    }
692
693
    /**
694
     * @return array
695
     */
696
    public function getRelatedData()
697
    {
698
        return $this->related_data;
699
    }
700
701
    /**
702
     * @param array $data
703
     *
704
     * @return $this
705
     */
706
    public function setRelatedData($data)
707
    {
708
        $this->related_data = $data;
709
        return $this;
710
    }
711
712
}