diff --git a/lib-3rd-party/pquery/IQuery.php b/lib-3rd-party/pquery/IQuery.php index cd3d18d9e1..93a7c205fa 100644 --- a/lib-3rd-party/pquery/IQuery.php +++ b/lib-3rd-party/pquery/IQuery.php @@ -1,6 +1,6 @@ "; } diff --git a/lib-3rd-party/pquery/gan_node_html.php b/lib-3rd-party/pquery/gan_node_html.php index a6bb61589b..4a8a7ee8f9 100644 --- a/lib-3rd-party/pquery/gan_node_html.php +++ b/lib-3rd-party/pquery/gan_node_html.php @@ -7,7 +7,7 @@ * @package pQuery */ -namespace pQuery; +namespace MailPoetVendor\pQuery; /** * Holds (x)html/xml tag information like tag name, attributes, @@ -65,14 +65,14 @@ class DomNode implements IQuery { * @var string * @see select() */ - var $selectClass = 'pQuery\\HtmlSelector'; + var $selectClass = 'MailPoetVendor\\pQuery\\HtmlSelector'; /** * Name of the parser class * @var string * @see setOuterText() * @see setInnerText() */ - var $parserClass = 'pQuery\\Html5Parser'; + var $parserClass = 'MailPoetVendor\\pQuery\\Html5Parser'; /** * Name of the class used for {@link addChild()} @@ -83,37 +83,37 @@ class DomNode implements IQuery { * Name of the class used for {@link addText()} * @var string */ - var $childClass_Text = 'pQuery\\TextNode'; + var $childClass_Text = 'MailPoetVendor\\pQuery\\TextNode'; /** * Name of the class used for {@link addComment()} * @var string */ - var $childClass_Comment = 'pQuery\\CommentNode'; + var $childClass_Comment = 'MailPoetVendor\\pQuery\\CommentNode'; /** * Name of the class used for {@link addContional()} * @var string */ - var $childClass_Conditional = 'pQuery\\ConditionalTagNode'; + var $childClass_Conditional = 'MailPoetVendor\\pQuery\\ConditionalTagNode'; /** * Name of the class used for {@link addCDATA()} * @var string */ - var $childClass_CDATA = 'pQuery\\CdataNode'; + var $childClass_CDATA = 'MailPoetVendor\\pQuery\\CdataNode'; /** * Name of the class used for {@link addDoctype()} * @var string */ - var $childClass_Doctype = 'pQuery\\DoctypeNode'; + var $childClass_Doctype = 'MailPoetVendor\\pQuery\\DoctypeNode'; /** * Name of the class used for {@link addXML()} * @var string */ - var $childClass_XML = 'pQuery\\XmlNode'; + var $childClass_XML = 'MailPoetVendor\\pQuery\\XmlNode'; /** * Name of the class used for {@link addASP()} * @var string */ - var $childClass_ASP = 'pQuery\\AspEmbeddedNode'; + var $childClass_ASP = 'MailPoetVendor\\pQuery\\AspEmbeddedNode'; /** * Parent node, null if none @@ -311,7 +311,7 @@ class DomNode implements IQuery { /** * Class magic invoke method, performs {@link query()}. * @param string $query The css query to run on the nodes. - * @return \pQuery + * @return pQuery */ function __invoke($query = '*') { return $this->query($query); @@ -1922,7 +1922,7 @@ class DomNode implements IQuery { */ public function query($query = '*') { $select = $this->select($query); - $result = new \pQuery((array)$select); + $result = new pQuery((array)$select); return $result; } @@ -2352,7 +2352,7 @@ class DomNode implements IQuery { return $this; } - public function count() { + public function count(): int { return 1; } @@ -2852,4 +2852,4 @@ class AspEmbeddedNode extends EmbeddedNode { #php4e } -?> \ No newline at end of file +?> diff --git a/lib-3rd-party/pquery/gan_parser_html.php b/lib-3rd-party/pquery/gan_parser_html.php index 75e44d7a24..9d01319123 100644 --- a/lib-3rd-party/pquery/gan_parser_html.php +++ b/lib-3rd-party/pquery/gan_parser_html.php @@ -7,7 +7,7 @@ * @package pQuery */ -namespace pQuery; +namespace MailPoetVendor\pQuery; /** * Parses a HTML document @@ -488,7 +488,7 @@ class HtmlParser extends HtmlParserBase { * @internal If string, then it will create a new instance as root * @var DomNode */ - var $root = 'pQuery\\DomNode'; + var $root = 'MailPoetVendor\\pQuery\\DomNode'; /** * Current parsing hierarchy @@ -836,4 +836,4 @@ class Html5Parser extends HtmlParser { } } -?> \ No newline at end of file +?> diff --git a/lib-3rd-party/pquery/gan_selector_html.php b/lib-3rd-party/pquery/gan_selector_html.php index c7c2b4fb47..c861364dc0 100644 --- a/lib-3rd-party/pquery/gan_selector_html.php +++ b/lib-3rd-party/pquery/gan_selector_html.php @@ -7,7 +7,7 @@ * @package pQuery */ -namespace pQuery; +namespace MailPoetVendor\pQuery; /** * Tokenizes a css selector query @@ -281,7 +281,7 @@ class HtmlSelector { * @internal If string, then it will create a new instance as parser * @var CSSQueryTokenizer */ - var $parser = 'pQuery\\CSSQueryTokenizer'; + var $parser = 'MailPoetVendor\\pQuery\\CSSQueryTokenizer'; /** * Target of queries @@ -945,5 +945,3 @@ class HtmlSelector { return true; } } - -?> diff --git a/lib-3rd-party/pquery/gan_tokenizer.php b/lib-3rd-party/pquery/gan_tokenizer.php index a8261a0dd9..c5287fa085 100644 --- a/lib-3rd-party/pquery/gan_tokenizer.php +++ b/lib-3rd-party/pquery/gan_tokenizer.php @@ -7,7 +7,7 @@ * @package pQuery */ -namespace pQuery; +namespace MailPoetVendor\pQuery; /** * Converts a document into tokens @@ -563,4 +563,4 @@ class TokenizerBase { } } -?> \ No newline at end of file +?> diff --git a/lib-3rd-party/pquery/gan_xml2array.php b/lib-3rd-party/pquery/gan_xml2array.php index f790926861..bb9fdbe9fa 100644 --- a/lib-3rd-party/pquery/gan_xml2array.php +++ b/lib-3rd-party/pquery/gan_xml2array.php @@ -7,7 +7,7 @@ * @package pQuery */ -namespace pQuery; +namespace MailPoetVendor\pQuery; /** * Converts a XML document to an array @@ -98,4 +98,4 @@ class XML2ArrayParser extends HtmlParserBase { } } -?> \ No newline at end of file +?> diff --git a/lib-3rd-party/pquery/ganon.php b/lib-3rd-party/pquery/ganon.php index 4daaa8b70b..7696b27bc6 100644 --- a/lib-3rd-party/pquery/ganon.php +++ b/lib-3rd-party/pquery/ganon.php @@ -7,8 +7,8 @@ * @package pQuery */ -use pQuery\Html5Parser; -use pQuery\HtmlFormatter; +use MailPoetVendor\pQuery\Html5Parser; +use MailPoetVendor\pQuery\HtmlFormatter; /** * Returns HTML DOM from string @@ -98,4 +98,4 @@ if (!defined('GANON_NO_INCLUDES')) { } #! -?> \ No newline at end of file +?> diff --git a/lib-3rd-party/pquery/pQuery.php b/lib-3rd-party/pquery/pQuery.php index 7d451e813c..14bafce5b7 100644 --- a/lib-3rd-party/pquery/pQuery.php +++ b/lib-3rd-party/pquery/pQuery.php @@ -7,12 +7,13 @@ * @package pQuery */ -use pQuery\IQuery; +namespace MailPoetVendor\pQuery; + /** * A jQuery-like object for php. */ -class pQuery implements ArrayAccess, IteratorAggregate, IQuery { +class pQuery implements \ArrayAccess, \IteratorAggregate, IQuery { /// Properties /// /** @@ -78,15 +79,15 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery { * * @return int Returns the count of matched elements. */ - public function count() { + public function count(): int { return count($this->nodes); } /** * Format/beautify a DOM. * - * @param pQuery\DomNode $dom The dom to format. - * @param array $options Extra formatting options. See {@link pQuery\HtmlFormatter::$options}. + * @param DomNode $dom The dom to format. + * @param array $options Extra formatting options. See {@link HtmlFormatter::$options}. * @return bool Returns `true` on sucess and `false` on failure. */ // public static function format($dom, $options = array()) { @@ -94,8 +95,8 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery { // return $formatter->format($dom); // } - public function getIterator() { - return new ArrayIterator($this->nodes); + public function getIterator(): \ArrayIterator { + return new \ArrayIterator($this->nodes); } public function hasClass($classname) { @@ -118,15 +119,16 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery { return $this; } - public function offsetExists($offset) { + public function offsetExists($offset): bool { return isset($this->nodes[$offset]); } + #[\ReturnTypeWillChange] public function offsetGet($offset) { return isset($this->nodes[$offset]) ? $this->nodes[$offset] : null; } - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { if (is_null($offset) || !isset($this->nodes[$offset])) { throw new \BadMethodCallException("You are not allowed to add new nodes to the pQuery object."); @@ -135,7 +137,7 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery { } } - public function offsetUnset($offset) { + public function offsetUnset($offset): void { if (isset($this->nodes[$offset])) { $this->nodes[$offset]->remove(); unset($this->nodes[$offset]); @@ -147,7 +149,7 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery { * * @param string $path The path to the url. * @param resource $context A context suitable to be passed into {@link file_get_contents} - * @return pQuery\DomNode Returns the root dom node for the html file. + * @return DomNode Returns the root dom node for the html file. */ public static function parseFile($path, $context = null) { $html_str = file_get_contents($path, false, $context); @@ -158,10 +160,10 @@ class pQuery implements ArrayAccess, IteratorAggregate, IQuery { * Query a string of html. * * @param string $html - * @return pQuery\DomNode Returns the root dom node for the html string. + * @return DomNode Returns the root dom node for the html string. */ public static function parseStr($html) { - $parser = new pQuery\Html5Parser($html); + $parser = new Html5Parser($html); return $parser->root; } diff --git a/lib-3rd-party/pquery/third_party/jsminplus.php b/lib-3rd-party/pquery/third_party/jsminplus.php index d12b8c876e..d5af2b463e 100644 --- a/lib-3rd-party/pquery/third_party/jsminplus.php +++ b/lib-3rd-party/pquery/third_party/jsminplus.php @@ -1,5 +1,7 @@ toString(true, true, 1), ENT_NOQUOTES, 'UTF-8'); @@ -12,4 +15,10 @@ class DomNode extends \pQuery\DomNode { public function getOuterText() { return html_entity_decode($this->toString(), ENT_NOQUOTES, 'UTF-8'); } + + public function query($query = '*') { + $select = $this->select($query); + $result = new pQuery((array)$select); + return $result; + } } diff --git a/lib/Util/pQuery/Html5Parser.php b/lib/Util/pQuery/Html5Parser.php index d993f86283..397daad6f5 100644 --- a/lib/Util/pQuery/Html5Parser.php +++ b/lib/Util/pQuery/Html5Parser.php @@ -2,7 +2,9 @@ namespace MailPoet\Util\pQuery; -class Html5Parser extends \pQuery\HtmlParser { - /** @var string|\pQuery\DomNode */ - public $root = 'MailPoet\Util\pQuery\DomNode'; +use MailPoetVendor\pQuery\HtmlParser; + +class Html5Parser extends HtmlParser { + /** @var string|DomNode */ + public $root = DomNode::class; } diff --git a/lib/Util/pQuery/pQuery.php b/lib/Util/pQuery/pQuery.php index 87394e0534..aff8de58e8 100644 --- a/lib/Util/pQuery/pQuery.php +++ b/lib/Util/pQuery/pQuery.php @@ -2,13 +2,15 @@ namespace MailPoet\Util\pQuery; +use MailPoetVendor\pQuery\pQuery as pQuerypQuery; + // extend pQuery class to use UTF-8 encoding when getting elements' inner/outer text // phpcs:ignore Squiz.Classes.ValidClassName -class pQuery extends \pQuery { - public static function parseStr($html) { +class pQuery extends pQuerypQuery { + public static function parseStr($html): DomNode { $parser = new Html5Parser($html); - if (!$parser->root instanceof \pQuery\DomNode) { + if (!$parser->root instanceof DomNode) { // this condition shouldn't happen it is here only for PHPStan throw new \Exception('Renderer is not configured correctly'); } diff --git a/tasks/phpstan/phpstan.neon b/tasks/phpstan/phpstan.neon index 664bd5d647..b2cda934be 100644 --- a/tasks/phpstan/phpstan.neon +++ b/tasks/phpstan/phpstan.neon @@ -16,7 +16,7 @@ parameters: ignoreErrors: - '#Function members_register_.+ not found#' - '#Call to an undefined method MailPoetVendor\\Idiorm\\IdiormResultSet::set\(\)#' - - '#Argument of an invalid type pQuery\\IQuery supplied for foreach, only iterables are supported#' + - '#Argument of an invalid type MailPoetVendor\\pQuery\\IQuery supplied for foreach, only iterables are supported#' - '/(with|has) no (return )?typehint specified/' # exclude level 6 errors - # Primary keys ScheduledTaskSubscriberEntity of are foreign keys and foreign keys may be null because of missing related record message: '#Property MailPoet\\Entities\\[a-zA-Z]+::\$[a-z]+ type mapping mismatch: property can contain MailPoet\\Entities\\[a-zA-Z]+\|null but database expects MailPoet\\Entities\\[a-zA-Z]+.#' diff --git a/tests/integration/Config/ShortcodesTest.php b/tests/integration/Config/ShortcodesTest.php index 5ac4d44ca4..a44f9514e6 100644 --- a/tests/integration/Config/ShortcodesTest.php +++ b/tests/integration/Config/ShortcodesTest.php @@ -12,6 +12,7 @@ use MailPoet\Models\Subscriber; use MailPoet\Newsletter\Url; use MailPoet\Router\Router; use MailPoet\Tasks\Sending as SendingTask; +use MailPoet\Util\pQuery\pQuery; use MailPoet\WP\Functions as WPFunctions; use MailPoetVendor\Idiorm\ORM; @@ -51,7 +52,7 @@ class ShortcodesTest extends \MailPoetTest { // result contains a link pointing to the "view in browser" router endpoint $result = $shortcodes->getArchive($params = false); WordPress::releaseFunction('apply_filters'); - $dom = \pQuery::parseStr($result); + $dom = pQuery::parseStr($result); $link = $dom->query('a'); /** @var string $link */ $link = $link->attr('href'); diff --git a/tests/integration/Newsletter/RendererTest.php b/tests/integration/Newsletter/RendererTest.php index 9f29169a2a..9f09de2eac 100644 --- a/tests/integration/Newsletter/RendererTest.php +++ b/tests/integration/Newsletter/RendererTest.php @@ -18,6 +18,7 @@ use MailPoet\Newsletter\Renderer\Preprocessor; use MailPoet\Newsletter\Renderer\Renderer; use MailPoet\Services\Bridge; use MailPoet\Util\License\License; +use MailPoet\Util\pQuery\pQuery; use PHPUnit\Framework\MockObject\MockObject; use WP_Error; @@ -60,7 +61,7 @@ class RendererTest extends \MailPoetTest { $this->license ); $this->columnRenderer = new ColumnRenderer(); - $this->dOMParser = new \pQuery(); + $this->dOMParser = new pQuery(); } public function testItRendersCompleteNewsletter() { diff --git a/tests/unit/Newsletter/Renderer/Blocks/TextTest.php b/tests/unit/Newsletter/Renderer/Blocks/TextTest.php index b7c02a862f..6c4eb6c24c 100644 --- a/tests/unit/Newsletter/Renderer/Blocks/TextTest.php +++ b/tests/unit/Newsletter/Renderer/Blocks/TextTest.php @@ -35,7 +35,7 @@ class TextTest extends \MailPoetUnitTest { $this->block['text'] = '
Text
'; $output = (new Text)->render($this->block); $table = $this->parser->parseStr($output)->query('table'); - assert($table instanceof \pQuery); + assert($table instanceof pQuery); $paragraphTable = $table[0]->toString(); $expectedResult = ''; $output = (new Text)->render($this->block); $table = $this->parser->parseStr($output)->query('table'); - assert($table instanceof \pQuery); + assert($table instanceof pQuery); $blockquoteTable = $table[0]->toString(); $expectedResult = 'Quote