@@ -19,6 +19,23 @@ class ScheduledStructure
19
19
const ELEMENT_IS_AFTER = 'isAfter ' ;
20
20
/**#@-*/
21
21
22
+ /**
23
+ * Map of class properties.
24
+ *
25
+ * @var array
26
+ */
27
+ private $ propertyMap = [
28
+ 'scheduledStructure ' ,
29
+ 'scheduledData ' ,
30
+ 'scheduledElements ' ,
31
+ 'scheduledMoves ' ,
32
+ 'scheduledRemoves ' ,
33
+ 'scheduledIfconfig ' ,
34
+ 'scheduledPaths ' ,
35
+ 'elementsToSort ' ,
36
+ 'brokenParent ' ,
37
+ ];
38
+
22
39
/**
23
40
* Information about structural elements, scheduled for creation
24
41
*
@@ -84,18 +101,10 @@ class ScheduledStructure
84
101
85
102
/**
86
103
* @param array $data
87
- *
88
- * @SuppressWarnings(PHPMD.NPathComplexity)
89
104
*/
90
105
public function __construct (array $ data = [])
91
106
{
92
- $ this ->scheduledStructure = isset ($ data ['scheduledStructure ' ]) ? $ data ['scheduledStructure ' ] : [];
93
- $ this ->scheduledData = isset ($ data ['scheduledData ' ]) ? $ data ['scheduledData ' ] : [];
94
- $ this ->scheduledElements = isset ($ data ['scheduledElements ' ]) ? $ data ['scheduledElements ' ] : [];
95
- $ this ->scheduledMoves = isset ($ data ['scheduledMoves ' ]) ? $ data ['scheduledMoves ' ] : [];
96
- $ this ->scheduledRemoves = isset ($ data ['scheduledRemoves ' ]) ? $ data ['scheduledRemoves ' ] : [];
97
- $ this ->scheduledIfconfig = isset ($ data ['scheduledIfconfig ' ]) ? $ data ['scheduledIfconfig ' ] : [];
98
- $ this ->scheduledPaths = isset ($ data ['scheduledPaths ' ]) ? $ data ['scheduledPaths ' ] : [];
107
+ $ this ->populateWithArray ($ data );
99
108
}
100
109
101
110
/**
@@ -540,17 +549,12 @@ public function flushScheduledStructure()
540
549
*/
541
550
public function __toArray ()
542
551
{
543
- return [
544
- 'scheduledStructure ' => $ this ->scheduledStructure ,
545
- 'scheduledData ' => $ this ->scheduledData ,
546
- 'scheduledElements ' => $ this ->scheduledElements ,
547
- 'scheduledMoves ' => $ this ->scheduledMoves ,
548
- 'scheduledRemoves ' => $ this ->scheduledRemoves ,
549
- 'scheduledIfconfig ' => $ this ->scheduledIfconfig ,
550
- 'scheduledPaths ' => $ this ->scheduledPaths ,
551
- 'elementsToSort ' => $ this ->elementsToSort ,
552
- 'brokenParent ' => $ this ->brokenParent ,
553
- ];
552
+ $ result = [];
553
+ foreach ($ this ->propertyMap as $ property ) {
554
+ $ result [$ property ] = $ this ->{$ property };
555
+ }
556
+
557
+ return $ result ;
554
558
}
555
559
556
560
/**
@@ -559,19 +563,22 @@ public function __toArray()
559
563
*
560
564
* @param array $data
561
565
* @return void
562
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
563
- * @SuppressWarnings(PHPMD.NPathComplexity)
564
566
*/
565
567
public function populateWithArray (array $ data )
566
568
{
567
- $ this ->scheduledStructure = isset ($ data ['scheduledStructure ' ]) ? $ data ['scheduledStructure ' ] : [];
568
- $ this ->scheduledData = isset ($ data ['scheduledData ' ]) ? $ data ['scheduledData ' ] : [];
569
- $ this ->scheduledElements = isset ($ data ['scheduledElements ' ]) ? $ data ['scheduledElements ' ] : [];
570
- $ this ->scheduledMoves = isset ($ data ['scheduledMoves ' ]) ? $ data ['scheduledMoves ' ] : [];
571
- $ this ->scheduledRemoves = isset ($ data ['scheduledRemoves ' ]) ? $ data ['scheduledRemoves ' ] : [];
572
- $ this ->scheduledIfconfig = isset ($ data ['scheduledIfconfig ' ]) ? $ data ['scheduledIfconfig ' ] : [];
573
- $ this ->scheduledPaths = isset ($ data ['scheduledPaths ' ]) ? $ data ['scheduledPaths ' ] : [];
574
- $ this ->elementsToSort = isset ($ data ['elementsToSort ' ]) ? $ data ['elementsToSort ' ] : [];
575
- $ this ->brokenParent = isset ($ data ['brokenParent ' ]) ? $ data ['brokenParent ' ] : [];
569
+ foreach ($ this ->propertyMap as $ property ) {
570
+ $ this ->{$ property } = $ this ->getDataValue ($ property , $ data );
571
+ }
572
+ }
573
+
574
+ /**
575
+ * Get value from array by key.
576
+ *
577
+ * @param string $name
578
+ * @param array $data
579
+ * @return array
580
+ */
581
+ private function getDataValue ($ name , array $ data ) {
582
+ return isset ($ data [$ name ]) ? $ data [$ name ] : [];
576
583
}
577
584
}
0 commit comments