Skip to content

Commit 061d39a

Browse files
authored
Merge pull request #41 from GravityPDF/query-contract
Restore Interface Contract in DOM.php
2 parents 240194a + 86e4bc2 commit 061d39a

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

src/DOM.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,17 @@ abstract class DOM implements Query, IteratorAggregate, Countable
6565
*
6666
* @param mixed $document
6767
* A document-like object.
68-
* @param string $string
68+
* @param string|null $string
6969
* A CSS 3 Selector
7070
* @param array $options
7171
* An associative array of options.
7272
*
7373
* @throws Exception
7474
* @see qp()
7575
*/
76-
public function __construct($document = null, $string = '', $options = [])
76+
public function __construct($document = null, $string = null, $options = [])
7777
{
78-
// Backwards compatibility fix for PHP8+
79-
if (is_null($string)) {
80-
$string = '';
81-
}
82-
83-
$string = trim($string);
78+
$string = is_string($string) ? trim($string) : '';
8479
$this->options = $options + Options::get() + $this->options;
8580

8681
$parser_flags = $options['parser_flags'] ?? self::DEFAULT_PARSER_FLAGS;

src/QueryPath.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class QueryPath
189189
* @see qp()
190190
* @see htmlqp()
191191
*/
192-
public static function with($document = null, $selector = '', array $options = [])
192+
public static function with($document = null, $selector = null, array $options = [])
193193
{
194194
$qpClass = $options['QueryPath_class'] ?? '\QueryPath\DOMQuery';
195195

@@ -205,7 +205,7 @@ public static function with($document = null, $selector = '', array $options = [
205205
*
206206
* @see qp()
207207
*/
208-
public static function withXML($source = null, $selector = '', array $options = [])
208+
public static function withXML($source = null, $selector = null, array $options = [])
209209
{
210210
$options += [
211211
'use_parser' => 'xml',
@@ -223,7 +223,7 @@ public static function withXML($source = null, $selector = '', array $options =
223223
*
224224
* @see htmlqp()
225225
*/
226-
public static function withHTML($source = null, $selector = '', array $options = [])
226+
public static function withHTML($source = null, $selector = null, array $options = [])
227227
{
228228
// Need a way to force an HTML parse instead of an XML parse when the
229229
// doctype is XHTML, since many XHTML documents are not valid XML
@@ -273,7 +273,7 @@ public static function withHTML($source = null, $selector = '', array $options =
273273
*
274274
* @see html5qp()
275275
*/
276-
public static function withHTML5($source = null, $selector = '', array $options = [])
276+
public static function withHTML5($source = null, $selector = null, array $options = [])
277277
{
278278
$qpClass = $options['QueryPath_class'] ?? '\QueryPath\DOMQuery';
279279

src/qp_functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
* @return mixed|DOMQuery
156156
* Or possibly another QueryPath-like object if you overrode QueryPath_class.
157157
*/
158-
function qp($document = null, $string = '', array $options = [])
158+
function qp($document = null, $string = null, array $options = [])
159159
{
160160
return QueryPath::with($document, $string, $options);
161161
}
@@ -190,7 +190,7 @@ function qp($document = null, $string = '', array $options = [])
190190
* @return mixed|DOMQuery
191191
* @see qp()
192192
*/
193-
function htmlqp($document = null, $selector = '', array $options = [])
193+
function htmlqp($document = null, $selector = null, array $options = [])
194194
{
195195
return QueryPath::withHTML($document, $selector, $options);
196196
}
@@ -219,7 +219,7 @@ function htmlqp($document = null, $selector = '', array $options = [])
219219
*
220220
* @return mixed|DOMQuery
221221
*/
222-
function html5qp($document = null, $selector = '', array $options = [])
222+
function html5qp($document = null, $selector = null, array $options = [])
223223
{
224224
return QueryPath::withHTML5($document, $selector, $options);
225225
}

0 commit comments

Comments
 (0)