Code-TidyAll

 view release on metacpan or  search on metacpan

php/PHP_CodeSniffer/src/Runner.php  view on Meta::CPAN

            // No errors found.
            return 0;
        } else if ($this->reporter->totalFixable === 0) {
            // Errors found, but none of them can be fixed by PHPCBF.
            return 1;
        } else {
            // Errors found, and some can be fixed by PHPCBF.
            return 2;
        }

    }//end runPHPCS()


    /**
     * Run the PHPCBF script.
     *
     * @return array
     */
    public function runPHPCBF()
    {
        if (defined('PHP_CODESNIFFER_CBF') === false) {
            define('PHP_CODESNIFFER_CBF', true);
        }

        try {
            Util\Timing::startTiming();
            Runner::checkRequirements();

            // Creating the Config object populates it with all required settings
            // based on the CLI arguments provided to the script and any config
            // values the user has set.
            $this->config = new Config();

            // When processing STDIN, we can't output anything to the screen
            // or it will end up mixed in with the file output.
            if ($this->config->stdin === true) {
                $this->config->verbosity = 0;
            }

            // Init the run and load the rulesets to set additional config vars.
            $this->init();

            // When processing STDIN, we only process one file at a time and
            // we don't process all the way through, so we can't use the parallel
            // running system.
            if ($this->config->stdin === true) {
                $this->config->parallel = 1;
            }

            // Override some of the command line settings that might break the fixes.
            $this->config->generator    = null;
            $this->config->explain      = false;
            $this->config->interactive  = false;
            $this->config->cache        = false;
            $this->config->showSources  = false;
            $this->config->recordErrors = false;
            $this->config->reportFile   = null;
            $this->config->reports      = ['cbf' => null];

            // If a standard tries to set command line arguments itself, some
            // may be blocked because PHPCBF is running, so stop the script
            // dying if any are found.
            $this->config->dieOnUnknownArg = false;

            $this->run();
            $this->reporter->printReports();

            echo PHP_EOL;
            Util\Timing::printRunTime();
        } catch (DeepExitException $e) {
            echo $e->getMessage();
            return $e->getCode();
        }//end try

        if ($this->reporter->totalFixed === 0) {
            // Nothing was fixed by PHPCBF.
            if ($this->reporter->totalFixable === 0) {
                // Nothing found that could be fixed.
                return 0;
            } else {
                // Something failed to fix.
                return 2;
            }
        }

        if ($this->reporter->totalFixable === 0) {
            // PHPCBF fixed all fixable errors.
            return 1;
        }

        // PHPCBF fixed some fixable errors, but others failed to fix.
        return 2;

    }//end runPHPCBF()


    /**
     * Exits if the minimum requirements of PHP_CodeSniffer are not met.
     *
     * @return array
     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
     */
    public function checkRequirements()
    {
        // Check the PHP version.
        if (PHP_VERSION_ID < 50400) {
            $error = 'ERROR: PHP_CodeSniffer requires PHP version 5.4.0 or greater.'.PHP_EOL;
            throw new DeepExitException($error, 3);
        }

        $requiredExtensions = [
            'tokenizer',
            'xmlwriter',
            'SimpleXML',
        ];
        $missingExtensions  = [];

        foreach ($requiredExtensions as $extension) {
            if (extension_loaded($extension) === false) {
                $missingExtensions[] = $extension;
            }



( run in 1.509 second using v1.01-cache-2.11-cpan-39bf76dae61 )