<commit_before><?php

/*
 * This file is part of the Jarvis package
 *
 * Copyright (c) 2015 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Feel free to edit as you please, and have fun.
 *
 * @author <NAME> <<EMAIL>>
 */

namespace Jarvis\Project\Repository;

use Herrera\Json\Json;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Jarvis\Project\ProjectConfiguration;
use Jarvis\Project\ProjectConfigurationFactory;

class JsonProjectConfigurationRepository implements ProjectConfigurationRepository
{
    /**
     * @var null|array
     */
    private $projectConfigs;

    /**
     * @var string
     */
    private $filePath;

    /**
     * @var ProjectConfigurationFactory
     */
    private $projectConfigurationFactory;

    public function __construct($filePath, ProjectConfigurationFactory $projectConfigurationFactory)
    {
        $this->filePath = $filePath;
        $this->projectConfigurationFactory = $projectConfigurationFactory;
    }

    /**
     * {@inheritdoc}
     */
    public function has($projectName)
    {
        return isset($this->getProjectConfigurationCollection()[$projectName]);
    }

    /**
     * {@inheritdoc}
     */
    public function count()
    {
        return count($this->getProjectConfigurationCollection());
    }

    /**
     * {@inheritdoc}
     */
    public function find($projectName)
    {
        return isset($this->getProjectConfigurationCollection()[$projectName]) ?
            $this->getProjectConfigurationCollection()[$projectName]
            :
            null;
    }

    /**
     * {@inheritdoc}
     */
    public function findBy(array $criteria)
    {
        $results = [];
        $accessor = PropertyAccess::createPropertyAccessor();
        foreach ($this->getProjectConfigurationCollection() as $projectConfig) {
            foreach ($criteria as $criterionName => $criterionValue) {
                $criterionValueArray = !is_array($criterionValue) ? [$criterionValue] : $criterionValue;
                $propertyValue = $accessor->getValue($projectConfig, $criterionName);
                $propertyValueArray = !is_array($propertyValue) ? [$propertyValue] : $propertyValue;
                foreach ($criterionValueArray as $criterionValue) {
                    if (in_array($criterionValue, $propertyValueArray, true)) {
                        // return $projectConfig;
                        $results[$projectConfig->getProjectName()] = $projectConfig;
                    }
                }
            }
        }

        return $results;
    }
<commit_msg>The option tag for project commands should match only installed project.<commit_after><?php

/*
 * This file is part of the Jarvis package
 *
 * Copyright (c) 2015 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Feel free to edit as you please, and have fun.
 *
 * @author <NAME> <<EMAIL>>
 */

namespace Jarvis\Project\Repository;

use Herrera\Json\Json;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Jarvis\Project\ProjectConfiguration;
use Jarvis\Project\ProjectConfigurationFactory;

class JsonProjectConfigurationRepository implements ProjectConfigurationRepository
{
    /**
     * @var null|array
     */
    private $projectConfigs;

    /**
     * @var string
     */
    private $filePath;

    /**
     * @var ProjectConfigurationFactory
     */
    private $projectConfigurationFactory;

    public function __construct($filePath, ProjectConfigurationFactory $projectConfigurationFactory)
    {
        $this->filePath = $filePath;
        $this->projectConfigurationFactory = $projectConfigurationFactory;
    }

    /**
     * {@inheritdoc}
     */
    public function has($projectName)
    {
        return isset($this->getProjectConfigurationCollection()[$projectName]);
    }

    /**
     * {@inheritdoc}
     */
    public function count()
    {
        return count($this->getProjectConfigurationCollection());
    }

    /**
     * {@inheritdoc}
     */
    public function find($projectName)
    {
        return isset($this->getProjectConfigurationCollection()[$projectName]) ?
            $this->getProjectConfigurationCollection()[$projectName]
            :
            null;
    }

    /**
     * {@inheritdoc}
     */
    public function findBy(array $criteria)
    {
        $results = [];
        $accessor = PropertyAccess::createPropertyAccessor();
        foreach ($this->getProjectConfigurationCollection() as $projectConfig) {
            foreach ($criteria as $criterionName => $criterionValue) {
                if ('installed' == $criterionName) {
                    continue;
                }
                $criterionValueArray = !is_array($criterionValue) ? [$criterionValue] : $criterionValue;
                $propertyValue = $accessor->getValue($projectConfig, $criterionName);
                $propertyValueArray = !is_array($propertyValue) ? [$propertyValue] : $propertyValue;
                foreach ($criterionValueArray as $criterionValue) {
                    if (in_array($criterionValue, $propertyValueArray, true)) {
                        $results[$projectConfig->getProjectName()] = $projectConfig;
                    }
                }
            }

            foreach ($criteria as $criterionName => $criterionValue) {
                if ('installed' == $criterionName && $criterionValue !== $projectConfig->isInstalled()) {
                    unset($results[$projectConfig->getProjectName()]);
                }
            }
        }

        return $results;
    }

{'fraction_non_alphanumeric': 0.11154048831898823, 'fraction_numerical': 0.0014052344985069384, 'mean_word_length': 2.4635036496350367, 'pattern_counts': {'":': 0, '<': 13, '<?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': '4938595', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1411, 'n_words': 307}