Skip to content

Commit

Permalink
Merge pull request #5 from magefan/5202-scope-considered-during-detec…
Browse files Browse the repository at this point in the history
…tion

add scope detection
  • Loading branch information
magefan authored Nov 29, 2021
2 parents 7676222 + c1a5a75 commit 2c49169
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
55 changes: 39 additions & 16 deletions Model/Config/Reader/Dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ public function getClassRewriteConflicts()
$type = $preference->getAttribute('type');
if ($for && $type) {
if (!isset($conflicts[$for])) {
$conflicts[$for] = [
'classes' => []
];
$conflicts[$for] = [];
}

if (!in_array($type, $conflicts[$for]['classes'])) {
$conflicts[$for]['classes'][] = $type;
if (!isset($conflicts[$for][$scope])) {
$conflicts[$for][$scope] = [];
}
if (!in_array($type, $conflicts[$for][$scope])) {
$conflicts[$for][$scope][] = $type;
}
}
}
Expand All @@ -41,23 +42,45 @@ public function getClassRewriteConflicts()
}
}

foreach ($conflicts as $origClass => $item) {
$hasNoMagentoClasses = false;
foreach ($item['classes'] as $class) {
if (strpos($class, 'Magento\\') !== 0 && strpos($class, '\\Magento\\') !== 0) {
$hasNoMagentoClasses = true;
foreach ($conflicts as $for => $scopeClasses) {
foreach ($scopeClasses as $scope => $classes) {
$hasNoMagentoClasses = false;
foreach ($classes as $class) {
if (strpos($class, 'Magento\\') !== 0 && strpos($class, '\\Magento\\') !== 0) {
$hasNoMagentoClasses = true;
}
}

if (!$hasNoMagentoClasses) {
unset($conflicts[$for][$scope]);
}

if ($scope != 'global') {
$isInGlobal = (isset($conflicts[$for]['global']) && count($conflicts[$for]['global']));
if (!$isInGlobal && count($classes) < 2) {
unset($conflicts[$for][$scope]);
}
}
}

if (!$hasNoMagentoClasses) {
unset($conflicts[$origClass]);
if (strpos($for, 'Interface') !== false && count($classes) < 2) {
unset($conflicts[$for][$scope]);
}
}
}

$result = [];
foreach ($conflicts as $for => $scopeClasses) {
foreach ($scopeClasses as $scope => $classes) {
if (!isset($result[$for])) {
$result[$for] = [
'classes' => []
];
}

if (strpos($origClass, 'Interface') !== false && count($item['classes']) < 2) {
unset($conflicts[$origClass]);
$result[$for]['classes'] = array_merge($result[$for]['classes'], $classes);
}
}

return $conflicts;
return $result;
}
}
6 changes: 4 additions & 2 deletions view/adminhtml/templates/list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* Glory to Ukraine! Glory to the heroes!
*/
?>

<?php
/** @var $block \Magefan\ConflictDetector\Block\Adminhtml\ConflictList */
?>
<?php
$classRewriteConflicts = $block->getClassRewriteConflicts()
?>
Expand Down Expand Up @@ -66,4 +68,4 @@
<p>
<br/><br/><br/><br/>
Created by <a href="https://magefan.com" target="_blank">Magefan</a>.
</p>
</p>

0 comments on commit 2c49169

Please sign in to comment.