ShortDescription.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\DocBlock;
  13. /**
  14. * This class represents a short description (aka summary) of a docblock.
  15. *
  16. * @internal
  17. */
  18. final class ShortDescription
  19. {
  20. /**
  21. * The docblock containing the short description.
  22. */
  23. private DocBlock $doc;
  24. public function __construct(DocBlock $doc)
  25. {
  26. $this->doc = $doc;
  27. }
  28. /**
  29. * Get the line index of the line containing the end of the short
  30. * description, if present.
  31. */
  32. public function getEnd(): ?int
  33. {
  34. $reachedContent = false;
  35. foreach ($this->doc->getLines() as $index => $line) {
  36. // we went past a description, then hit a tag or blank line, so
  37. // the last line of the description must be the one before this one
  38. if ($reachedContent && ($line->containsATag() || !$line->containsUsefulContent())) {
  39. return $index - 1;
  40. }
  41. // no short description was found
  42. if ($line->containsATag()) {
  43. return null;
  44. }
  45. // we've reached content, but need to check the next lines too
  46. // in case the short description is multi-line
  47. if ($line->containsUsefulContent()) {
  48. $reachedContent = true;
  49. }
  50. }
  51. return null;
  52. }
  53. }