This commit is contained in:
KhaiNguyen
2020-02-13 10:39:37 +07:00
commit 59401cb805
12867 changed files with 4646216 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?php
/**
* Yoast SEO Plugin File.
*
* @package Yoast\YoastSEO\PHP_CodeShift
*/
namespace Yoast\WP\SEO\PHP_CodeShift;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\String_;
use PhpParser\NodeVisitorAbstract;
/**
* Class Vendor_Prefixing_Visitor
*/
class Remove_Vendor_Prefixing_Array_Key_Visitor extends NodeVisitorAbstract {
/**
* Removes vendor prefixes from array keys.
*
* @param \PhpParser\Node $node The node being visited.
*
* @return \PhpParser\Node The possibly modified node.
*/
public function leaveNode( Node $node ) {
if ( ! $node instanceof ArrayItem ) {
return $node;
}
if ( $node->key instanceof String_ && \strpos( $node->key->value, \YOAST_VENDOR_NS_PREFIX ) !== false ) {
$node->key->value = \str_replace( \YOAST_VENDOR_NS_PREFIX . '\\', '', $node->key->value );
}
return $node;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Yoast SEO Plugin File.
*
* @package Yoast\YoastSEO\PHP_CodeShift
*/
namespace Yoast\WP\SEO\PHP_CodeShift;
use Codeshift\AbstractCodemod;
/**
* Class Vendor_Prefixing_Codemod
*/
class Remove_Vendor_Prefixing_Codemod extends AbstractCodemod {
/**
* Sets up the environment required to do the code modifications.
*/
public function init() {
\define( 'YoastSEO_Vendor\RUCKUSING_BASE', __DIR__ . '/../../fake-ruckusing' );
\define( 'YOAST_VENDOR_NS_PREFIX', 'YoastSEO_Vendor' );
\define( 'YOAST_VENDOR_DEFINE_PREFIX', 'YOASTSEO_VENDOR__' );
\define( 'YOAST_VENDOR_PREFIX_DIRECTORY', 'vendor_prefixed' );
$visitor = new Remove_Vendor_Prefixing_Visitor();
$comment_visitor = new Remove_Vendor_Prefixing_Comment_Visitor();
$array_key_visitor = new Remove_Vendor_Prefixing_Array_Key_Visitor();
$this->addTraversalTransform( $visitor, $comment_visitor, $array_key_visitor );
}
}
return 'Yoast\WP\SEO\PHP_CodeShift\Remove_Vendor_Prefixing_Codemod';

View File

@@ -0,0 +1,37 @@
<?php
/**
* Yoast SEO Plugin File.
*
* @package Yoast\YoastSEO\PHP_CodeShift
*/
namespace Yoast\WP\SEO\PHP_CodeShift;
use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
/**
* Class Vendor_Prefixing_Visitor
*/
class Remove_Vendor_Prefixing_Comment_Visitor extends NodeVisitorAbstract {
/**
* Removes vendor prefixes from comments.
*
* @param \PhpParser\Node $node The node being visited.
*
* @return \PhpParser\Node The possibly modified node.
*/
public function leaveNode( Node $node ) {
$comment = $node->getDocComment();
if ( $comment && \strpos( $comment->getText(), \YOAST_VENDOR_NS_PREFIX ) !== false ) {
$updated_text = \str_replace( \YOAST_VENDOR_NS_PREFIX . '\\', '', $comment->getText() );
$updated_comment = new Doc( $updated_text, $comment->getLine(), $comment->getFilePos(), $comment->getTokenPos() );
$node->setDocComment( $updated_comment );
}
return $node;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Yoast SEO Plugin File.
*
* @package Yoast\YoastSEO\PHP_CodeShift
*/
namespace Yoast\WP\SEO\PHP_CodeShift;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\NodeVisitorAbstract;
/**
* Class Vendor_Prefixing_Visitor
*/
class Remove_Vendor_Prefixing_Visitor extends NodeVisitorAbstract {
/**
* Removes vendor prefixes from use statements.
*
* @param \PhpParser\Node $node The node being visited.
*
* @return \PhpParser\Node The possibly modified node.
*/
public function leaveNode( Node $node ) {
if ( ! $node instanceof Name ) {
return $node;
}
if ( $node->getFirst() !== \YOAST_VENDOR_NS_PREFIX ) {
return $node;
}
return $node->slice( 1 );
}
}