<commit_before><?php

namespace DF\PHPCoverFish\Base;

use DF\PHPCoverFish\Common\CoverFishPHPUnitFile;
use DF\PHPCoverFish\Common\CoverFishPHPUnitTest;
use DF\PHPCoverFish\Validator\Base\BaseCoverFishValidatorInterface;

/**
 * Class BaseCoverFishScanner
 *
 * @package   DF\PHPCoverFish
 * @author    <NAME> <<EMAIL>>
 * @copyright 2015 <NAME> <<EMAIL>>
 * @license   http://www.opensource.org/licenses/MIT
 * @link      http://github.com/dunkelfrosch/phpcoverfish/tree
 * @since     class available since Release 0.9.9
 * @version   1.0.0
 */
class BaseCoverFishScanner extends BaseScanner
{
    /**
     * @var string
     */
    protected $filePattern = '*.php';

    /**
     * @var array
     */
    protected $filePatternExclude = array(
        '*.log',
        '*.js',
        '*.html',
        '*.twig',
        '*.css',
        '*.scss',
        '*.less',
        '*.txt',
        '*.md',
        '*.yml',
        '*.xml'
    );

    /**
     * @param array $cliOptions
     *
     * @codeCoverageIgnore
     */
    public function __construct(array $cliOptions)
    {
        parent::__construct();
        $this->initCoverFishScanner($cliOptions);

        if (true === $this->coverFishHelper->checkFileExist($this->phpUnitXMLFile)) {
            $this->setConfigFromPHPUnitConfigFile();
        }

        if (true === $this->checkSourceAutoload($this->testAutoloadPath)) {
            include(sprintf('%s', $this->testAutoloadPath));
        }
    }

    /**
     * @param array $cliOptions
     *
     * @codeCoverageIgnore
     */
    private function initCoverFishScanner(array $cliOptions)
    {
        // fetch all necessary coverfish parameter by optional given raw-data first
        $this->testAutoloadPath = $cliOptions['raw_scan_autoload_file'];
        $this->testSourcePath = $cliOptions['raw_scan_source'];
        $this->testExcludePath = $cliOptions['raw_scan_exclude_path'];

        // fetch additional system/app parameter
        $this->phpUnitXMLFile = $cliOptions['sys_phpunit_config'];
        $this->phpUnitTestSuite = $cliOptions['sys_phpunit_config_test_suite'];

        $this->warningThreshold = (int) $cliOptions['sys_warning_threshold'];
        $this->stopOnFailure = (bool) $cliOptions['sys_stop_on_failure'];
        $this->stopOnError = (bool) $cliOptions['sys_stop_on_error'];
    }

