Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDelMar committed Oct 5, 2024
2 parents 34c15b2 + 1484a81 commit c53b25c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 116 deletions.
118 changes: 59 additions & 59 deletions src/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,8 @@ public function enterNode(Node $node)
return null;
}

$symbolName = self::getNodeName($node);

if ($node instanceof ClassMethod || $node instanceof Property) {
$parent = $this->stack[count($this->stack) - 2];
\assert($parent instanceof \PhpParser\Node\Stmt\ClassLike);

if ($parent->name !== null) {
$symbolName = sprintf(
'%1$s::%2$s%3$s',
$parent->name->name,
$node instanceof Property ? '$' : '',
$symbolName
);
}
}
$node->setAttribute('fullSymbolName', $symbolName);
$symbolName = $this->getSymbolName($node);
$node->setAttribute('WPStubs_symbolName', $symbolName);

$additions = $this->generateAdditionalTagsFromDoc($docComment);
if (count($additions) > 0) {
Expand All @@ -108,12 +94,10 @@ public function enterNode(Node $node)
$this->additionalTagStrings[$symbolName] = $additions;
}

if ($voidOrNever !== '') {
if ($voidOrNever instanceof Type) {
$addition = sprintf(
'@phpstan-return %s',
$voidOrNever === 'never'
? (new Never_())->__toString()
: (new Void_())->__toString()
$voidOrNever->__toString()
);
if (
! isset($this->additionalTagStrings[$symbolName])
Expand All @@ -126,17 +110,32 @@ public function enterNode(Node $node)
return null;
}

private static function getNodeName(Node $node): string
private function getSymbolName(Node $node): string
{
if ((($node instanceof Function_) || ($node instanceof ClassMethod) || ($node instanceof Class_)) && $node->name instanceof Identifier) {
return $node->name->name;
$name = $node->name->name;
}

if ($node instanceof Property) {
return $node->props[0]->name->name;
$name = $node->props[0]->name->name;
}

return '';
\assert(isset($name), 'Node does not have a name');

if ($node instanceof Function_ || $node instanceof Class_) {
return $name;
}

$parent = $this->stack[count($this->stack) - 2];
\assert($parent instanceof \PhpParser\Node\Stmt\ClassLike);
\assert($parent->name instanceof \PhpParser\Node\Identifier);

return sprintf(
'%1$s::%2$s%3$s',
$parent->name->name,
$node instanceof Property ? '$' : '',
$name
);
}

/**
Expand Down Expand Up @@ -164,10 +163,10 @@ private function postProcessNode(Node $node): void
return;
}

/** @var ?string $fullSymbolName */
$fullSymbolName = $node->getAttribute('fullSymbolName');
/** @var ?string $symbolName */
$symbolName = $node->getAttribute('WPStubs_symbolName');

if ($fullSymbolName === null) {
if ($symbolName === null) {
return;
}

Expand All @@ -177,13 +176,13 @@ private function postProcessNode(Node $node): void
return;
}

$newDocComment = $this->addTags($fullSymbolName, $docComment);
$newDocComment = $this->addTags($symbolName, $docComment);

if ($newDocComment instanceof Doc) {
$node->setDocComment($newDocComment);
}

if (! isset($this->additionalTagStrings[$fullSymbolName])) {
if (! isset($this->additionalTagStrings[$symbolName])) {
return;
}

Expand All @@ -193,7 +192,7 @@ private function postProcessNode(Node $node): void
return;
}

$newDocComment = $this->addStringTags($fullSymbolName, $docComment);
$newDocComment = $this->addStringTags($symbolName, $docComment);

if (! ($newDocComment instanceof Doc)) {
return;
Expand Down Expand Up @@ -785,15 +784,18 @@ private static function isOptional(string $description): bool
|| (stripos($description, 'Defaults to ') !== false);
}

private function voidOrNever(Node $node): string
private function voidOrNever(Node $node): ?Type
{
$never = new Never_();
$void = new Void_();

if (! ($node instanceof Function_) && ! ($node instanceof ClassMethod)) {
return '';
return null;
}

if (! isset($node->stmts) || count($node->stmts) === 0) {
// Interfaces and abstract methods.
return '';
return null;
}

$returnStmts = $this->nodeFinder->findInstanceOf($node, Stmt_Return::class);
Expand All @@ -810,11 +812,11 @@ static function (Node $node): bool {
}
) instanceof Node
) {
return '';
return null;
}
// If there is no return statement that is not void,
// it's return type void.
return 'void';
return $void;
}

