FixerNameValidator.php 757 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer;
  12. /**
  13. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  14. *
  15. * @internal
  16. */
  17. final class FixerNameValidator
  18. {
  19. /**
  20. * @param string $name
  21. * @param bool $isCustom
  22. *
  23. * @return bool
  24. */
  25. public function isValid($name, $isCustom)
  26. {
  27. if (!$isCustom) {
  28. return 1 === Preg::match('/^[a-z][a-z0-9_]*$/', $name);
  29. }
  30. return 1 === Preg::match('/^[A-Z][a-zA-Z0-9]*\/[a-z][a-z0-9_]*$/', $name);
  31. }
  32. }