123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- /*
- * This file is part of the PHP CS utility.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace Symfony\CS\DocBlock;
- /**
- * This represents a line of a docblock.
- *
- * @author Graham Campbell <graham@mineuk.com>
- */
- class Line
- {
- /**
- * The content of this line.
- *
- * @var string
- */
- private $content;
- /**
- * Create a new line instance.
- *
- * @param string $content
- */
- public function __construct($content)
- {
- $this->content = $content;
- }
- /**
- * Get the content of this line.
- *
- * @return int
- */
- public function getContent()
- {
- return $this->content;
- }
- /**
- * Does this line contain useful content?
- *
- * If the line contains text or tags, then this is true.
- *
- * @return bool
- */
- public function containsUsefulContent()
- {
- return 0 !== preg_match('/\\*\s*\S+/', $this->content) && !$this->isTheStart() && !$this->isTheEnd();
- }
- /**
- * Does the line contain a tag?
- *
- * If this is true, then it must be the first line of an annotation.
- *
- * @return bool
- */
- public function containsATag()
- {
- return 0 !== preg_match('/\\*\s*@/', $this->content);
- }
- /**
- * Is the line the start of a docblock?
- *
- * @return bool
- */
- public function isTheStart()
- {
- return false !== strpos($this->content, '/**');
- }
- /**
- * Is the line the end of a docblock?
- *
- * @return bool
- */
- public function isTheEnd()
- {
- return false !== strpos($this->content, '*/');
- }
- /**
- * Set the content of this line.
- *
- * @param string $content
- */
- public function setContent($content)
- {
- $this->content = $content;
- }
- /**
- * Remove this line by clearing its contents.
- *
- * Note that this method technically brakes the internal state of the
- * docblock, but is useful when we need to retain the indexes of lines
- * during the execution of an algorithm.
- */
- public function remove()
- {
- $this->content = '';
- }
- /**
- * Append a blank docblock line to this line's contents.
- *
- * Note that this method technically brakes the internal state of the
- * docblock, but is useful when we need to retain the indexes of lines
- * during the execution of an algorithm.
- */
- public function addBlank()
- {
- preg_match_all('/\ *\*/', $this->content, $matches);
- $this->content .= $matches[0][0]."\n";
- }
- /**
- * Get the string representation of object.
- *
- * @return string
- */
- public function __toString()
- {
- return $this->content;
- }
- }
|