<commit_before><?php

namespace Jelix\ComposerPlugin;
use Composer\Util\Filesystem;
use Composer\Package\PackageInterface;

class JelixParameters {

    const VERSION = 1;
    protected $packagesInfos = array();

    protected $fs;

    /**
     * @var string
     */
    protected $vendorDir;

    /**
     * @var string
     */
    protected $varConfigDir;

    /**
     * @var string
     */
    protected $appDir = null;

    function __construct($vendorDir)
    {
        $this->fs = new Filesystem();
        $this->vendorDir = $vendorDir;
    }

    function loadFromFile($filepath)
    {
        $content = json_decode(file_get_contents($filepath), true);
        if (!isset($content['packages'])) {
            return;
        }
        foreach($content['packages'] as $package => $infos) {
            $content = array_merge_recursive(array('modules-dirs'=>array(),
                                        'plugins-dirs'=>array(),
                                        'modules'=>array()),
                                    $infos);
            $parameters = new JelixPackageParameters($package);
            $parameters->setModulesDirs($content['modules-dirs']);
            $parameters->setPluginsDirs($content['plugins-dirs']);
            $parameters->setSingleModuleDirs($content['modules']);
            $this->packagesInfos[$package] = $parameters;
        }
    }

    function saveToFile($filepath)
    {
        $content = array( 'version'=>1, 'packages'=>array());
        foreach($this->packagesInfos as $package => $parameters) {
            $content['packages'][$package] = array(
                'modules-dirs'=>$parameters->getModulesDirs(),
                'plugins-dirs'=>$parameters->getPluginsDirs(),
                'modules'=>$parameters->getSingleModuleDirs()
            );
        }
        file_put_contents($filepath, json_encode($content, JSON_PRETTY_PRINT));
    }

    function getAppDir() {
        return $this->appDir;
    }

    function getVarConfigDir() {
        return $this->varConfigDir;
    }

    function getVendorDir() {
        return $this->vendorDir;
    }

