DefaultFinder.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS\Finder;
  11. use Symfony\Component\Finder\Finder;
  12. use Symfony\CS\FinderInterface;
  13. /**
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class DefaultFinder extends Finder implements FinderInterface
  17. {
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. $files = $this->getFilesToExclude();
  22. $this
  23. ->files()
  24. ->name('*.php')
  25. ->name('*.twig')
  26. ->name('*.xml')
  27. ->name('*.yml')
  28. ->ignoreDotFiles(true)
  29. ->ignoreVCS(true)
  30. ->exclude('vendor')
  31. ->filter(
  32. function (\SplFileInfo $file) use ($files) {
  33. return !in_array($file->getRelativePathname(), $files, true);
  34. }
  35. )
  36. ;
  37. }
  38. public function setDir($dir)
  39. {
  40. $this->in($this->getDirs($dir));
  41. }
  42. /**
  43. * Gets the directories that needs to be scanned for files to validate.
  44. *
  45. * @param string $dir
  46. *
  47. * @return string[]
  48. */
  49. protected function getDirs($dir)
  50. {
  51. return array($dir);
  52. }
  53. /**
  54. * Excludes files because modifying them would break.
  55. *
  56. * This is mainly useful for fixtures in unit tests.
  57. *
  58. * @return string[]
  59. */
  60. protected function getFilesToExclude()
  61. {
  62. return array();
  63. }
  64. }