Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Manual CS fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Filippo Tessarotto <zoeslam@gmail.com>
  • Loading branch information
Slamdunk committed Jan 11, 2021
1 parent ecd2d54 commit f87fd62
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/DOMXPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
13 changes: 7 additions & 6 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
/**#@-*/

/**
Expand Down Expand Up @@ -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('/<html[^>]*xmlns="([^"]+)"[^>]*>/i', $document, $matches)) {
$this->xpathNamespaces[] = $matches[1];
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -244,6 +244,7 @@ protected function setErrors($errors)
/**
* Get DOMDocument from set raw document
*
* @param string $stringDocument
* @return DOMDocument
* @throws Exception\RuntimeException
*/
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Document/NodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Document/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
/**#@-*/

/**
Expand Down Expand Up @@ -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 {
Expand All @@ -144,7 +144,7 @@ function ($matches) use ($placeholder) {
}
}

if (1 == count($paths)) {
if (1 === count($paths)) {
return $paths[0];
}
return implode('|', $paths);
Expand Down
4 changes: 2 additions & 2 deletions src/NodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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('/<html[^>]*xmlns="([^"]+)"[^>]*>/i', $document, $matches)) {
$this->xpathNamespaces[] = $matches[1];
return $this->setDocumentXhtml($document, $encoding);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions test/DOMXPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
7 changes: 4 additions & 3 deletions test/Document/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace LaminasTest\Dom\Document;

use Generator;
use Laminas\Dom\Document\Query;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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' => [
Expand All @@ -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));
}
Expand Down
7 changes: 3 additions & 4 deletions test/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,21 @@ 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');
}
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()
Expand Down

0 comments on commit f87fd62

Please sign in to comment.