<commit_before><?php
/*
 * This file is part of Rocketeer
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Rocketeer\Services\Tasks;

use Closure;
use Illuminate\Support\Str;
use Rocketeer\Abstracts\AbstractTask;
use Rocketeer\Binaries\AnonymousBinary;
use Rocketeer\Exceptions\TaskCompositionException;
use Rocketeer\Traits\HasLocator;

/**
 * Handles creating tasks from strings, closures, AbstractTask children, etc.
 *
 * @author <NAME> <<EMAIL>>
 */
class TasksBuilder
{
    use HasLocator;

    /**
     * Build a binary.
     *
     * @param string $binary
     *
     * @return \Rocketeer\Abstracts\AbstractBinary|\Rocketeer\Abstracts\AbstractPackageManager
     */
    public function buildBinary($binary)
    {
        $class = $this->findQualifiedName($binary, [
            'Rocketeer\Binaries\PackageManagers\%s',
            'Rocketeer\Binaries\%s',
        ]);

        // If there is a class by that name
        if ($class) {
            return new $class($this->app);
        }

        // Else wrap the command in an AnonymousBinary
        $anonymous = new AnonymousBinary($this->app);
        $anonymous->setBinary($binary);

        return $anonymous;
    }

    //////////////////////////////////////////////////////////////////////
    ////////////////////////////// COMMANDS //////////////////////////////
    //////////////////////////////////////////////////////////////////////

    /**
     * Build the command bound to a task.
     *
     * @param string|AbstractTask $task
     * @param string|null         $slug
     *
     * @return \Rocketeer\Abstracts\AbstractCommand
     */
    public function buildCommand($task, $slug = null)
    {
        // Build the task instance
        try {
            $instance = $this->buildTask($task);
        } catch (TaskCompositionException $exception) {
            $instance = null;
        }

        // Get the command name
        $name    = $instance ? $instance->getName() : null;
        $name    = is_string($task) ? $task : $name;
        $command = $this->findQualifiedName($name, [
            'Rocketeer\Console\Commands\%sCommand',
            'Rocketeer\Console\Commands\BaseTaskCommand',
        ]);

        $command = new $command($instance, $slug);
        $command->setLaravel($this->app);<commit_msg>Fix custom commands being overriden<commit_after><?php
/*
 * This file is part of Rocketeer
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Rocketeer\Services\Tasks;

use Closure;
use Illuminate\Support\Str;
use Rocketeer\Abstracts\AbstractTask;
use Rocketeer\Binaries\AnonymousBinary;
use Rocketeer\Exceptions\TaskCompositionException;
use Rocketeer\Traits\HasLocator;

/**
 * Handles creating tasks from strings, closures, AbstractTask children, etc.
 *
 * @author <NAME> <<EMAIL>>
 */
class TasksBuilder
{
    use HasLocator;

    /**
     * Build a binary.
     *
     * @param string $binary
     *
     * @return \Rocketeer\Abstracts\AbstractBinary|\Rocketeer\Abstracts\AbstractPackageManager
     */
    public function buildBinary($binary)
    {
        $class = $this->findQualifiedName($binary, [
            'Rocketeer\Binaries\PackageManagers\%s',
            'Rocketeer\Binaries\%s',
        ]);

        // If there is a class by that name
        if ($class) {
            return new $class($this->app);
        }

        // Else wrap the command in an AnonymousBinary
        $anonymous = new AnonymousBinary($this->app);
        $anonymous->setBinary($binary);

        return $anonymous;
    }

    //////////////////////////////////////////////////////////////////////
    ////////////////////////////// COMMANDS //////////////////////////////
    //////////////////////////////////////////////////////////////////////

    /**
     * Build the command bound to a task.
     *
     * @param string|AbstractTask $task
     * @param string|null         $slug
     *
     * @return \Rocketeer\Abstracts\AbstractCommand
     */
    public function buildCommand($task, $slug = null)
    {
        // Build the task instance
        try {
            $instance = $this->buildTask($task);
        } catch (TaskCompositionException $exception) {
            $instance = null;
        }

        // Get the command name
        $name    = $instance ? $instance->getName() : null;
        $command = $this->findQualifiedName($name, array(
            'Rocketeer\Console\Commands\%sCommand',
        ));

        // If no command found, use BaseTaskCommand or task name
        if (!$command || $command === 'Closure') {
            $name    = is_string($task) ? $task : $name;
            $command = $this->findQualifiedName($name, array(
                'Rocketeer\Console\Commands\%sCommand',
                'Rocketeer\Console\Commands\BaseTaskCommand',
            ));
        }

        $command = new $command($instance, $slug);
        $command->setLaravel($this->app);
{'fraction_non_alphanumeric': 0.18859820382663023, 'fraction_numerical': 0.0, 'mean_word_length': 1.7872687704026116, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 34, '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': '1878624', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1355, 'n_words': 329}