@@ -24,7 +24,6 @@ abstract class AbstractCondition extends \Magento\Framework\DataObject implement
24
24
{
25
25
/**
26
26
* Defines which operators will be available for this condition
27
- *
28
27
* @var string
29
28
*/
30
29
protected $ _inputType = null ;
@@ -84,17 +83,13 @@ public function __construct(Context $context, array $data = [])
84
83
85
84
$ options = $ this ->getAttributeOptions ();
86
85
if ($ options ) {
87
- foreach (array_keys ($ options ) as $ attr ) {
88
- $ this ->setAttribute ($ attr );
89
- break ;
90
- }
86
+ reset ($ options );
87
+ $ this ->setAttribute (key ($ options ));
91
88
}
92
89
$ options = $ this ->getOperatorOptions ();
93
90
if ($ options ) {
94
- foreach (array_keys ($ options ) as $ operator ) {
95
- $ this ->setOperator ($ operator );
96
- break ;
97
- }
91
+ reset ($ options );
92
+ $ this ->setOperator (key ($ options ));
98
93
}
99
94
}
100
95
@@ -160,14 +155,13 @@ public function getForm()
160
155
*/
161
156
public function asArray (array $ arrAttributes = [])
162
157
{
163
- $ out = [
158
+ return [
164
159
'type ' => $ this ->getType (),
165
160
'attribute ' => $ this ->getAttribute (),
166
161
'operator ' => $ this ->getOperator (),
167
162
'value ' => $ this ->getValue (),
168
163
'is_value_processed ' => $ this ->getIsValueParsed (),
169
164
];
170
- return $ out ;
171
165
}
172
166
173
167
/**
@@ -205,7 +199,7 @@ public function getMappedSqlField()
205
199
*/
206
200
public function asXml ()
207
201
{
208
- $ xml = "<type> " .
202
+ return "<type> " .
209
203
$ this ->getType () .
210
204
"</type> " .
211
205
"<attribute> " .
@@ -217,7 +211,6 @@ public function asXml()
217
211
"<value> " .
218
212
$ this ->getValue () .
219
213
"</value> " ;
220
- return $ xml ;
221
214
}
222
215
223
216
/**
@@ -244,8 +237,7 @@ public function loadXml($xml)
244
237
if (is_string ($ xml )) {
245
238
$ xml = simplexml_load_string ($ xml );
246
239
}
247
- $ arr = (array )$ xml ;
248
- $ this ->loadArray ($ arr );
240
+ $ this ->loadArray ((array )$ xml );
249
241
return $ this ;
250
242
}
251
243
@@ -304,10 +296,7 @@ public function loadOperatorOptions()
304
296
*/
305
297
public function getInputType ()
306
298
{
307
- if (null === $ this ->_inputType ) {
308
- return 'string ' ;
309
- }
310
- return $ this ->_inputType ;
299
+ return null === $ this ->_inputType ? 'string ' : $ this ->_inputType ;
311
300
}
312
301
313
302
/**
@@ -348,12 +337,11 @@ public function loadValueOptions()
348
337
*/
349
338
public function getValueSelectOptions ()
350
339
{
351
- $ valueOption = $ opt = [];
340
+ $ opt = [];
352
341
if ($ this ->hasValueOption ()) {
353
- $ valueOption = (array )$ this ->getValueOption ();
354
- }
355
- foreach ($ valueOption as $ key => $ value ) {
356
- $ opt [] = ['value ' => $ key , 'label ' => $ value ];
342
+ foreach ((array )$ this ->getValueOption () as $ key => $ value ) {
343
+ $ opt [] = ['value ' => $ key , 'label ' => $ value ];
344
+ }
357
345
}
358
346
return $ opt ;
359
347
}
@@ -470,22 +458,20 @@ public function getNewChildName()
470
458
*/
471
459
public function asHtml ()
472
460
{
473
- $ html = $ this ->getTypeElementHtml () .
461
+ return $ this ->getTypeElementHtml () .
474
462
$ this ->getAttributeElementHtml () .
475
463
$ this ->getOperatorElementHtml () .
476
464
$ this ->getValueElementHtml () .
477
465
$ this ->getRemoveLinkHtml () .
478
466
$ this ->getChooserContainerHtml ();
479
- return $ html ;
480
467
}
481
468
482
469
/**
483
470
* @return string
484
471
*/
485
472
public function asHtmlRecursive ()
486
473
{
487
- $ html = $ this ->asHtml ();
488
- return $ html ;
474
+ return $ this ->asHtml ();
489
475
}
490
476
491
477
/**
@@ -520,9 +506,10 @@ public function getTypeElementHtml()
520
506
public function getAttributeElement ()
521
507
{
522
508
if (null === $ this ->getAttribute ()) {
523
- foreach (array_keys ($ this ->getAttributeOption ()) as $ option ) {
524
- $ this ->setAttribute ($ option );
525
- break ;
509
+ $ options = $ this ->getAttributeOption ();
510
+ if ($ options ) {
511
+ reset ($ options );
512
+ $ this ->setAttribute (key ($ options ));
526
513
}
527
514
}
528
515
return $ this ->getForm ()->addField (
@@ -558,10 +545,8 @@ public function getOperatorElement()
558
545
{
559
546
$ options = $ this ->getOperatorSelectOptions ();
560
547
if ($ this ->getOperator () === null ) {
561
- foreach ($ options as $ option ) {
562
- $ this ->setOperator ($ option ['value ' ]);
563
- break ;
564
- }
548
+ $ option = reset ($ options );
549
+ $ this ->setOperator ($ option ['value ' ]);
565
550
}
566
551
567
552
$ elementId = sprintf ('%s__%s__operator ' , $ this ->getPrefix (), $ this ->getId ());
@@ -654,8 +639,7 @@ public function getValueElementHtml()
654
639
public function getAddLinkHtml ()
655
640
{
656
641
$ src = $ this ->_assetRepo ->getUrl ('images/rule_component_add.gif ' );
657
- $ html = '<img src=" ' . $ src . '" class="rule-param-add v-middle" alt="" title=" ' . __ ('Add ' ) . '"/> ' ;
658
- return $ html ;
642
+ return '<img src=" ' . $ src . '" class="rule-param-add v-middle" alt="" title=" ' . __ ('Add ' ) . '"/> ' ;
659
643
}
660
644
661
645
/**
@@ -676,11 +660,7 @@ public function getRemoveLinkHtml()
676
660
public function getChooserContainerHtml ()
677
661
{
678
662
$ url = $ this ->getValueElementChooserUrl ();
679
- $ html = '' ;
680
- if ($ url ) {
681
- $ html = '<div class="rule-chooser" url=" ' . $ url . '"></div> ' ;
682
- }
683
- return $ html ;
663
+ return $ url ? '<div class="rule-chooser" url=" ' . $ url . '"></div> ' : '' ;
684
664
}
685
665
686
666
/**
@@ -690,8 +670,7 @@ public function getChooserContainerHtml()
690
670
*/
691
671
public function asString ($ format = '' )
692
672
{
693
- $ str = $ this ->getAttributeName () . ' ' . $ this ->getOperatorName () . ' ' . $ this ->getValueName ();
694
- return $ str ;
673
+ return $ this ->getAttributeName () . ' ' . $ this ->getOperatorName () . ' ' . $ this ->getValueName ();
695
674
}
696
675
697
676
/**
@@ -700,8 +679,7 @@ public function asString($format = '')
700
679
*/
701
680
public function asStringRecursive ($ level = 0 )
702
681
{
703
- $ str = str_pad ('' , $ level * 3 , ' ' , STR_PAD_LEFT ) . $ this ->asString ();
704
- return $ str ;
682
+ return str_pad ('' , $ level * 3 , ' ' , STR_PAD_LEFT ) . $ this ->asString ();
705
683
}
706
684
707
685
/**
@@ -740,12 +718,10 @@ public function validateAttribute($validatedValue)
740
718
case '== ' :
741
719
case '!= ' :
742
720
if (is_array ($ value )) {
743
- if (is_array ($ validatedValue )) {
744
- $ result = array_intersect ($ value , $ validatedValue );
745
- $ result = !empty ($ result );
746
- } else {
721
+ if (!is_array ($ validatedValue )) {
747
722
return false ;
748
723
}
724
+ $ result = !empty (array_intersect ($ value , $ validatedValue ));
749
725
} else {
750
726
if (is_array ($ validatedValue )) {
751
727
$ result = count ($ validatedValue ) == 1 && array_shift ($ validatedValue ) == $ value ;
@@ -759,18 +735,16 @@ public function validateAttribute($validatedValue)
759
735
case '> ' :
760
736
if (!is_scalar ($ validatedValue )) {
761
737
return false ;
762
- } else {
763
- $ result = $ validatedValue <= $ value ;
764
738
}
739
+ $ result = $ validatedValue <= $ value ;
765
740
break ;
766
741
767
742
case '>= ' :
768
743
case '< ' :
769
744
if (!is_scalar ($ validatedValue )) {
770
745
return false ;
771
- } else {
772
- $ result = $ validatedValue >= $ value ;
773
746
}
747
+ $ result = $ validatedValue >= $ value ;
774
748
break ;
775
749
776
750
case '{} ' :
@@ -783,12 +757,11 @@ public function validateAttribute($validatedValue)
783
757
}
784
758
}
785
759
} elseif (is_array ($ value )) {
786
- if (is_array ($ validatedValue )) {
787
- $ result = array_intersect ($ value , $ validatedValue );
788
- $ result = !empty ($ result );
789
- } else {
760
+ if (!is_array ($ validatedValue )) {
790
761
return false ;
791
762
}
763
+ $ result = array_intersect ($ value , $ validatedValue );
764
+ $ result = !empty ($ result );
792
765
} else {
793
766
if (is_array ($ validatedValue )) {
794
767
$ result = in_array ($ value , $ validatedValue );
@@ -833,13 +806,13 @@ protected function _compareValues($validatedValue, $value, $strict = true)
833
806
{
834
807
if ($ strict && is_numeric ($ validatedValue ) && is_numeric ($ value )) {
835
808
return $ validatedValue == $ value ;
836
- } else {
837
- $ validatePattern = preg_quote ($ validatedValue , '~ ' );
838
- if ($ strict ) {
839
- $ validatePattern = '^ ' . $ validatePattern . '$ ' ;
840
- }
841
- return (bool )preg_match ('~ ' . $ validatePattern . '~iu ' , $ value );
842
809
}
810
+
811
+ $ validatePattern = preg_quote ($ validatedValue , '~ ' );
812
+ if ($ strict ) {
813
+ $ validatePattern = '^ ' . $ validatePattern . '$ ' ;
814
+ }
815
+ return (bool )preg_match ('~ ' . $ validatePattern . '~iu ' , $ value );
843
816
}
844
817
845
818
/**
0 commit comments