@@ -24,7 +24,6 @@ abstract class AbstractCondition extends \Magento\Framework\DataObject implement
2424{
2525 /**
2626 * Defines which operators will be available for this condition
27- *
2827 * @var string
2928 */
3029 protected $ _inputType = null ;
@@ -84,17 +83,13 @@ public function __construct(Context $context, array $data = [])
8483
8584 $ options = $ this ->getAttributeOptions ();
8685 if ($ options ) {
87- foreach (array_keys ($ options ) as $ attr ) {
88- $ this ->setAttribute ($ attr );
89- break ;
90- }
86+ reset ($ options );
87+ $ this ->setAttribute (key ($ options ));
9188 }
9289 $ options = $ this ->getOperatorOptions ();
9390 if ($ options ) {
94- foreach (array_keys ($ options ) as $ operator ) {
95- $ this ->setOperator ($ operator );
96- break ;
97- }
91+ reset ($ options );
92+ $ this ->setOperator (key ($ options ));
9893 }
9994 }
10095
@@ -160,14 +155,13 @@ public function getForm()
160155 */
161156 public function asArray (array $ arrAttributes = [])
162157 {
163- $ out = [
158+ return [
164159 'type ' => $ this ->getType (),
165160 'attribute ' => $ this ->getAttribute (),
166161 'operator ' => $ this ->getOperator (),
167162 'value ' => $ this ->getValue (),
168163 'is_value_processed ' => $ this ->getIsValueParsed (),
169164 ];
170- return $ out ;
171165 }
172166
173167 /**
@@ -205,7 +199,7 @@ public function getMappedSqlField()
205199 */
206200 public function asXml ()
207201 {
208- $ xml = "<type> " .
202+ return "<type> " .
209203 $ this ->getType () .
210204 "</type> " .
211205 "<attribute> " .
@@ -217,7 +211,6 @@ public function asXml()
217211 "<value> " .
218212 $ this ->getValue () .
219213 "</value> " ;
220- return $ xml ;
221214 }
222215
223216 /**
@@ -244,8 +237,7 @@ public function loadXml($xml)
244237 if (is_string ($ xml )) {
245238 $ xml = simplexml_load_string ($ xml );
246239 }
247- $ arr = (array )$ xml ;
248- $ this ->loadArray ($ arr );
240+ $ this ->loadArray ((array )$ xml );
249241 return $ this ;
250242 }
251243
@@ -304,10 +296,7 @@ public function loadOperatorOptions()
304296 */
305297 public function getInputType ()
306298 {
307- if (null === $ this ->_inputType ) {
308- return 'string ' ;
309- }
310- return $ this ->_inputType ;
299+ return null === $ this ->_inputType ? 'string ' : $ this ->_inputType ;
311300 }
312301
313302 /**
@@ -348,12 +337,11 @@ public function loadValueOptions()
348337 */
349338 public function getValueSelectOptions ()
350339 {
351- $ valueOption = $ opt = [];
340+ $ opt = [];
352341 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+ }
357345 }
358346 return $ opt ;
359347 }
@@ -470,22 +458,20 @@ public function getNewChildName()
470458 */
471459 public function asHtml ()
472460 {
473- $ html = $ this ->getTypeElementHtml () .
461+ return $ this ->getTypeElementHtml () .
474462 $ this ->getAttributeElementHtml () .
475463 $ this ->getOperatorElementHtml () .
476464 $ this ->getValueElementHtml () .
477465 $ this ->getRemoveLinkHtml () .
478466 $ this ->getChooserContainerHtml ();
479- return $ html ;
480467 }
481468
482469 /**
483470 * @return string
484471 */
485472 public function asHtmlRecursive ()
486473 {
487- $ html = $ this ->asHtml ();
488- return $ html ;
474+ return $ this ->asHtml ();
489475 }
490476
491477 /**
@@ -520,9 +506,10 @@ public function getTypeElementHtml()
520506 public function getAttributeElement ()
521507 {
522508 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 ));
526513 }
527514 }
528515 return $ this ->getForm ()->addField (
@@ -558,10 +545,8 @@ public function getOperatorElement()
558545 {
559546 $ options = $ this ->getOperatorSelectOptions ();
560547 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 ' ]);
565550 }
566551
567552 $ elementId = sprintf ('%s__%s__operator ' , $ this ->getPrefix (), $ this ->getId ());
@@ -654,8 +639,7 @@ public function getValueElementHtml()
654639 public function getAddLinkHtml ()
655640 {
656641 $ 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 ' ) . '"/> ' ;
659643 }
660644
661645 /**
@@ -676,11 +660,7 @@ public function getRemoveLinkHtml()
676660 public function getChooserContainerHtml ()
677661 {
678662 $ 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> ' : '' ;
684664 }
685665
686666 /**
@@ -690,8 +670,7 @@ public function getChooserContainerHtml()
690670 */
691671 public function asString ($ format = '' )
692672 {
693- $ str = $ this ->getAttributeName () . ' ' . $ this ->getOperatorName () . ' ' . $ this ->getValueName ();
694- return $ str ;
673+ return $ this ->getAttributeName () . ' ' . $ this ->getOperatorName () . ' ' . $ this ->getValueName ();
695674 }
696675
697676 /**
@@ -700,8 +679,7 @@ public function asString($format = '')
700679 */
701680 public function asStringRecursive ($ level = 0 )
702681 {
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 ();
705683 }
706684
707685 /**
@@ -740,12 +718,10 @@ public function validateAttribute($validatedValue)
740718 case '== ' :
741719 case '!= ' :
742720 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 )) {
747722 return false ;
748723 }
724+ $ result = !empty (array_intersect ($ value , $ validatedValue ));
749725 } else {
750726 if (is_array ($ validatedValue )) {
751727 $ result = count ($ validatedValue ) == 1 && array_shift ($ validatedValue ) == $ value ;
@@ -759,18 +735,16 @@ public function validateAttribute($validatedValue)
759735 case '> ' :
760736 if (!is_scalar ($ validatedValue )) {
761737 return false ;
762- } else {
763- $ result = $ validatedValue <= $ value ;
764738 }
739+ $ result = $ validatedValue <= $ value ;
765740 break ;
766741
767742 case '>= ' :
768743 case '< ' :
769744 if (!is_scalar ($ validatedValue )) {
770745 return false ;
771- } else {
772- $ result = $ validatedValue >= $ value ;
773746 }
747+ $ result = $ validatedValue >= $ value ;
774748 break ;
775749
776750 case '{} ' :
@@ -783,12 +757,11 @@ public function validateAttribute($validatedValue)
783757 }
784758 }
785759 } 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 )) {
790761 return false ;
791762 }
763+ $ result = array_intersect ($ value , $ validatedValue );
764+ $ result = !empty ($ result );
792765 } else {
793766 if (is_array ($ validatedValue )) {
794767 $ result = in_array ($ value , $ validatedValue );
@@ -833,13 +806,13 @@ protected function _compareValues($validatedValue, $value, $strict = true)
833806 {
834807 if ($ strict && is_numeric ($ validatedValue ) && is_numeric ($ value )) {
835808 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 );
842809 }
810+
811+ $ validatePattern = preg_quote ($ validatedValue , '~ ' );
812+ if ($ strict ) {
813+ $ validatePattern = '^ ' . $ validatePattern . '$ ' ;
814+ }
815+ return (bool )preg_match ('~ ' . $ validatePattern . '~iu ' , $ value );
843816 }
844817
845818 /**
0 commit comments