JMOlivas\Phpqa\Input\FilesOption::normalize PHP Method

normalize() public method

- If it's either empty or absent, it returns an empty array - If it's a single value separated by commas, it converts it to array - Otherwise returns the value as is.
public normalize ( ) : array
return array
    public function normalize()
    {
        if ($this->isAbsent() || $this->isEmpty()) {
            return [];
        }
        if (count($this->files) === 1 && strpos($this->files[0], ',') !== false) {
            return explode(',', $this->files[0]);
        }
        return $this->files;
    }

Usage Example

Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $project = $input->getOption('project');
     /**
      * @var \JMOlivas\Phpqa\Console\Application $application
      */
     $application = $this->getApplication();
     /**
      * @var \JMOlivas\Phpqa\Config $config
      */
     $config = $application->getConfig();
     if (!$config->isCustom() && !$project) {
         throw new Exception(sprintf('No local phpqa.yml or phpqa.yml.dist at current working directory ' . 'you must provide a valid project value (%s)', implode(',', $this->projects)));
     }
     if (!$config->isCustom() && !in_array($project, $this->projects)) {
         throw new Exception(sprintf('You must provide a valid project value (%s)', implode(',', $this->projects)));
     }
     $config->loadProjectConfiguration($project);
     $this->directory = $application->getApplicationDirectory();
     $output->writeln(sprintf('<question>%s</question>', $application->getName()));
     $filesOption = new FilesOption($input->getOption('files'));
     $git = $input->getOption('git');
     if (!$filesOption->isAbsent() && $git) {
         throw new Exception('Options `files` and `git` cannot be used in combination.');
     }
     if ($filesOption->isAbsent() && !$git) {
         throw new Exception('You must set `files` or `git` options.');
     }
     if (!$filesOption->isAbsent() && $filesOption->isEmpty()) {
         throw new Exception('Options `files` needs at least one file.');
     }
     if ($git) {
         $files = $this->extractCommitedFiles($output, $config);
     } else {
         $files = $filesOption->normalize();
     }
     $output->writeln(sprintf('<info>%s</info>', $config->get('application.messages.files.info')));
     foreach ($files as $file) {
         $output->writeln(sprintf('<comment> - %s</comment>', $file));
     }
     $this->checkComposer($output, $files, $config);
     $analyzers = array_keys($config->get('application.analyzer'));
     foreach ($analyzers as $analyzer) {
         $this->analyzer($output, $analyzer, $files, $config, $project);
     }
     $output->writeln(sprintf('<info>%s</info>', $config->get('application.messages.completed.info')));
 }
All Usage Examples Of JMOlivas\Phpqa\Input\FilesOption::normalize