@@ -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,11 @@ 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
+ $ this ->setAttribute (key ($ options ));
91
87
}
92
88
$ options = $ this ->getOperatorOptions ();
93
89
if ($ options ) {
94
- foreach (array_keys ($ options ) as $ operator ) {
95
- $ this ->setOperator ($ operator );
96
- break ;
97
- }
90
+ $ this ->setOperator (key ($ options ));
98
91
}
99
92
}
100
93
@@ -160,14 +153,13 @@ public function getForm()
160
153
*/
161
154
public function asArray (array $ arrAttributes = [])
162
155
{
163
- $ out = [
156
+ return [
164
157
'type ' => $ this ->getType (),
165
158
'attribute ' => $ this ->getAttribute (),
166
159
'operator ' => $ this ->getOperator (),
167
160
'value ' => $ this ->getValue (),
168
161
'is_value_processed ' => $ this ->getIsValueParsed (),
169
162
];
170
- return $ out ;
171
163
}
172
164
173
165
/**
@@ -205,7 +197,7 @@ public function getMappedSqlField()
205
197
*/
206
198
public function asXml ()
207
199
{
208
- $ xml = "<type> " .
200
+ return "<type> " .
209
201
$ this ->getType () .
210
202
"</type> " .
211
203
"<attribute> " .
@@ -217,7 +209,6 @@ public function asXml()
217
209
"<value> " .
218
210
$ this ->getValue () .
219
211
"</value> " ;
220
- return $ xml ;
221
212
}
222
213
223
214
/**
@@ -244,8 +235,7 @@ public function loadXml($xml)
244
235
if (is_string ($ xml )) {
245
236
$ xml = simplexml_load_string ($ xml );
246
237
}
247
- $ arr = (array )$ xml ;
248
- $ this ->loadArray ($ arr );
238
+ $ this ->loadArray ((array )$ xml );
249
239
return $ this ;
250
240
}
251
241
@@ -304,10 +294,7 @@ public function loadOperatorOptions()
304
294
*/
305
295
public function getInputType ()
306
296
{
307
- if (null === $ this ->_inputType ) {
308
- return 'string ' ;
309
- }
310
- return $ this ->_inputType ;
297
+ return null === $ this ->_inputType ? 'string ' : $ this ->_inputType ;
311
298
}
312
299
313
300
/**
@@ -348,12 +335,11 @@ public function loadValueOptions()
348
335
*/
349
336
public function getValueSelectOptions ()
350
337
{
351
- $ valueOption = $ opt = [];
338
+ $ opt = [];
352
339
if ($ this ->hasValueOption ()) {
353
- $ valueOption = (array )$ this ->getValueOption ();
354
- }
355
- foreach ($ valueOption as $ key => $ value ) {
356
- $ opt [] = ['value ' => $ key , 'label ' => $ value ];
340
+ foreach ((array )$ this ->getValueOption () as $ key => $ value ) {
341
+ $ opt [] = ['value ' => $ key , 'label ' => $ value ];
342
+ }
357
343
}
358
344
return $ opt ;
359
345
}
@@ -470,22 +456,20 @@ public function getNewChildName()
470
456
*/
471
457
public function asHtml ()
472
458
{
473
- $ html = $ this ->getTypeElementHtml () .
459
+ return $ this ->getTypeElementHtml () .
474
460
$ this ->getAttributeElementHtml () .
475
461
$ this ->getOperatorElementHtml () .
476
462
$ this ->getValueElementHtml () .
477
463
$ this ->getRemoveLinkHtml () .
478
464
$ this ->getChooserContainerHtml ();
479
- return $ html ;
480
465
}
481
466
482
467
/**
483
468
* @return string
484
469
*/
485
470
public function asHtmlRecursive ()
486
471
{
487
- $ html = $ this ->asHtml ();
488
- return $ html ;
472
+ return $ this ->asHtml ();
489
473
}
490
474
491
475
/**
@@ -520,9 +504,9 @@ public function getTypeElementHtml()
520
504
public function getAttributeElement ()
521
505
{
522
506
if (null === $ this ->getAttribute ()) {
523
- foreach ( array_keys ( $ this ->getAttributeOption ()) as $ option ) {
524
- $ this -> setAttribute ( $ option );
525
- break ;
507
+ $ options = $ this ->getAttributeOptions ();
508
+ if ( $ options ) {
509
+ $ this -> setAttribute ( key ( $ options )) ;
526
510
}
527
511
}
528
512
return $ this ->getForm ()->addField (
@@ -558,10 +542,8 @@ public function getOperatorElement()
558
542
{
559
543
$ options = $ this ->getOperatorSelectOptions ();
560
544
if ($ this ->getOperator () === null ) {
561
- foreach ($ options as $ option ) {
562
- $ this ->setOperator ($ option ['value ' ]);
563
- break ;
564
- }
545
+ $ option = current ($ options );
546
+ $ this ->setOperator ($ option ['value ' ]);
565
547
}
566
548
567
549
$ elementId = sprintf ('%s__%s__operator ' , $ this ->getPrefix (), $ this ->getId ());
@@ -654,8 +636,7 @@ public function getValueElementHtml()
654
636
public function getAddLinkHtml ()
655
637
{
656
638
$ 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 ;
639
+ return '<img src=" ' . $ src . '" class="rule-param-add v-middle" alt="" title=" ' . __ ('Add ' ) . '"/> ' ;
659
640
}
660
641
661
642
/**
@@ -676,11 +657,7 @@ public function getRemoveLinkHtml()
676
657
public function getChooserContainerHtml ()
677
658
{
678
659
$ url = $ this ->getValueElementChooserUrl ();
679
- $ html = '' ;
680
- if ($ url ) {
681
- $ html = '<div class="rule-chooser" url=" ' . $ url . '"></div> ' ;
682
- }
683
- return $ html ;
660
+ return $ url ? '<div class="rule-chooser" url=" ' . $ url . '"></div> ' : '' ;
684
661
}
685
662
686
663
/**
@@ -690,8 +667,7 @@ public function getChooserContainerHtml()
690
667
*/
691
668
public function asString ($ format = '' )
692
669
{
693
- $ str = $ this ->getAttributeName () . ' ' . $ this ->getOperatorName () . ' ' . $ this ->getValueName ();
694
- return $ str ;
670
+ return $ this ->getAttributeName () . ' ' . $ this ->getOperatorName () . ' ' . $ this ->getValueName ();
695
671
}
696
672
697
673
/**
@@ -700,8 +676,7 @@ public function asString($format = '')
700
676
*/
701
677
public function asStringRecursive ($ level = 0 )
702
678
{
703
- $ str = str_pad ('' , $ level * 3 , ' ' , STR_PAD_LEFT ) . $ this ->asString ();
704
- return $ str ;
679
+ return str_pad ('' , $ level * 3 , ' ' , STR_PAD_LEFT ) . $ this ->asString ();
705
680
}
706
681
707
682
/**
@@ -740,12 +715,10 @@ public function validateAttribute($validatedValue)
740
715
case '== ' :
741
716
case '!= ' :
742
717
if (is_array ($ value )) {
743
- if (is_array ($ validatedValue )) {
744
- $ result = array_intersect ($ value , $ validatedValue );
745
- $ result = !empty ($ result );
746
- } else {
718
+ if (!is_array ($ validatedValue )) {
747
719
return false ;
748
720
}
721
+ $ result = !empty (array_intersect ($ value , $ validatedValue ));
749
722
} else {
750
723
if (is_array ($ validatedValue )) {
751
724
$ result = count ($ validatedValue ) == 1 && array_shift ($ validatedValue ) == $ value ;
@@ -759,18 +732,16 @@ public function validateAttribute($validatedValue)
759
732
case '> ' :
760
733
if (!is_scalar ($ validatedValue )) {
761
734
return false ;
762
- } else {
763
- $ result = $ validatedValue <= $ value ;
764
735
}
736
+ $ result = $ validatedValue <= $ value ;
765
737
break ;
766
738
767
739
case '>= ' :
768
740
case '< ' :
769
741
if (!is_scalar ($ validatedValue )) {
770
742
return false ;
771
- } else {
772
- $ result = $ validatedValue >= $ value ;
773
743
}
744
+ $ result = $ validatedValue >= $ value ;
774
745
break ;
775
746
776
747
case '{} ' :
@@ -783,12 +754,11 @@ public function validateAttribute($validatedValue)
783
754
}
784
755
}
785
756
} elseif (is_array ($ value )) {
786
- if (is_array ($ validatedValue )) {
787
- $ result = array_intersect ($ value , $ validatedValue );
788
- $ result = !empty ($ result );
789
- } else {
757
+ if (!is_array ($ validatedValue )) {
790
758
return false ;
791
759
}
760
+ $ result = array_intersect ($ value , $ validatedValue );
761
+ $ result = !empty ($ result );
792
762
} else {
793
763
if (is_array ($ validatedValue )) {
794
764
$ result = in_array ($ value , $ validatedValue );
@@ -833,13 +803,13 @@ protected function _compareValues($validatedValue, $value, $strict = true)
833
803
{
834
804
if ($ strict && is_numeric ($ validatedValue ) && is_numeric ($ value )) {
835
805
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
806
}
807
+
808
+ $ validatePattern = preg_quote ($ validatedValue , '~ ' );
809
+ if ($ strict ) {
810
+ $ validatePattern = '^ ' . $ validatePattern . '$ ' ;
811
+ }
812
+ return (bool )preg_match ('~ ' . $ validatePattern . '~iu ' , $ value );
843
813
}
844
814
845
815
/**
0 commit comments