<commit_before><?php

/**
 * Class Ecocode_Profiler_Helper_Rewrite
 *
 * taken from the awesome b98-magerun:
 * https://github.com/netz98/n98-magerun/blob/master/src/N98/Magento/Command/Developer/Module/Rewrite/ConflictsCommand.php#L49-L55
 */
class Ecocode_Profiler_Helper_Rewrite extends Mage_Core_Helper_Abstract
{
    protected $_rewrites     = null;
    protected $_rewriteTypes = [
        'blocks',
        'helpers',
        'models',
    ];


    /**
     * Return all rewrites
     *
     * @return array
     */
    public function getRewrites()
    {
        if ($this->_rewrites === null) {
            $prototype = $this->_rewriteTypes;
            $return    = array_combine($prototype, array_fill(0, count($prototype), []));
            // Load config of each module because modules can overwrite config each other. Global config is already merged
            $modules = \Mage::getConfig()->getNode('modules')->children();
            foreach ($modules as $moduleName => $moduleData) {
                // Check only active modules
                if (!$moduleData->is('active')) {
                    continue;
                }
                // Load config of module
                $configXmlFile = \Mage::getConfig()->getModuleDir('etc', $moduleName) . DIRECTORY_SEPARATOR . 'config.xml';
                if (!is_readable($configXmlFile)) {
                    continue;
                }
                $xml = \simplexml_load_file($configXmlFile);
                if (!$xml) {
                    continue;
                }
                $rewriteElements = $xml->xpath('//*/*/rewrite');
                foreach ($rewriteElements as $element) {
                    $type = \simplexml_import_dom(dom_import_simplexml($element)->parentNode->parentNode)->getName();
                    if (!isset($return[$type])) {
                        continue;
                    }
                    foreach ($element->children() as $child) {
                        $groupClassName = \simplexml_import_dom(dom_import_simplexml($element)->parentNode)->getName();
                        if (!isset($return[$type][$groupClassName . '/' . $child->getName()])) {
                            $return[$type][$groupClassName . '/' . $child->getName()] = [];
                        }
                        $return[$type][$groupClassName . '/' . $child->getName()][] = (string)$child;
                    }
                }
            }
            $this->_rewrites = $return;
        }
        return $this->_rewrites;
    }

    public function getRewriteConflicts()
    {
        $conflicts = [];
        $rewrites  = $this->getRewrites();
        foreach ($rewrites as $type => $data) {
            if (!is_array($data)) {
                continue;
            }
            foreach ($data as $class => $rewriteClasses) {
                if (!$this->_isInheritanceConflict($rewriteClasses)) {
                    continue;
                }
                $conflicts[] = [
                    'type'         => $type,
                    'class'        => $class,
                    'rewrites'     => $rewriteClasses,
                    'loaded_class' => $this->_getLoadedClass($type, $class),
                ];
            }
        }
        return $conflicts;
    }<commit_msg>master corrected rewrite detection<commit_after><?php

/**
 * Class Ecocode_Profiler_Helper_Rewrite
 *
 * taken from the awesome b98-magerun:
 * https://github.com/netz98/n98-magerun/blob/master/src/N98/Magento/Command/Developer/Module/Rewrite/ConflictsCommand.php#L49-L55
 */
class Ecocode_Profiler_Helper_Rewrite extends Mage_Core_Helper_Abstract
{
    protected $_rewrites     = null;
    protected $_rewriteTypes = [
        'blocks',
        'helpers',
        'models',
    ];


    /**
     * Return all rewrites
     *
     * @return array
     */
    public function getRewrites()
    {
        if ($this->_rewrites === null) {
            $files      = ['config.xml', 'development.xml'];
            $prototype = $this->_rewriteTypes;
            $return    = array_combine($prototype, array_fill(0, count($prototype), []));
            // Load config of each module because modules can overwrite config each other. Global config is already merged
            $modules = \Mage::getConfig()->getNode('modules')->children();
            foreach ($modules as $moduleName => $moduleData) {
                // Check only active modules
                if (!$moduleData->is('active')) {
                    continue;
                }
                // Load config of module
                foreach ($files as $file) {

                    $configXmlFile = \Mage::getConfig()->getModuleDir('etc', $moduleName) . DIRECTORY_SEPARATOR . $file;
                    if (!is_readable($configXmlFile)) {
                        continue;
                    }
                    $xml = \simplexml_load_file($configXmlFile);
                    if (!$xml) {
                        continue;
                    }
                    $rewriteElements = $xml->xpath('//*/*/rewrite');
                    foreach ($rewriteElements as $element) {
                        $type = \simplexml_import_dom(dom_import_simplexml($element)->parentNode->parentNode)->getName();
                        if (!isset($return[$type])) {
                            continue;
                        }
                        foreach ($element->children() as $child) {
                            $groupClassName = \simplexml_import_dom(dom_import_simplexml($element)->parentNode)->getName();
                            if (!isset($return[$type][$groupClassName . '/' . $child->getName()])) {
                                $return[$type][$groupClassName . '/' . $child->getName()] = [];
                            }
                            $return[$type][$groupClassName . '/' . $child->getName()][] = (string)$child;
                        }
                    }
                }
            }
            $this->_rewrites = $return;
        }
        return $this->_rewrites;
    }

    public function getRewriteConflicts()
    {
        $conflicts = [];
        $rewrites  = $this->getRewrites();
        foreach ($rewrites as $type => $data) {
            if (!is_array($data)) {
                continue;
            }
            foreach ($data as $class => $rewriteClasses) {
                if (!$this->_isInheritanceConflict($rewriteClasses)) {
                    continue;
                }
                $conflicts[] = [
                    'type'         => $type,
                    'class'        => $class,
                    'rewrites'     => $rewriteClasses,
                    'loaded_class' => $this->_getLoadedClass($type, $class),
                ];
            }
        }
        return $conflicts;
    }
{'fraction_non_alphanumeric': 0.13159437280187572, 'fraction_numerical': 0.0038100820633059787, 'mean_word_length': 1.4453600859906843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 19}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5321112', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1704, 'n_words': 308}