remove-vendor-prefixing-comment-visitor.php 908 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * Yoast SEO Plugin File.
  4. *
  5. * @package Yoast\YoastSEO\PHP_CodeShift
  6. */
  7. namespace Yoast\WP\Free\PHP_CodeShift;
  8. use PhpParser\Comment\Doc;
  9. use PhpParser\Node;
  10. use PhpParser\NodeVisitorAbstract;
  11. /**
  12. * Class Vendor_Prefixing_Visitor
  13. */
  14. class Remove_Vendor_Prefixing_Comment_Visitor extends NodeVisitorAbstract {
  15. /**
  16. * @param \PhpParser\Node $node The node being visited.
  17. *
  18. * @return \PhpParser\Node The possibly modified node.
  19. */
  20. public function leaveNode( Node $node ) {
  21. $comment = $node->getDocComment();
  22. if ( $comment && \strpos( $comment->getText(), \YOAST_VENDOR_NS_PREFIX ) !== false ) {
  23. $updated_text = \str_replace( \YOAST_VENDOR_NS_PREFIX . '\\', '', $comment->getText() );
  24. $updated_comment = new Doc( $updated_text, $comment->getLine(), $comment->getFilePos(), $comment->getTokenPos() );
  25. $node->setDocComment( $updated_comment );
  26. }
  27. return $node;
  28. }
  29. }