From 15e4968ee95c442c6c5a7a8a1e037d488f966316 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sun, 8 Sep 2019 19:18:27 +0200 Subject: [PATCH] parser: Declare some dynamic properties Mostly via the @property annotation. This is to make phan a little happier. Change-Id: I3fde33955240dab20870821e9db93caba163845b --- includes/parser/PPDPart.php | 4 ++++ includes/parser/PPDStack.php | 2 ++ includes/parser/PPDStackElement.php | 2 ++ includes/parser/PPFrame.php | 3 +++ includes/parser/PPFrame_DOM.php | 7 ++++--- includes/parser/PPTemplateFrame_Hash.php | 2 ++ includes/parser/Preprocessor.php | 5 +++++ includes/parser/Preprocessor_Hash.php | 6 ------ 8 files changed, 22 insertions(+), 9 deletions(-) diff --git a/includes/parser/PPDPart.php b/includes/parser/PPDPart.php index b56527ac6a..6b63a0dd96 100644 --- a/includes/parser/PPDPart.php +++ b/includes/parser/PPDPart.php @@ -21,6 +21,10 @@ /** * @ingroup Parser + * + * @property int $eqpos + * @property int $commentEnd + * @property int $visualEnd */ class PPDPart { /** diff --git a/includes/parser/PPDStack.php b/includes/parser/PPDStack.php index 68f1bb27bf..b9d796d7a0 100644 --- a/includes/parser/PPDStack.php +++ b/includes/parser/PPDStack.php @@ -27,6 +27,8 @@ class PPDStack { /** @var PPDStackElement[] */ public $stack; public $rootAccum; + /** @var string|array */ + public $accum; /** * @var PPDStackElement|false diff --git a/includes/parser/PPDStackElement.php b/includes/parser/PPDStackElement.php index 116244dbb7..fe2b04e223 100644 --- a/includes/parser/PPDStackElement.php +++ b/includes/parser/PPDStackElement.php @@ -21,6 +21,8 @@ /** * @ingroup Parser + * + * @property int $startPos */ class PPDStackElement { /** diff --git a/includes/parser/PPFrame.php b/includes/parser/PPFrame.php index 3f147f01c3..b50fcfce05 100644 --- a/includes/parser/PPFrame.php +++ b/includes/parser/PPFrame.php @@ -21,6 +21,9 @@ /** * @ingroup Parser + * + * @property int $depth + * @property PPFrame $parent */ interface PPFrame { const NO_ARGS = 1; diff --git a/includes/parser/PPFrame_DOM.php b/includes/parser/PPFrame_DOM.php index bb310f2113..a0ec326d95 100644 --- a/includes/parser/PPFrame_DOM.php +++ b/includes/parser/PPFrame_DOM.php @@ -82,7 +82,7 @@ class PPFrame_DOM implements PPFrame { * Create a new child frame * $args is optionally a multi-root PPNode or array containing the template arguments * - * @param bool|array $args + * @param bool|array|PPNode_DOM $args * @param Title|bool $title * @param int $indexOffset * @return PPTemplateFrame_DOM @@ -95,11 +95,12 @@ class PPFrame_DOM implements PPFrame { } if ( $args !== false ) { $xpath = false; - if ( $args instanceof PPNode ) { + if ( $args instanceof PPNode_DOM ) { $args = $args->node; } + // @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach foreach ( $args as $arg ) { - if ( $arg instanceof PPNode ) { + if ( $arg instanceof PPNode_DOM ) { $arg = $arg->node; } if ( !$xpath || $xpath->document !== $arg->ownerDocument ) { diff --git a/includes/parser/PPTemplateFrame_Hash.php b/includes/parser/PPTemplateFrame_Hash.php index df740cf22d..902e4f17b8 100644 --- a/includes/parser/PPTemplateFrame_Hash.php +++ b/includes/parser/PPTemplateFrame_Hash.php @@ -40,6 +40,8 @@ class PPTemplateFrame_Hash extends PPFrame_Hash { $namedArgs = [], $title = false ) { parent::__construct( $preprocessor ); + /** @var PPFrame_Hash parent */ + '@phan-var PPFrame_Hash $parent'; $this->parent = $parent; $this->numberedArgs = $numberedArgs; diff --git a/includes/parser/Preprocessor.php b/includes/parser/Preprocessor.php index 99ca1be489..19dd96e885 100644 --- a/includes/parser/Preprocessor.php +++ b/includes/parser/Preprocessor.php @@ -31,6 +31,11 @@ abstract class Preprocessor { const CACHE_VERSION = 1; + /** + * @var Parser + */ + public $parser; + /** * @var array Brace matching rules. */ diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 9f4b7c73f0..7c372ee3d7 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -41,12 +41,6 @@ */ // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class Preprocessor_Hash extends Preprocessor { - - /** - * @var Parser - */ - public $parser; - const CACHE_PREFIX = 'preprocess-hash'; const CACHE_VERSION = 2; -- 2.20.1