예제 #1
0
파일: Jane.php 프로젝트: stof/jane
 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;
 }
예제 #2
0
 public function testThatCustomFinderWorks()
 {
     $finder = Finder::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());
 }
예제 #3
0
 /**
  * @covers Symfony\CS\Fixer::fix
  * @covers Symfony\CS\Fixer::fixFile
  */
 public function testThatFixInvalidFileReportsToErrorManager()
 {
     $fixer = new Fixer();
     $fixer->setLinter(new Linter());
     $config = Config::create()->finder(new \DirectoryIterator(__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'FixerTest' . DIRECTORY_SEPARATOR . 'invalid'))->fixers(array(new \Symfony\CS\Fixer\PSR2\VisibilityFixer(), new \Symfony\CS\Fixer\Symfony\UnusedUseFixer()))->setUsingCache(false);
     $changed = $fixer->fix($config, true, true);
     $pathToInvalidFile = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'FixerTest' . DIRECTORY_SEPARATOR . 'invalid' . DIRECTORY_SEPARATOR . 'somefile.php';
     $this->assertCount(0, $changed);
     $errors = $fixer->getErrorsManager()->getInvalidErrors();
     $this->assertCount(1, $errors);
     $error = $errors[0];
     $this->assertInstanceOf('Symfony\\CS\\Error\\Error', $error);
     $this->assertSame(Error::TYPE_INVALID, $error->getType());
     $this->assertSame($pathToInvalidFile, $error->getFilePath());
 }
예제 #4
0
 /**
  * @covers Symfony\CS\Fixer::fix
  * @covers Symfony\CS\Fixer::fixFile
  * @covers Symfony\CS\Fixer::prepareFixers
  */
 public function testThatFixSuccessfully()
 {
     $fixer = new Fixer();
     $fixer->addFixer(new \Symfony\CS\Fixer\PSR2\VisibilityFixer());
     $fixer->addFixer(new \Symfony\CS\Fixer\PSR0\Psr0Fixer());
     //will be ignored cause of test keyword in namespace
     $config = Config::create()->finder(new \DirectoryIterator(__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'FixerTest'));
     $config->fixers($fixer->getFixers());
     $changed = $fixer->fix($config, true, true);
     $pathToInvalidFile = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'FixerTest' . DIRECTORY_SEPARATOR . 'somefile.php';
     $this->assertCount(1, $changed);
     $this->assertCount(2, $changed[$pathToInvalidFile]);
     $this->assertSame(array('appliedFixers', 'diff'), array_keys($changed[$pathToInvalidFile]));
     $this->assertSame('visibility', $changed[$pathToInvalidFile]['appliedFixers'][0]);
 }
<?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);
예제 #6
0
<?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();
$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/ | grep php$', $diff);
} else {
    exec('git show --name-only --oneline --pretty="format:" --diff-filter=AMR | grep -v ^spec/ | grep php$', $diff);
    $diff = array_filter($diff);
}
foreach ($diff as $filename) {
    printf('Parsed file : %s' . PHP_EOL, $filename);
}
$finder->append($diff);
return \Symfony\CS\Config\Config::create()->fixers($fixers)->finder($finder);
예제 #7
0
 /**
  * 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);
     }
 }
예제 #8
0
 /**
  * @param Fixer $fixer
  */
 public function __construct(Fixer $fixer = null)
 {
     $finder = DefaultFinder::create();
     $finder->append($this->commitedFiles());
     parent::__construct($fixer, Config::create()->finder($finder));
 }
 /**
  * @param string       $styleCIConfigDir
  * @param string|array $finderDirs       A directory path or an array of directories for Finder
  *
  * @return Config
  */
 public static function create($styleCIConfigDir = null, $finderDirs = null)
 {
     $bridge = new static($styleCIConfigDir, $finderDirs);
     return Config::create()->finder($bridge->getFinder())->level($bridge->getLevel())->fixers($bridge->getFixers());
 }
예제 #10
0
 /**
  * @dataProvider provideAddCustomFixersCases
  */
 public function testAddCustomFixers($expected, $suite)
 {
     $config = Config::create();
     $config->addCustomFixers($suite);
     $this->assertSame($expected, $config->getCustomFixers());
 }