// Check for never return type.
Expand All @@ -825,12 +827,12 @@ static function (Node $node): bool {
// If a first level statement is exit/die, it's return type never.
if ($stmt->expr instanceof Exit_) {
if (! $stmt->expr->expr instanceof String_) {
return 'never';
return $never;
}
if (strpos($stmt->expr->expr->value, 'must be overridden') !== false) {
return '';
return null;
}
return 'never';
return $never;
}
if (! ($stmt->expr instanceof FuncCall) || ! ($stmt->expr->name instanceof Name)) {
continue;
Expand All @@ -839,7 +841,7 @@ static function (Node $node): bool {
// If a first level statement is a call to wp_send_json(_success/error),
// it's return type never.
if (strpos($name->toString(), 'wp_send_json') === 0) {
return 'never';
return $never;
}
// Skip all functions but wp_die().
if (strpos($name->toString(), 'wp_die') !== 0) {
Expand All @@ -848,7 +850,7 @@ static function (Node $node): bool {
$args = $stmt->expr->getArgs();
// If wp_die is called without 3rd parameter, it's return type never.
if (count($args) < 3) {
return 'never';
return $never;
}
// If wp_die is called with 3rd parameter, we need additional checks.
try {
Expand All @@ -859,18 +861,18 @@ static function (Node $node): bool {
}

if (is_int($arg)) {
return 'never';
return $never;
}

if (! is_array($arg)) {
continue;
}

if (! array_key_exists('exit', $arg) || (bool)$arg['exit']) {
return 'never';
return $never;
}
}
return '';
return null;
}

private function getCleanCommentsNode(Node $node): Node
Expand All @@ -879,28 +881,26 @@ private function getCleanCommentsNode(Node $node): Node
return $node;
}

// Remove "//" comments.
$comments = [];
foreach ($node->getComments() as $comment) {
if (strpos(trim($comment->getText()), '//') === 0) {
$commentText = trim($comment->getText());

// Strip out comments that are not PHPDoc comments.
if (
strpos($commentText, '/**') === false
) {
continue;
}
$comments[] = $comment;
}

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

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

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

$node->setAttribute('comments', $comments);
Expand Down
57 changes: 0 additions & 57 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -1556,12 +1556,10 @@ public function cleanup()
*/
class ftp_base
{
/* Public variables */
var $LocalEcho;
var $Verbose;
var $OS_local;
var $OS_remote;
/* Private variables */
var $_lastaction;
var $_errors;
var $_type;
Expand Down Expand Up @@ -1592,7 +1590,6 @@ class ftp_base
var $OS_FullName;
var $_eol_code;
var $AutoAsciiExt;
/* Constructor */
function __construct($port_mode = \FALSE, $verb = \FALSE, $le = \FALSE)
{
}
Expand Down Expand Up @@ -2032,12 +2029,6 @@ public function clear_destination($remote_destination)
{
}
}
/* For future use
define( 'PCLZIP_CB_PRE_LIST', 78005 );
define( 'PCLZIP_CB_POST_LIST', 78006 );
define( 'PCLZIP_CB_PRE_DELETE', 78007 );
define( 'PCLZIP_CB_POST_DELETE', 78008 );
*/
class PclZip
{
var $zipname = '';
Expand Down Expand Up @@ -27615,31 +27606,6 @@ public function parse_file()
}
}
namespace {
#
# Portable PHP password hashing framework.
#
# Version 0.5 / WordPress.
#
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
# the public domain. Revised in subsequent years, still public domain.
#
# There's absolutely no warranty.
#
# The homepage URL for this framework is:
#
# http://www.openwall.com/phpass/
#
# Please be sure to update the Version line if you edit this file in any way.
# It is suggested that you leave the main version number intact, but indicate
# your project name (after the slash) and add your own revision information.
#
# Please do not change the "private" password hashing method implemented in
# here, thereby making your hashes incompatible. However, if you must, please
# change the hash type identifier (the "$P$") to something different.
#
# Obviously, since this code is in the public domain, the above are not
# requirements (there can be none), but merely suggestions.
#
/**
* Portable PHP password hashing framework.
*
Expand Down Expand Up @@ -72150,20 +72116,6 @@ public function get_item_schema()
public function get_collection_params()
{
}
/*
* Include a hash of the query args, so that different requests are stored in
* separate caches.
*
* MD5 is chosen for its speed, low-collision rate, universal availability, and to stay
* under the character limit for `_site_transient_timeout_{...}` keys.
*
* @link https://stackoverflow.com/questions/3665247/fastest-hash-for-non-cryptographic-uses
*
* @since 6.0.0
*
* @param array $query_args Query arguments to generate a transient key from.
* @return string Transient key.
*/
protected function get_transient_key($query_args)
{
}
Expand Down Expand Up @@ -80108,9 +80060,6 @@ function wp_dashboard_empty()
function wp_welcome_panel()
{
}
/*
* Deprecated functions come here to die.
*/
/**
* @since 2.1.0
* @deprecated 2.1.0 Use wp_editor()
Expand Down Expand Up @@ -100633,9 +100582,6 @@ function wp_functionality_constants()
function wp_templating_constants()
{
}
/*
* Deprecated functions come here to die.
*/
/**
* Retrieves all post data for a given post.
*
Expand Down Expand Up @@ -121172,9 +121118,6 @@ function ms_file_constants()
function ms_subdomain_constants()
{
}
/*
* Deprecated functions come here to die.
*/
/**
* Get the "dashboard blog", the blog where users without a blog edit their profile data.
* Dashboard blog functionality was removed in WordPress 3.1, replaced by the user admin.
Expand Down

0 comments on commit c53b25c

Please sign in to comment.