<commit_before><?php

namespace MediaMonks\MssqlBundle\Composer;

use Composer\Script\CommandEvent;
use Symfony\Component\Finder\Finder;

/**
 * @author <NAME> <<EMAIL>>
 */
class ScriptHandler
{
    /**
     * @param CommandEvent $event
     */
    public static function ensureDoctrineORMOverrides(CommandEvent $event)
    {
        $doctrineOrmPath = self::getDoctrineOrmPath();
        if(!file_exists($doctrineOrmPath)) {
            return;
        }

        $finder = new Finder();
        $finder->files()->in($doctrineOrmPath)
            ->exclude([
                'Decorator',
                'Event',
                'Id',
                'Internal',
                'Proxy',
                'Query',
                'Tools',
                'Repository',
                'Tools',
                'Utility'
            ]);

        $baseFind    = 'use Doctrine\ORM\Persisters\Entity\\';
        $baseReplace = 'use MediaMonks\MssqlBundle\Doctrine\ORM\Persisters\Entity\\';
        $replaces    = [
            'BasicEntityPersister',
            'SingleTablePersister'
        ];

        foreach ($finder as $file) {
            $data = file_get_contents($file->getRealpath());
            if (strpos($data, $baseFind) === false) {
                continue;
            }
            foreach ($replaces as $replace) {
                $data = str_replace($baseFind . $replace, $baseReplace . $replace, $data);
            }
            file_put_contents($file->getRealpath(), $data);
        }
    }

    /**
     * @return string
     */
    public static function getDoctrineOrmPath()
    {
        $currentDirectory = __DIR__;
        if(strpos($currentDirectory, 'vendor/mediamonks') === false) {
            return $currentDirectory . '/../../../../vendor/doctrine/orm/lib/'; // for local development
        }
        return $currentDirectory . '/../../../doctrine/orm/lib/'; // when installed as a package
    }
}<commit_msg>- Using vendor folder from composer config now<commit_after><?php

namespace MediaMonks\MssqlBundle\Composer;

use Composer\Script\Event;
use Symfony\Component\Finder\Finder;

/**
 * @author <NAME> <<EMAIL>>
 */
class ScriptHandler
{
    const DOCTRINE_ORM_PACKAGE_PATH = '/doctrine/orm/lib/';

    /**
     * @param Event $event
     */
    public static function ensureDoctrineORMOverrides(Event $event)
    {
        $doctrineOrmPath = self::getDoctrineOrmPath($event);
        if (!file_exists($doctrineOrmPath)) {
            return; // Doctrine ORM does not seem be installed
        }

        $finder = new Finder();
        $finder->files()->in($doctrineOrmPath)
            ->exclude([
                'Decorator',
                'Event',
                'Id',
                'Internal',
                'Proxy',
                'Query',
                'Tools',
                'Repository',
                'Tools',
                'Utility'
            ]);

        $baseFind    = 'use Doctrine\ORM\Persisters\Entity\\';
        $baseReplace = 'use MediaMonks\MssqlBundle\Doctrine\ORM\Persisters\Entity\\';
        $replaces    = [
            'BasicEntityPersister',
            'SingleTablePersister'
        ];

        foreach ($finder as $file) {
            $data = file_get_contents($file->getRealpath());
            if (strpos($data, $baseFind) === false) {
                continue;
            }
            foreach ($replaces as $replace) {
                $data = str_replace($baseFind . $replace, $baseReplace . $replace, $data);
            }
            file_put_contents($file->getRealpath(), $data);
        }
    }

    /**
     * @param Event $event
     * @return string
     */
    public static function getDoctrineOrmPath(Event $event)
    {
        return $event->getComposer()->getConfig()->get('vendor-dir') . self::DOCTRINE_ORM_PACKAGE_PATH;
    }
}
{'fraction_non_alphanumeric': 0.13574778530484627, 'fraction_numerical': 0.0, 'mean_word_length': 1.714992927864215, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5738735', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1070, 'n_words': 198}