<commit_before><?php
/**
 * Validate console command.
 *
 * PHP version 5
 *
 * @category PHP
 * @package  PHP_Reflect
 * @author   Laurent Laville <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version  GIT: $Id$
 * @link     http://php5.laurent-laville.org/reflect/
 */

namespace Bartlett\Reflect\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Seld\JsonLint\JsonParser;
use Seld\JsonLint\ParsingException;

/**
 * Console command to validate structure of the JSON configuration file.
 *
 * @category PHP
 * @package  PHP_Reflect
 * @author   Laurent Laville <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version  Release: @package_version@
 * @link     http://php5.laurent-laville.org/reflect/
 * @since    Class available since Release 2.3.0
 */
class ValidateCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('validate')
            ->setDescription('Validates a phpreflect.json')
            ->addArgument(
                'file',
                InputArgument::OPTIONAL,
                'Path to phpreflect.json file',
                getenv("REFLECT") ? : './phpreflect.json'
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $file = $input->getArgument('file');

        if (!file_exists($file)) {
            $output->writeln('<error>' . $file . ' not found.</error>');
            return 1;
        }
        if (!is_readable($file)) {
            $output->writeln('<error>' . $file . ' is not readable.</error>');
            return 1;
        }

        $json = file_get_contents($file);

        try {
            $parser = new JsonParser();
            $parser->parse($json);
        } catch (ParsingException $e) {
            $fmt = $this->getApplication()->getHelperSet()->get('formatter');

            $output->writeln(
                $fmt->formatBlock(
                    explode("\n", $e->getMessage()),
                    'error'
                )
            );
            return 1;<commit_msg>allow validate console command to run with phar distribution of reflect<commit_after><?php
/**
 * Validate console command.
 *
 * PHP version 5
 *
 * @category PHP
 * @package  PHP_Reflect
 * @author   Laurent Laville <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version  GIT: $Id$
 * @link     http://php5.laurent-laville.org/reflect/
 */

namespace Bartlett\Reflect\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Seld\JsonLint\JsonParser;
use Seld\JsonLint\ParsingException;

/**
 * Console command to validate structure of the JSON configuration file.
 *
 * @category PHP
 * @package  PHP_Reflect
 * @author   Laurent Laville <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version  Release: @package_version@
 * @link     http://php5.laurent-laville.org/reflect/
 * @since    Class available since Release 2.3.0
 */
class ValidateCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('validate')
            ->setDescription('Validates a phpreflect.json')
            ->addArgument(
                'file',
                InputArgument::OPTIONAL,
                'Path to phpreflect.json file',
                getenv("REFLECT") ? : './phpreflect.json'
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $file  = $input->getArgument('file');
        $fname = realpath($file);

        if (!file_exists($fname)) {
            $output->writeln('<error>' . $file . ' not found.</error>');
            return 1;
        }
        if (!is_readable($fname)) {
            $output->writeln('<error>' . $file . ' is not readable.</error>');
            return 1;
        }

        $json = file_get_contents($fname);

        try {
            $parser = new JsonParser();
            $parser->parse($json);
        } catch (ParsingException $e) {
            $fmt = $this->getApplication()->getHelperSet()->get('formatter');

            $output->writeln(
                $fmt->formatBlock(
                    explode("\n", $e->getMessage()),
                    'error'
                )
            );
            return 1;
{'fraction_non_alphanumeric': 0.13401187446988974, 'fraction_numerical': 0.003816793893129771, 'mean_word_length': 2.1850101282916947, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3219122', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1325, 'n_words': 283}