ShortDescription.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * @readonly
  17. *
  18. * @internal
  19. */
  20. final class ShortDescription
  21. {
  22. /**
  23. * The docblock containing the short description.
  24. */
  25. private DocBlock $doc;
  26. public function __construct(DocBlock $doc)
  27. {
  28. $this->doc = $doc;
  29. }
  30. /**
  31. * Get the line index of the line containing the end of the short
  32. * description, if present.
  33. */
  34. public function getEnd(): ?int
  35. {
  36. $reachedContent = false;
  37. foreach ($this->doc->getLines() as $index => $line) {
  38. // we went past a description, then hit a tag or blank line, so
  39. // the last line of the description must be the one before this one
  40. if ($reachedContent && ($line->containsATag() || !$line->containsUsefulContent())) {
  41. return $index - 1;
  42. }
  43. // no short description was found
  44. if ($line->containsATag()) {
  45. return null;
  46. }
  47. // we've reached content, but need to check the next lines too
  48. // in case the short description is multi-line
  49. if ($line->containsUsefulContent()) {
  50. $reachedContent = true;
  51. }
  52. }
  53. return null;
  54. }
  55. }