/**
  * Execute command
  *
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return int|null|void
  *
  * @throws Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getArgument('path');
     /**
      * We load the options to work with
      */
     $options = $this->getUsableConfig($input);
     /**
      * Building the real directory or file to work in
      */
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($path)) {
         $path = getcwd() . DIRECTORY_SEPARATOR . $path;
     }
     if (!is_file($path) && !is_dir($path)) {
         throw new Exception('Directory or file "' . $path . '" does not exist');
     }
     /**
      * Print dry-run message if needed
      */
     $this->printDryRunMessage($input, $output, $path);
     /**
      * Print all configuration block if verbose level allows it
      */
     $this->printConfigUsed($output, $options);
     $fileFinder = new FileFinder();
     $files = $fileFinder->findPHPFilesByPath($path);
     /**
      * Parse and fix all found files
      */
     $this->parseAndFixFiles($input, $output, $files, $options);
 }
 /**
  * Test php file finder.
  */
 public function testFindPHPFilesByPath()
 {
     $path = dirname(__FILE__) . '/../Mocks/';
     $fileFinder = new FileFinder();
     $this->assertCount(3, $fileFinder->findPHPFilesByPath($path));
 }
 /**
  * Execute command.
  *
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return int|null|void
  *
  * @throws Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $verbose = $output->getVerbosity();
     $path = $input->getArgument('path');
     $dryRun = $input->getOption('dry-run');
     $fileFinder = new FileFinder();
     $configLoader = new ConfigLoader();
     $configFinder = new ConfigFinder();
     /**
      * 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);
     $configInFile = $configFinder->findConfigFile($configPath);
     $strict = $configLoader->loadConfigValue(self::COMMAND_NAME, $configInFile);
     if (!array_key_exists(self::COMMAND_NAME, $configInFile)) {
         throw new Exception('Strict definition must be defined in .formatter.yml file under');
     }
     /**
      * Building the real directory or file to work in.
      */
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($path)) {
         $path = getcwd() . DIRECTORY_SEPARATOR . $path;
     }
     if (!is_file($path) && !is_dir($path)) {
         throw new Exception('Directory or file "' . $path . '" does not exist');
     }
     /*
      * Dry-run message
      */
     if ($dryRun && $verbose >= OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln('# This process has been executed in mode dry-run');
     }
     if ($verbose >= OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln('# Executing process in ' . $path);
     }
     /**
      * Creates the new StrictFixer.
      */
     $strictFixer = new StrictFixer($strict);
     $files = $fileFinder->findPHPFilesByPath($path);
     /*
      * If verbose level is higher or equal than -vv, we print the config
      * file data, if is not empty.
      */
     if ($verbose >= OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln("# Strict used:\n\n" . $strict ? '1' : '0');
     }
     $output->writeln('#');
     /*
      * Each found php file is processed
      */
     foreach ($files as $file) {
         $data = $file->getContents();
         $result = $strictFixer->fix($data);
         if ($result === false || $data === $result) {
             continue;
         }
         if ($verbose >= OutputInterface::VERBOSITY_NORMAL) {
             $output->writeln('# ' . $file);
         }
         if (!$dryRun) {
             file_put_contents($file->getRealPath(), $result);
         }
     }
 }