<commit_before><?php

/**
 * @file
 * Contains \Jkribeiro\Composer\ComposerHydrationHandler.
 */

namespace Jkribeiro\Composer;

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

/**
 * Composer Hydration Handler Class.
 */
class ComposerHydrationHandler
{
    const REPLACE_ARG = '--replace';
    const MAGIC_VAR_BASENAME = '{%BASENAME%}';

    /**
     * @var Event Object
     */
    public $event;

    /**
     * @var string
     */
    public $basePath;

    /**
     * Class ComposerHydrationHandler Constructor.
     *
     * @param object $event
     *   Composer Event object.
     *
     * @param string $basePath
     *   Path where the hydration will be performed.
     */
    public function __construct(Event $event, $basePath)
    {
        $this->event = $event;
        $this->basePath = $basePath;
    }

    /**
     * Checks if the given command argument is available.
     *
     * @param string $argumentName
     *   Command argument name to be verified.
     *
     * @return bool
     *   Returns TRUE in case of success, FALSE otherwise.
     */
    public function cmdArgumentExist($argumentName)
    {
        return in_array($argumentName, array(self::REPLACE_ARG));
    }

    /**
     * Returns all magic variables available.
     *
     * @return array
     *   Returns an array containing all magic variables available.
     */
    public function getMagicVariables()
    {
        return array(
            self::MAGIC_VAR_BASENAME,
        );
    }

    /**
     * Checks if the given replace value is a magic variable.
     *
     * @return bool
     *   Returns TRUE in case of success, FALSE otherwise.
     */
    public function isMagicVariable($replace_value)
    {
        return in_array($replace_value, $this->getMagicVariables());
    }

    /**
     * Returns the magic value of a magic variable.
     *
     * @return string
     *   The magic value.
     */
    public function getMagicVariableValue($variable)
    {
        switch ($variable) {
            case self::MAGIC_VAR_BASENAME:
                return basename(realpath("."));
                break;
        }

        return null;
    }

    /**
     * Returns an array containing the replace values from command argument.
     *
     * @param string $argValues
     *   Command argument replace value.
     *
     * @return array
     *   An array, following the format: SEARCH => REPLACE.
     */
    public function getReplaceValuesFromArgument($argValues)
    {
        $replaceValues = array();

        $argValues = explode(',', $argValues);
        foreach ($argValues as $argValue) {
            $argValue = explode(':', $argValue);<commit_msg>Added magic constant UCFIRST_BASENAME, to capitalize the first character of the basename.<commit_after><?php

/**
 * @file
 * Contains \Jkribeiro\Composer\ComposerHydrationHandler.
 */

namespace Jkribeiro\Composer;

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

/**
 * Composer Hydration Handler Class.
 */
class ComposerHydrationHandler
{
    const REPLACE_ARG = '--replace';
    const MAGIC_VAR_BASENAME = '{%BASENAME%}';
    const MAGIC_VAR_UCFIRST_BASENAME = '{%UCFIRST_BASENAME%}';

    /**
     * @var Event Object
     */
    public $event;

    /**
     * @var string
     */
    public $basePath;

    /**
     * Class ComposerHydrationHandler Constructor.
     *
     * @param object $event
     *   Composer Event object.
     *
     * @param string $basePath
     *   Path where the hydration will be performed.
     */
    public function __construct(Event $event, $basePath)
    {
        $this->event = $event;
        $this->basePath = $basePath;
    }

    /**
     * Checks if the given command argument is available.
     *
     * @param string $argumentName
     *   Command argument name to be verified.
     *
     * @return bool
     *   Returns TRUE in case of success, FALSE otherwise.
     */
    public function cmdArgumentExist($argumentName)
    {
        return in_array($argumentName, array(self::REPLACE_ARG));
    }

    /**
     * Returns all magic variables available.
     *
     * @return array
     *   Returns an array containing all magic variables available.
     */
    public function getMagicVariables()
    {
        return array(
            self::MAGIC_VAR_BASENAME,
            self::MAGIC_VAR_UCFIRST_BASENAME,
        );
    }

    /**
     * Checks if the given replace value is a magic variable.
     *
     * @return bool
     *   Returns TRUE in case of success, FALSE otherwise.
     */
    public function isMagicVariable($replace_value)
    {
        return in_array($replace_value, $this->getMagicVariables());
    }

    /**
     * Returns the magic value of a magic variable.
     *
     * @return string
     *   The magic value.
     */
    public function getMagicVariableValue($variable)
    {
        switch ($variable) {
            case self::MAGIC_VAR_BASENAME:
                return basename(realpath("."));
                break;

            case self::MAGIC_VAR_UCFIRST_BASENAME:
                return ucfirst(basename(realpath(".")));
                break;
        }

        return null;
    }

    /**
     * Returns an array containing the replace values from command argument.
     *
     * @param string $argValues
     *   Command argument replace value.
     *
     * @return array
     *   An array, following the format: SEARCH => REPLACE.
     */
    public function getReplaceValuesFromArgument($argValues)
    {
        $replaceValues = array();

        $argValues = explode(',', $argValues);
        foreach ($argValues as $argValue) {
            $argValue = explode(':', $argValue);
{'fraction_non_alphanumeric': 0.102803738317757, 'fraction_numerical': 0.0, 'mean_word_length': 2.107945205479452, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6027125', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1604, 'n_words': 429}