    /**
     * @param PackageInterface $package
     */
    function addPackage(PackageInterface $package, $packagePath, $appPackage=false)
    {
        $parameters = new JelixPackageParameters($package->getName());
        $this->packagesInfos[$package->getName()] = $parameters;

        $extra = $package->getExtra();
        if (!isset($extra['jelix'])) {
            if ($appPackage) {
                $this->appDir = $packagePath;
            }
            return;
        }

        if ($appPackage) {
            if (isset($extra['jelix']['app-dir'])) {
                if ($fs->isAbsolutePath($extra['jelix']['app-dir'])) {
                    $this->appDir = $extra['jelix']['app-dir'];
                }
                else {
                    $this->appDir = realPath($packagePath.DIRECTORY_SEPARATOR.$extra['jelix']['app-dir']);
                }
                if (!$this->appDir || !file_exists($this->appDir)) {
                    throw new ReaderException("given application dir is not set or does not exists");
                }
            }
            else {
                $this->appDir = $packagePath;
            }
            $this->appDir = rtrim($this->appDir, "/")."/";
            $this->varConfigDir = $this->appDir.'var/config';

            if (isset($extra['jelix']['var-config-dir'])) {
                if ($fs->isAbsolutePath($extra['jelix']['var-config-dir'])) {
                    $this->varConfigDir = $extra['jelix']['var-config-dir'];
                }
                else {
                    $this->varConfigDir = realPath($packagePath . DIRECTORY_SEPARATOR . $extra['jelix']['var-config-dir']);
                }
                if (!$this->varConfigDir || !file_exists($this->varConfigDir)) {
                    throw new ReaderException("given var config dir is not set or does not exists");
                }
                $this->varConfigDir = rtrim($this->varConfigDir, "/")."/";
            }
        }

        if (isset($extra['jelix']['modules-dir'])) {
            if (!is_array($extra['jelix']['modules-dir'])) {
                throw new ReaderException("Error in composer.json of ".$package->getName().": extra/jelix/modules-dir is not an array");
            }
            foreach($extra['jelix']['modules-dir'] as $path) {
                $path = realPath($packagePath.DIRECTORY_SEPARATOR.$path);
                if ($path != '') {
                    $parameters->addModulesDir($this->fs->findShortestPath($this->vendorDir, $path, true));
                }
            }
        }

        if (isset($extra['jelix']['modules'])) {
            if (!is_array($extra['jelix']['modules'])) {
                throw new ReaderException("Error in composer.json of " . $package->getName() . ": extra/jelix/modules is not an array");
            }
            foreach($extra['jelix']['modules'] as $path) {
                $path = realPath($packagePath.DIRECTORY_SEPARATOR.$path);<commit_msg>Fix variable typo<commit_after><?php

namespace Jelix\ComposerPlugin;
use Composer\Util\Filesystem;
use Composer\Package\PackageInterface;

class JelixParameters {

    const VERSION = 1;
    protected $packagesInfos = array();

    protected $fs;

    /**
     * @var string
     */
    protected $vendorDir;

    /**
     * @var string
     */
    protected $varConfigDir;

    /**
     * @var string
     */
    protected $appDir = null;

    function __construct($vendorDir)
    {
        $this->fs = new Filesystem();
        $this->vendorDir = $vendorDir;
    }

    function loadFromFile($filepath)
    {
        $content = json_decode(file_get_contents($filepath), true);
        if (!isset($content['packages'])) {
            return;
        }
        foreach($content['packages'] as $package => $infos) {
            $content = array_merge_recursive(array('modules-dirs'=>array(),
                                        'plugins-dirs'=>array(),
                                        'modules'=>array()),
                                    $infos);
            $parameters = new JelixPackageParameters($package);
            $parameters->setModulesDirs($content['modules-dirs']);
            $parameters->setPluginsDirs($content['plugins-dirs']);
            $parameters->setSingleModuleDirs($content['modules']);
            $this->packagesInfos[$package] = $parameters;
        }
    }

    function saveToFile($filepath)
    {
        $content = array( 'version'=>1, 'packages'=>array());
        foreach($this->packagesInfos as $package => $parameters) {
            $content['packages'][$package] = array(
                'modules-dirs'=>$parameters->getModulesDirs(),
                'plugins-dirs'=>$parameters->getPluginsDirs(),
                'modules'=>$parameters->getSingleModuleDirs()
            );
        }
        file_put_contents($filepath, json_encode($content, JSON_PRETTY_PRINT));
    }

    function getAppDir() {
        return $this->appDir;
    }

    function getVarConfigDir() {
        return $this->varConfigDir;
    }

    function getVendorDir() {
        return $this->vendorDir;
    }

    /**
     * @param PackageInterface $package
     */
    function addPackage(PackageInterface $package, $packagePath, $appPackage=false)
    {
        $parameters = new JelixPackageParameters($package->getName());
        $this->packagesInfos[$package->getName()] = $parameters;

        $extra = $package->getExtra();
        if (!isset($extra['jelix'])) {
            if ($appPackage) {
                $this->appDir = $packagePath;
            }
            return;
        }

        if ($appPackage) {
            if (isset($extra['jelix']['app-dir'])) {
                if ($this->fs->isAbsolutePath($extra['jelix']['app-dir'])) {
                    $this->appDir = $extra['jelix']['app-dir'];
                }
                else {
                    $this->appDir = realPath($packagePath.DIRECTORY_SEPARATOR.$extra['jelix']['app-dir']);
                }
                if (!$this->appDir || !file_exists($this->appDir)) {
                    throw new ReaderException("given application dir is not set or does not exists");
                }
            }
            else {
                $this->appDir = $packagePath;
            }
            $this->appDir = rtrim($this->appDir, "/")."/";
            $this->varConfigDir = $this->appDir.'var/config';

            if (isset($extra['jelix']['var-config-dir'])) {
                if ($this->fs->isAbsolutePath($extra['jelix']['var-config-dir'])) {
                    $this->varConfigDir = $extra['jelix']['var-config-dir'];
                }
                else {
                    $this->varConfigDir = realPath($packagePath . DIRECTORY_SEPARATOR . $extra['jelix']['var-config-dir']);
                }
                if (!$this->varConfigDir || !file_exists($this->varConfigDir)) {
                    throw new ReaderException("given var config dir is not set or does not exists");
                }
                $this->varConfigDir = rtrim($this->varConfigDir, "/")."/";
            }
        }

        if (isset($extra['jelix']['modules-dir'])) {
            if (!is_array($extra['jelix']['modules-dir'])) {
                throw new ReaderException("Error in composer.json of ".$package->getName().": extra/jelix/modules-dir is not an array");
            }
            foreach($extra['jelix']['modules-dir'] as $path) {
                $path = realPath($packagePath.DIRECTORY_SEPARATOR.$path);
                if ($path != '') {
                    $parameters->addModulesDir($this->fs->findShortestPath($this->vendorDir, $path, true));
                }
            }
        }

        if (isset($extra['jelix']['modules'])) {
            if (!is_array($extra['jelix']['modules'])) {
                throw new ReaderException("Error in composer.json of " . $package->getName() . ": extra/jelix/modules is not an array");
            }
            foreach($extra['jelix']['modules'] as $path) {
                $path = realPath($packagePath.DIRECTORY_SEPARATOR.$path);
{'fraction_non_alphanumeric': 0.1568280204643841, 'fraction_numerical': 0.0003935458480913026, 'mean_word_length': 1.8918918918918919, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2847401', 'n_tokens_mistral': 2792, 'n_tokens_neox': 2695, 'n_words': 447}