From f84905c0e4a4f52b4f3553a2b97fb9c89f7026bc Mon Sep 17 00:00:00 2001
From: Oleksandr Shmyheliuk <oshmyheliuk@magento.com>
Date: Thu, 5 Jan 2017 16:52:28 +0200
Subject: [PATCH] MAGETWO-62705: Implementation

---
 .../Magento/Store/Model/Scope/Validator.php   | 31 ++++++++++++-------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/app/code/Magento/Store/Model/Scope/Validator.php b/app/code/Magento/Store/Model/Scope/Validator.php
index 77138b1460c..3bc91ea3c36 100644
--- a/app/code/Magento/Store/Model/Scope/Validator.php
+++ b/app/code/Magento/Store/Model/Scope/Validator.php
@@ -50,26 +50,35 @@ class Validator implements ValidatorInterface
             throw new LocalizedException(__('Scope can\'t be empty'));
         }
 
-        if (empty($scopeCode)) {
-            throw new LocalizedException(__('Scope code can\'t be empty'));
-        }
-
-        if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $scopeCode)) {
-            throw new LocalizedException(__('Wrong scope code format'));
-        }
+        $this->validateScopeCode($scopeCode);
 
         try {
             $scopeResolver = $this->scopeResolverPool->get($scope);
+            $scopeResolver->getScope($scopeCode)->getId();
         } catch (InvalidArgumentException $e) {
             throw new LocalizedException(__('Scope "%1" doesn\'t exist', $scope));
-        }
-
-        try {
-            $scopeResolver->getScope($scopeCode)->getId();
         } catch (NoSuchEntityException $e) {
             throw new LocalizedException(__('Scope code "%1" doesn\'t exist in scope "%2"', $scopeCode, $scope));
         }
 
         return true;
     }
+
+    /**
+     * Validate scope code
+     * Throw exception if not valid.
+     *
+     * @param $scopeCode
+     * @throws LocalizedException if scope code is empty or has a wrong format
+     */
+    private function validateScopeCode($scopeCode)
+    {
+        if (empty($scopeCode)) {
+            throw new LocalizedException(__('Scope code can\'t be empty'));
+        }
+
+        if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $scopeCode)) {
+            throw new LocalizedException(__('Wrong scope code format'));
+        }
+    }
 }
-- 
GitLab