    /**
     * update/set configuration using phpunit xml file
     */
    public function setConfigFromPHPUnitConfigFile()
    {
        try {
            /** @var \SimpleXMLElement $xmlDocument */
            $xmlDocument = simplexml_load_file($this->phpUnitXMLFile);

            $this->phpUnitXMLPath = $this->coverFishHelper->getPathFromFileNameAndPath($this->phpUnitXMLFile);
            $this->testAutoloadPath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getAttributeFromXML('bootstrap', $xmlDocument));
            $this->testSourcePath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getTestSuitePropertyFromXML('directory', $xmlDocument));
            $this->testExcludePath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getTestSuitePropertyFromXML('exclude', $xmlDocument));

        } catch (\Exception $e) {

            echo (sprintf('parse error loading phpunit config file "%s"!', $this->phpUnitXMLFile));
            echo (sprintf('-> message: %s', $e->getMessage()));

        }
    }

    /**
     * @param CoverFishPHPUnitTest $phpUnitTest
     *
     * @return CoverFishPHPUnitTest
     */
    public function validateAndReturnMapping(CoverFishPHPUnitTest $phpUnitTest)
    {
        $phpUnitTest->clearCoverMappings();

        /** @var BaseCoverFishValidatorInterface $validator */
        foreach ($this->validatorCollection as $validator) {
            if (false === $validator->validate()) {
                continue;
            }<commit_msg>prepare main scanner class for new stable release (1.0.0), remove obsolete command arguments<commit_after><?php

namespace DF\PHPCoverFish\Base;

use DF\PHPCoverFish\Common\CoverFishPHPUnitFile;
use DF\PHPCoverFish\Common\CoverFishPHPUnitTest;
use DF\PHPCoverFish\Validator\Base\BaseCoverFishValidatorInterface;

/**
 * Class BaseCoverFishScanner
 *
 * @package   DF\PHPCoverFish
 * @author    <NAME> <<EMAIL>>
 * @copyright 2015 <NAME> <<EMAIL>>
 * @license   http://www.opensource.org/licenses/MIT
 * @link      http://github.com/dunkelfrosch/phpcoverfish/tree
 * @since     class available since Release 0.9.9
 * @version   1.0.0
 */
class BaseCoverFishScanner extends BaseScanner
{
    /**
     * @var string
     */
    protected $filePattern = '*.php';

    /**
     * @var array
     */
    protected $filePatternExclude = array(
        '*.log',
        '*.js',
        '*.html',
        '*.twig',
        '*.css',
        '*.scss',
        '*.less',
        '*.txt',
        '*.md',
        '*.yml',
        '*.xml'
    );

    /**
     * @param array $cliOptions
     *
     * @codeCoverageIgnore
     */
    public function __construct(array $cliOptions)
    {
        parent::__construct();
        $this->initCoverFishScanner($cliOptions);

        if (true === $this->coverFishHelper->checkFileExist($this->phpUnitXMLFile)) {
            $this->setConfigFromPHPUnitConfigFile();
        }

        if (true === $this->checkSourceAutoload($this->testAutoloadPath)) {
            // still looking for a valid workaround %)
            include(sprintf('%s', $this->testAutoloadPath));
        }
    }

    /**
     * @param array $cliOptions
     *
     * @codeCoverageIgnore
     */
    private function initCoverFishScanner(array $cliOptions)
    {
        // fetch all necessary coverfish parameter by optional given raw-data first
        $this->testAutoloadPath = $cliOptions['raw_scan_autoload_file'];
        $this->testSourcePath = $cliOptions['raw_scan_source'];
        $this->testExcludePath = $cliOptions['raw_scan_exclude_path'];

        // fetch additional system/app parameter
        $this->phpUnitXMLFile = $cliOptions['sys_phpunit_config'];
        $this->phpUnitTestSuite = $cliOptions['sys_phpunit_config_test_suite'];
        $this->stopOnFailure = (bool) $cliOptions['sys_stop_on_failure'];
        $this->stopOnError = (bool) $cliOptions['sys_stop_on_error'];
    }

    /**
     * update/set configuration using phpunit xml file
     */
    public function setConfigFromPHPUnitConfigFile()
    {
        try {
            /** @var \SimpleXMLElement $xmlDocument */
            $xmlDocument = simplexml_load_file($this->phpUnitXMLFile);

            $this->phpUnitXMLPath = $this->coverFishHelper->getPathFromFileNameAndPath($this->phpUnitXMLFile);
            $this->testAutoloadPath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getAttributeFromXML('bootstrap', $xmlDocument));
            $this->testSourcePath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getTestSuitePropertyFromXML('directory', $xmlDocument));
            $this->testExcludePath = sprintf('%s', $this->getTestSuitePropertyFromXML('exclude', $xmlDocument));

        } catch (\Exception $e) {

            echo (sprintf('parse error loading phpunit config file "%s"!', $this->phpUnitXMLFile));
            echo (sprintf('-> message: %s', $e->getMessage()));

        }
    }

    /**
     * @param CoverFishPHPUnitTest $phpUnitTest
     *
     * @return CoverFishPHPUnitTest
     */
    public function validateAndReturnMapping(CoverFishPHPUnitTest $phpUnitTest)
    {
        $phpUnitTest->clearCoverMappings();

        /** @var BaseCoverFishValidatorInterface $validator */
        foreach ($this->validatorCollection as $validator) {
            if (false === $validator->validate()) {
                continue;
            }
{'fraction_non_alphanumeric': 0.14143790849673202, 'fraction_numerical': 0.0030065359477124184, 'mean_word_length': 2.7560137457044673, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 16}, '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': '1361720', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2254, 'n_words': 388}