Skip to content

Commit 45aae72

Browse files
Improve removal of unused comments (#243)
* Improve removal of unused comments * Update src/Visitor.php Co-authored-by: Viktor Szépe <viktor@szepe.net> --------- Co-authored-by: Viktor Szépe <viktor@szepe.net>
1 parent dc1e3c3 commit 45aae72

File tree

2 files changed

+14
-73
lines changed

2 files changed

+14
-73
lines changed

src/Visitor.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -879,28 +879,26 @@ private function getCleanCommentsNode(Node $node): Node
879879
return $node;
880880
}
881881

882-
// Remove "//" comments.
883882
$comments = [];
884883
foreach ($node->getComments() as $comment) {
885-
if (strpos(trim($comment->getText()), '//') === 0) {
884+
$commentText = trim($comment->getText());
885+
886+
// Strip out comments that are not PHPDoc comments.
887+
if (
888+
strpos($commentText, '/**') === false
889+
) {
886890
continue;
887891
}
888-
$comments[] = $comment;
889-
}
890-
891-
$node->setAttribute('comments', $comments);
892892

893-
if ($node->getDocComment() === null) {
894-
return $node;
895-
}
893+
// Strip out comments that are not templates and not the actual docComment.
894+
if (
895+
strpos($commentText, '/**#@') === false
896+
&& $commentText !== trim((string)$node->getDocComment())
897+
) {
898+
continue;
899+
}
896900

897-
// Remove file comments that are bound to the first node in a file.
898-
$comments = $node->getComments();
899-
if (
900-
$comments[0]->getText() !== (string)$node->getDocComment()
901-
&& strpos($comments[0]->getText(), '/**#@') !== 0
902-
) {
903-
array_shift($comments);
901+
$comments[] = $comment;
904902
}
905903

906904
$node->setAttribute('comments', $comments);

wordpress-stubs.php

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,12 +1556,10 @@ public function cleanup()
15561556
*/
15571557
class ftp_base
15581558
{
1559-
/* Public variables */
15601559
var $LocalEcho;
15611560
var $Verbose;
15621561
var $OS_local;
15631562
var $OS_remote;
1564-
/* Private variables */
15651563
var $_lastaction;
15661564
var $_errors;
15671565
var $_type;
@@ -1592,7 +1590,6 @@ class ftp_base
15921590
var $OS_FullName;
15931591
var $_eol_code;
15941592
var $AutoAsciiExt;
1595-
/* Constructor */
15961593
function __construct($port_mode = \FALSE, $verb = \FALSE, $le = \FALSE)
15971594
{
15981595
}
@@ -2032,12 +2029,6 @@ public function clear_destination($remote_destination)
20322029
{
20332030
}
20342031
}
2035-
/* For future use
2036-
define( 'PCLZIP_CB_PRE_LIST', 78005 );
2037-
define( 'PCLZIP_CB_POST_LIST', 78006 );
2038-
define( 'PCLZIP_CB_PRE_DELETE', 78007 );
2039-
define( 'PCLZIP_CB_POST_DELETE', 78008 );
2040-
*/
20412032
class PclZip
20422033
{
20432034
var $zipname = '';
@@ -27615,31 +27606,6 @@ public function parse_file()
2761527606
}
2761627607
}
2761727608
namespace {
27618-
#
27619-
# Portable PHP password hashing framework.
27620-
#
27621-
# Version 0.5 / WordPress.
27622-
#
27623-
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
27624-
# the public domain. Revised in subsequent years, still public domain.
27625-
#
27626-
# There's absolutely no warranty.
27627-
#
27628-
# The homepage URL for this framework is:
27629-
#
27630-
# http://www.openwall.com/phpass/
27631-
#
27632-
# Please be sure to update the Version line if you edit this file in any way.
27633-
# It is suggested that you leave the main version number intact, but indicate
27634-
# your project name (after the slash) and add your own revision information.
27635-
#
27636-
# Please do not change the "private" password hashing method implemented in
27637-
# here, thereby making your hashes incompatible. However, if you must, please
27638-
# change the hash type identifier (the "$P$") to something different.
27639-
#
27640-
# Obviously, since this code is in the public domain, the above are not
27641-
# requirements (there can be none), but merely suggestions.
27642-
#
2764327609
/**
2764427610
* Portable PHP password hashing framework.
2764527611
*
@@ -72150,20 +72116,6 @@ public function get_item_schema()
7215072116
public function get_collection_params()
7215172117
{
7215272118
}
72153-
/*
72154-
* Include a hash of the query args, so that different requests are stored in
72155-
* separate caches.
72156-
*
72157-
* MD5 is chosen for its speed, low-collision rate, universal availability, and to stay
72158-
* under the character limit for `_site_transient_timeout_{...}` keys.
72159-
*
72160-
* @link https://stackoverflow.com/questions/3665247/fastest-hash-for-non-cryptographic-uses
72161-
*
72162-
* @since 6.0.0
72163-
*
72164-
* @param array $query_args Query arguments to generate a transient key from.
72165-
* @return string Transient key.
72166-
*/
7216772119
protected function get_transient_key($query_args)
7216872120
{
7216972121
}
@@ -80108,9 +80060,6 @@ function wp_dashboard_empty()
8010880060
function wp_welcome_panel()
8010980061
{
8011080062
}
80111-
/*
80112-
* Deprecated functions come here to die.
80113-
*/
8011480063
/**
8011580064
* @since 2.1.0
8011680065
* @deprecated 2.1.0 Use wp_editor()
@@ -100633,9 +100582,6 @@ function wp_functionality_constants()
100633100582
function wp_templating_constants()
100634100583
{
100635100584
}
100636-
/*
100637-
* Deprecated functions come here to die.
100638-
*/
100639100585
/**
100640100586
* Retrieves all post data for a given post.
100641100587
*
@@ -121172,9 +121118,6 @@ function ms_file_constants()
121172121118
function ms_subdomain_constants()
121173121119
{
121174121120
}
121175-
/*
121176-
* Deprecated functions come here to die.
121177-
*/
121178121121
/**
121179121122
* Get the "dashboard blog", the blog where users without a blog edit their profile data.
121180121123
* Dashboard blog functionality was removed in WordPress 3.1, replaced by the user admin.

0 commit comments

Comments
 (0)