From f87fd6276c69e42b29436cf5e7555fcf08a549e3 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 11 Jan 2021 14:06:02 +0100 Subject: [PATCH] Manual CS fixes Signed-off-by: Filippo Tessarotto --- src/DOMXPath.php | 4 ++-- src/Document.php | 13 +++++++------ src/Document/NodeList.php | 4 ++-- src/Document/Query.php | 8 ++++---- src/NodeList.php | 4 ++-- src/Query.php | 12 ++++++------ test/DOMXPathTest.php | 8 ++++---- test/Document/QueryTest.php | 7 ++++--- test/DocumentTest.php | 7 +++---- 9 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/DOMXPath.php b/src/DOMXPath.php index 6413373..e07940a 100644 --- a/src/DOMXPath.php +++ b/src/DOMXPath.php @@ -70,14 +70,14 @@ public function queryWithErrorException($expression, ?DOMNode $contextNode = nul */ public function addError($errno, $errstr = '', $errfile = '', $errline = 0) { - $last_error = end($this->errors); + $lastError = end($this->errors); $this->errors[] = new ErrorException( $errstr, 0, $errno, $errfile, $errline, - $last_error + $lastError ); } } diff --git a/src/Document.php b/src/Document.php index 4ba429d..2969e3a 100644 --- a/src/Document.php +++ b/src/Document.php @@ -31,9 +31,9 @@ class Document /**#@+ * Document types */ - const DOC_HTML = 'DOC_HTML'; - const DOC_XHTML = 'DOC_XHTML'; - const DOC_XML = 'DOC_XML'; + public const DOC_HTML = 'DOC_HTML'; + public const DOC_XHTML = 'DOC_XHTML'; + public const DOC_XML = 'DOC_XML'; /**#@-*/ /** @@ -120,7 +120,7 @@ protected function setStringDocument($document, $forcedType = null, $forcedEncod } // Breaking XML declaration to make syntax highlighting work - if ('<' . '?xml' == substr(trim($document), 0, 5)) { + if ('<' . '?xml' === substr(trim($document), 0, 5)) { $type = static::DOC_XML; if (preg_match('/]*xmlns="([^"]+)"[^>]*>/i', $document, $matches)) { $this->xpathNamespaces[] = $matches[1]; @@ -166,7 +166,7 @@ protected function setType($type) * Get DOMDocument generated from set raw document * * @return DOMDocument - * @throws Exception\RuntimeException If cannot get DOMDocument; no document registered + * @throws Exception\RuntimeException If cannot get DOMDocument; no document registered. */ public function getDomDocument() { @@ -244,6 +244,7 @@ protected function setErrors($errors) /** * Get DOMDocument from set raw document * + * @param string $stringDocument * @return DOMDocument * @throws Exception\RuntimeException */ @@ -342,7 +343,7 @@ public function registerXpathPhpFunctions($xpathPhpFunctions = true) * * @return bool */ - private static function disableEntityLoader($flag = true) + private static function disableEntityLoader(bool $flag = true) { if (LIBXML_VERSION < 20900) { return libxml_disable_entity_loader($flag); diff --git a/src/Document/NodeList.php b/src/Document/NodeList.php index 7aabb26..32080b1 100644 --- a/src/Document/NodeList.php +++ b/src/Document/NodeList.php @@ -130,7 +130,7 @@ public function offsetGet($key) * * @param mixed $key * @param mixed $value - * @throws Exception\BadMethodCallException when attempting to write to a read-only item + * @throws Exception\BadMethodCallException When attempting to write to a read-only item. */ public function offsetSet($key, $value) { @@ -141,7 +141,7 @@ public function offsetSet($key, $value) * ArrayAccess: unset offset * * @param mixed $key - * @throws Exception\BadMethodCallException when attempting to unset a read-only item + * @throws Exception\BadMethodCallException When attempting to unset a read-only item. */ public function offsetUnset($key) { diff --git a/src/Document/Query.php b/src/Document/Query.php index 5caa1bd..dc36b4f 100644 --- a/src/Document/Query.php +++ b/src/Document/Query.php @@ -39,8 +39,8 @@ class Query /**#@+ * Query types */ - const TYPE_XPATH = 'TYPE_XPATH'; - const TYPE_CSS = 'TYPE_CSS'; + public const TYPE_XPATH = 'TYPE_XPATH'; + public const TYPE_CSS = 'TYPE_CSS'; /**#@-*/ /** @@ -124,7 +124,7 @@ function ($matches) use ($placeholder) { foreach ($segments as $key => $segment) { $pathSegment = static::_tokenize($segment); - if (0 == $key) { + if (0 === $key) { if (0 === strpos($pathSegment, '[contains(')) { $paths[0] .= '*' . ltrim($pathSegment, '*'); } else { @@ -144,7 +144,7 @@ function ($matches) use ($placeholder) { } } - if (1 == count($paths)) { + if (1 === count($paths)) { return $paths[0]; } return implode('|', $paths); diff --git a/src/NodeList.php b/src/NodeList.php index 51737c9..8e5c4b0 100644 --- a/src/NodeList.php +++ b/src/NodeList.php @@ -215,7 +215,7 @@ public function offsetGet($key) * * @param mixed $key * @param mixed $value - * @throws Exception\BadMethodCallException when attempting to write to a read-only item + * @throws Exception\BadMethodCallException When attempting to write to a read-only item. */ public function offsetSet($key, $value) { @@ -226,7 +226,7 @@ public function offsetSet($key, $value) * ArrayAccess: unset offset * * @param mixed $key - * @throws Exception\BadMethodCallException when attempting to unset a read-only item + * @throws Exception\BadMethodCallException When attempting to unset a read-only item. */ public function offsetUnset($key) { diff --git a/src/Query.php b/src/Query.php index d2be92e..d4a1faa 100644 --- a/src/Query.php +++ b/src/Query.php @@ -39,9 +39,9 @@ class Query /**#@+ * Document types */ - const DOC_XML = 'docXml'; - const DOC_HTML = 'docHtml'; - const DOC_XHTML = 'docXhtml'; + public const DOC_XML = 'docXml'; + public const DOC_HTML = 'docHtml'; + public const DOC_XHTML = 'docXhtml'; /**#@-*/ /** @var string */ @@ -129,7 +129,7 @@ public function setDocument($document, $encoding = null) return $this; } // breaking XML declaration to make syntax highlighting work - if ('<' . '?xml' == substr(trim($document), 0, 5)) { + if ('<' . '?xml' === substr(trim($document), 0, 5)) { if (preg_match('/]*xmlns="([^"]+)"[^>]*>/i', $document, $matches)) { $this->xpathNamespaces[] = $matches[1]; return $this->setDocumentXhtml($document, $encoding); @@ -320,7 +320,7 @@ public function registerXpathPhpFunctions($xpathPhpFunctions = true) * @param DOMDocument $document * @param string|array $xpathQuery * @return DOMNodeList - * @throws ErrorException If query cannot be executed + * @throws ErrorException If query cannot be executed. */ protected function getNodeList($document, $xpathQuery, ?DOMNode $contextNode = null) { @@ -349,7 +349,7 @@ protected function getNodeList($document, $xpathQuery, ?DOMNode $contextNode = n * * @return bool */ - private static function disableEntityLoader($flag = true) + private static function disableEntityLoader(bool $flag = true) { if (LIBXML_VERSION < 20900) { return libxml_disable_entity_loader($flag); diff --git a/test/DOMXPathTest.php b/test/DOMXPathTest.php index ead689d..7e034b6 100644 --- a/test/DOMXPathTest.php +++ b/test/DOMXPathTest.php @@ -26,19 +26,19 @@ protected function setUp(): void public function testQueryWithErrorExceptionSuccess() { - $domXPath = new DOMXPath($this->document); + $domXpath = new DOMXPath($this->document); - $result = $domXPath->queryWithErrorException('any'); + $result = $domXpath->queryWithErrorException('any'); $this->assertInstanceOf(DOMNodeList::class, $result); } public function testQueryWithErrorExceptionThrowExceptionWhenQueryExpresionIsInvalid() { - $domXPath = new DOMXPath($this->document); + $domXpath = new DOMXPath($this->document); $this->expectException(ErrorException::class); $this->expectExceptionMessage('Invalid expression'); - $domXPath->queryWithErrorException('any#any'); + $domXpath->queryWithErrorException('any#any'); } } diff --git a/test/Document/QueryTest.php b/test/Document/QueryTest.php index f53fec4..6653300 100644 --- a/test/Document/QueryTest.php +++ b/test/Document/QueryTest.php @@ -8,6 +8,7 @@ namespace LaminasTest\Dom\Document; +use Generator; use Laminas\Dom\Document\Query; use PHPUnit\Framework\TestCase; @@ -136,7 +137,7 @@ public function testShouldAllowMatchingOfAttributeValues() $this->assertEquals("//tag[@id='id']//@attribute", $test); } - public function descendantSelector() + public function descendantSelector(): Generator { yield 'space before' => ['child >leaf']; yield 'space after' => ['child> leaf']; @@ -186,7 +187,7 @@ public function testCanTransformWithAttributeAndDot() $this->assertEquals("//a[@href='http://example.com']", $test); } - public function nestedAttributeSelectors() + public function nestedAttributeSelectors(): array { return [ 'with-double-quotes' => [ @@ -211,7 +212,7 @@ public function nestedAttributeSelectors() /** * @dataProvider nestedAttributeSelectors */ - public function testTransformNestedAttributeSelectors($selector, $expectedXpath) + public function testTransformNestedAttributeSelectors(string $selector, string $expectedXpath) { $this->assertEquals($expectedXpath, Query::cssToXpath($selector)); } diff --git a/test/DocumentTest.php b/test/DocumentTest.php index 510f317..8f062c2 100644 --- a/test/DocumentTest.php +++ b/test/DocumentTest.php @@ -46,7 +46,7 @@ public function setUp(): void $this->document = new Document(); } - public function getHtml() + private function getHtml(): string { if (null === $this->html) { $this->html = file_get_contents(__DIR__ . '/_files/sample.xhtml'); @@ -54,14 +54,13 @@ public function getHtml() return $this->html; } - public function loadHtml() + private function loadHtml() { $this->document = new Document($this->getHtml()); } - public function handleError($msg, $code = 0) + public function handleError(string $msg, int $code = 0) { - $this->error = $msg; } public function testConstructorShouldNotRequireArguments()