From b98f41796650d36e44fcd2cb42d02bb09cf8ccd1 Mon Sep 17 00:00:00 2001
From: Tadhg Bowe <tadhg.bowe@screenpages.com>
Date: Sat, 7 Jul 2018 12:38:15 +0100
Subject: [PATCH] import-export-improvements #82 : configurable variations -
 not a super attribute error message improvements - code styling Travis CI
 build fixes

---
 .../Import/Product/Type/Configurable.php      | 39 ++++++++-----------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php
index 43da5661e966..5969f872616e 100644
--- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php
+++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php
@@ -332,34 +332,25 @@ private function identifySuperAttributeError($superAttrCode, $rowNum)
     {
         // This attribute code is not a super attribute. Need to give a clearer message why?
         $reasonFound = false;
-
         $codeExists = false;
-        $codeNotGlobal = false;
-        $codeNotTypeSelect = false;
+
         // Does this attribute code exist?
         $sourceAttribute = $this->doesSuperAttributeExist($superAttrCode);
-        if (count($sourceAttribute)) {
+        if (!is_null($sourceAttribute)) {
             $codeExists = true;
             // Does attribute have the correct settings?
-            if (is_array($sourceAttribute)) {
-                if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') {
-                    $codeNotGlobal = true;
-                } elseif (isset($sourceAttribute['type']) && $sourceAttribute['type'] !== 'select') {
-                    $codeNotTypeSelect = true;
-                }
+            if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') {
+                $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode);
+                $reasonFound = true;
+            } elseif (isset($sourceAttribute['type']) && $sourceAttribute['type'] !== 'select') {
+                $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode);
+                $reasonFound = true;
             }
         }
 
-        // Identify (if any) the correct fault:
         if ($codeExists === false) {
             $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode);
             $reasonFound = true;
-        } elseif ($codeNotGlobal === true) {
-            $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode);
-            $reasonFound = true;
-        } elseif ($codeNotTypeSelect === true) {
-            $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode);
-            $reasonFound = true;
         }
 
         return $reasonFound;
@@ -373,9 +364,8 @@ private function identifySuperAttributeError($superAttrCode, $rowNum)
      */
     private function doesSuperAttributeExist($superAttrCode)
     {
-        $returnFilterArray = [];
-        if (is_array(self::$commonAttributesCache))
-        {
+        $returnAttributeArray = null;
+        if (is_array(self::$commonAttributesCache)) {
             $filteredAttribute = array_filter(
                 self::$commonAttributesCache,
                 function ($element) use ($superAttrCode) {
@@ -383,10 +373,13 @@ function ($element) use ($superAttrCode) {
                 }
             );
 
-            // Return the first element of the filtered array.
-            $returnFilterArray = array_shift($filteredAttribute);
+            // Return the first element of the filtered array (if found).
+            if (count($filteredAttribute))
+            {
+                $returnAttributeArray = array_shift($filteredAttribute);
+            }
         }
-        return $returnFilterArray;
+        return $returnAttributeArray;
     }
 
     /**