/**
  * Given a Project, a set of languages and a set of domains, return a random
  * non filled yet Translation object
  *
  * If the flag revision is enabled, then only already translated elements
  * will be picked up
  *
  * @param Project $project   Project
  * @param array   $languages Languages
  * @param array   $domains   Domains
  * @param boolean $revision  Revision only
  *
  * @return Translation|false Translation found or null if none translation
  *                           is available
  */
 public function pickUpTranslation(Project $project, array $languages, array $domains, $revision)
 {
     $repositories = $project->getRepositories($domains, $languages);
     $translations = array_reduce($repositories, function (Repository $repository) use($revision) {
         $translations = $repository->getTranslations();
         return array_filter($translations, function (Translation $translation) use($revision) {
             return $revision === ($translation->getValue() == '');
         });
     });
     $position = array_rand($translations);
     return $translations[$position];
 }
 /**
  * Create project given an input instance
  *
  * @param InputInterface $input Input
  *
  * @return Project New project instance
  */
 public function createProject(InputInterface $input)
 {
     $configFinder = new ConfigFinder();
     $configLoader = new ConfigLoader();
     /**
      * This section is just for finding the right values to work with in
      * this execution.
      *
      * $options array will have, after this block, all these values
      */
     $configPath = rtrim($input->getOption('config'), DIRECTORY_SEPARATOR);
     $configValues = $configLoader->loadConfigValues($configFinder->findConfigFile($configPath));
     $masterLanguage = $configValues['master_language'];
     $languages = $configValues['languages'];
     $filePaths = $configValues['paths'];
     return Project::create($masterLanguage, $languages, $filePaths);
 }
 /**
  * Get total metrics given a Project.
  *
  * The format is that one
  *
  * [
  *      'en' => 267,
  *      'ca' => 120,
  *      'es' => 12,
  * ]
  *
  * @param Project $project   Project
  * @param array   $domains   Domains
  * @param array   $languages Languages
  *
  * @return array Metrics
  */
 public function getTotalMetrics(Project $project, array $domains = [], array $languages = [])
 {
     $metrics = [];
     $masterLanguage = $project->getMasterLanguage();
     $languages = empty($languages) ? $project->getAvailableLanguages() : $languages;
     $languages = array_intersect($languages, $project->getAvailableLanguages());
     unset($languages[$masterLanguage]);
     $masterKeys = $project->getKeys($domains, [$masterLanguage]);
     $masterCount = count($masterKeys);
     $metrics[$masterLanguage] = $masterCount;
     foreach ($languages as $language) {
         $languageKeys = $project->getKeys($domains, [$language]);
         $existentLanguageTranslations = array_intersect($languageKeys, $masterKeys);
         $metrics[$language] = count($existentLanguageTranslations);
     }
     arsort($metrics);
     return $metrics;
 }
 /**
  * Get project
  */
 protected function getProject()
 {
     $paths = [dirname(__FILE__) . '/../../../Fixtures'];
     return Project::create('en', ['en', 'ca'], $paths);
 }