private function getFinder($path) { if (is_file($path)) { return new \ArrayIterator([new \SplFileInfo($path)]); } $finder = new DefaultFinder(); $finder->setDir($path); return $finder; }
public function generate($schemaFilePath, $name, $namespace, $directory) { $context = $this->createContext($schemaFilePath, $name, $namespace, $directory); if (!file_exists($directory . DIRECTORY_SEPARATOR . 'Model')) { mkdir($directory . DIRECTORY_SEPARATOR . 'Model', 0755, true); } if (!file_exists($directory . DIRECTORY_SEPARATOR . 'Normalizer')) { mkdir($directory . DIRECTORY_SEPARATOR . 'Normalizer', 0755, true); } $prettyPrinter = new Standard(); $modelFiles = $this->modelGenerator->generate($context->getRootReference(), $name, $context); $normalizerFiles = $this->normalizerGenerator->generate($context->getRootReference(), $name, $context); $generated = []; foreach ($modelFiles as $file) { $generated[] = $file->getFilename(); file_put_contents($file->getFilename(), $prettyPrinter->prettyPrintFile([$file->getNode()])); } foreach ($normalizerFiles as $file) { $generated[] = $file->getFilename(); file_put_contents($file->getFilename(), $prettyPrinter->prettyPrintFile([$file->getNode()])); } if ($this->fixer !== null) { $config = Config::create()->setRiskyAllowed(true)->setRules(array('@Symfony' => true, 'empty_return' => false, 'concat_without_spaces' => false, 'double_arrow_multiline_whitespaces' => false, 'unalign_equals' => false, 'unalign_double_arrow' => false, 'align_double_arrow' => true, 'align_equals' => true, 'concat_with_spaces' => true, 'newline_after_open_tag' => true, 'ordered_use' => true, 'phpdoc_order' => true, 'short_array_syntax' => true))->finder(DefaultFinder::create()->in($directory)); $resolver = new ConfigurationResolver(); $resolver->setDefaultConfig($config); $resolver->resolve(); $this->fixer->fix($config); } return $generated; }
public function testThatCustomDefaultFinderWorks() { $finder = DefaultFinder::create(); $finder->in(__DIR__ . '/../Fixtures/FinderDirectory'); $config = Config::create()->finder($finder); $iterator = $config->getFinder()->getIterator(); $this->assertSame(1, count($iterator)); $iterator->rewind(); $this->assertSame('somefile.php', $iterator->current()->getFilename()); }
/** * Make the default finder for Chromabits projects. * * @return Finder */ protected function makeFinder() { $directories = RootDirectories::getEnforceable(); $found = []; $filesystem = new Filesystem(); foreach ($directories as $directory) { if ($filesystem->exists($directory) && is_dir($directory)) { $found[] = $directory; } } return DefaultFinder::create()->in($found); }
/** * @return Finder */ public function getFinder() { $finder = DefaultFinder::create()->in($this->finderDirs); if (isset($this->styleCIConfig['finder']) && is_array($this->styleCIConfig['finder'])) { $finderConfig = $this->styleCIConfig['finder']; foreach ($finderConfig as $key => $values) { $finderMethod = Container::camelize(str_replace('-', '_', $key)); foreach ($values as $value) { $finder->{$finderMethod}($value); } } } return $finder; }
/** * @expectedException \LogicException * "You must call one of in() or append() methods before iterating over a Finder." */ public function testThatDefaultFinderDoesNotSpecifyAnyDirectory() { $finder = DefaultFinder::create(); $finder->getIterator(); }
<?php $finder = \Symfony\CS\Finder\DefaultFinder::create()->files(); $fixers = (require __DIR__ . '/.php_cs-fixers.php'); $finder->name('*.php')->in(__DIR__ . '/features')->in(__DIR__ . '/src'); return \Symfony\CS\Config\Config::create()->level(Symfony\CS\FixerInterface::PSR2_LEVEL)->fixers($fixers)->finder($finder);
/** * Print files * * @param File[] $files * @param string $directory */ public function printFiles($files, $directory) { foreach ($files as $file) { if (!file_exists(dirname($file->getFilename()))) { mkdir(dirname($file->getFilename()), 0755, true); } file_put_contents($file->getFilename(), $this->prettyPrinter->prettyPrintFile([$file->getNode()])); } if ($this->fixer !== null) { $config = Config::create()->setRiskyAllowed(true)->setRules(array('@Symfony' => true, 'empty_return' => false, 'concat_without_spaces' => false, 'double_arrow_multiline_whitespaces' => false, 'unalign_equals' => false, 'unalign_double_arrow' => false, 'align_double_arrow' => true, 'align_equals' => true, 'concat_with_spaces' => true, 'newline_after_open_tag' => true, 'ordered_use' => true, 'phpdoc_order' => true, 'short_array_syntax' => true))->finder(DefaultFinder::create()->in($directory)); $resolver = new ConfigurationResolver(); $resolver->setDefaultConfig($config); $resolver->resolve(); $this->fixer->fix($config); } }
/** * @param Fixer $fixer */ public function __construct(Fixer $fixer = null) { $finder = DefaultFinder::create(); $finder->append($this->commitedFiles()); parent::__construct($fixer, Config::create()->finder($finder)); }
<?php $finder = \Symfony\CS\Finder\DefaultFinder::create()->exclude('vendor')->in(__DIR__); $fixers = ['-concat_without_spaces', '-empty_return', '-multiline_array_trailing_comma', '-phpdoc_short_description', '-single_quote', '-trim_array_spaces', '-operators_spaces', '-unary_operators_spaces', '-unalign_equals', '-unalign_double_arrow', 'align_double_arrow', 'newline_after_open_tag', 'ordered_use', 'phpdoc_order']; return \Symfony\CS\Config\Config::create()->level(Symfony\CS\FixerInterface::PSR2_LEVEL)->fixers($fixers)->finder($finder);
<?php $branch = getenv('TRAVIS_BRANCH'); $phpVersion = getenv('TRAVIS_PHP_VERSION'); printf('Current branch inspected : %s' . PHP_EOL, $branch); $finder = \Symfony\CS\Finder\DefaultFinder::create()->files()->exclude('app/check.php'); $fixers = (require __DIR__ . '/.php_cs-fixers.php'); if (is_numeric(getenv('TRAVIS_PULL_REQUEST'))) { $commitRange = str_replace('...', '..', getenv('TRAVIS_COMMIT_RANGE')); printf('Commit range = %s' . PHP_EOL, $commitRange); exec('git diff ' . $commitRange . ' --name-only --diff-filter=AMR | grep -v Spec.php$ | grep php$', $diff); } else { exec('git show --name-only --oneline --pretty="format:" --diff-filter=AMR | grep -v Spec.php$ | grep php$', $diff); $diff = array_filter($diff); } foreach ($diff as $idx => $filename) { if ($filename !== 'app/check.php') { printf('Parsed file : %s' . PHP_EOL, $filename); } else { printf('Excluded file : %s' . PHP_EOL, $filename); unset($diff[$idx]); } } $finder->append($diff); return \Symfony\CS\Config\Config::create()->level(Symfony\CS\FixerInterface::PSR2_LEVEL)->fixers($fixers)->finder($finder);
public function __construct() { parent::__construct(); $this->name('*.php')->name('*.phtml')->name('*.xml')->exclude(array('lib', 'shell', 'app/Mage.php', 'app/code/core', 'app/code/community', 'app/design/frontend/default', 'app/design/frontend/enterprise/default', 'app/design/frontend/base', 'app/design/adminhtml/default')); }