Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 5c129fa

Browse files
author
Volodymyr Kublytskyi
committed
Deliver magento-partners/magento2ce#25: used implementation from magento-partners/magento2ce#15 to reduce cyclomatic complexity to appropriate level
1 parent ce3bb4f commit 5c129fa

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

app/code/Magento/Theme/Model/Design/Config/Validator.php

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,8 @@ public function validate(DesignConfigInterface $designConfig)
6464
}
6565

6666
foreach ($elements as $name => $data) {
67-
// Load template object by configured template id
68-
$template = $this->templateFactory->create();
69-
$scopeId = false;
70-
if ($designConfig->getScope() == 'stores') {
71-
$scopeId = $designConfig->getScopeId();
72-
}
73-
$template->emulateDesign($scopeId);
7467
$templateId = $data['value'];
75-
if (is_numeric($templateId)) {
76-
$template->load($templateId);
77-
} else {
78-
$template->loadDefault($templateId);
79-
}
80-
$text = $template->getTemplateText();
81-
$template->revertDesign();
68+
$text = $this->getTemplateText($templateId, $designConfig);
8269
// Check if template body has a reference to the same config path
8370
if (preg_match_all(Template::CONSTRUCTION_TEMPLATE_PATTERN, $text, $constructions, PREG_SET_ORDER)) {
8471
foreach ($constructions as $construction) {
@@ -98,6 +85,36 @@ public function validate(DesignConfigInterface $designConfig)
9885
}
9986
}
10087

88+
/**
89+
* @param $designConfig
90+
* @return mixed
91+
*/
92+
private function getScopeId($designConfig)
93+
{
94+
if ($designConfig->getScope() == 'stores') {
95+
return $designConfig->getScopeId();
96+
}
97+
return false;
98+
}
99+
/**
100+
* @param $designConfig
101+
* @return mixed
102+
*/
103+
private function getTemplateText($templateId, $designConfig)
104+
{
105+
// Load template object by configured template id
106+
$template = $this->templateFactory->create();
107+
$template->emulateDesign($this->getScopeId($designConfig));
108+
if (is_numeric($templateId)) {
109+
$template->load($templateId);
110+
} else {
111+
$template->loadDefault($templateId);
112+
}
113+
$text = $template->getTemplateText();
114+
$template->revertDesign();
115+
return $text;
116+
}
117+
101118
/**
102119
* Return associative array of parameters.
103120
*

0 commit comments

Comments
 (0)