Uppercase.php 770 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
  4. * SPDX-License-Identifier: MIT
  5. */
  6. declare(strict_types=1);
  7. namespace Respect\Validation\Rules;
  8. use function is_string;
  9. use function mb_strtoupper;
  10. /**
  11. * Validates whether the characters in the input are uppercase.
  12. *
  13. * @author Alexandre Gomes Gaigalas <alganet@gmail.com>
  14. * @author Danilo Benevides <danilobenevides01@gmail.com>
  15. * @author Henrique Moody <henriquemoody@gmail.com>
  16. * @author Jean Pimentel <jeanfap@gmail.com>
  17. */
  18. final class Uppercase extends AbstractRule
  19. {
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function validate($input): bool
  24. {
  25. if (!is_string($input)) {
  26. return false;
  27. }
  28. return $input === mb_strtoupper($input);
  29. }
  30. }