Driver_Simple_Xpath   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 26
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A find() 0 16 5
1
<?php
2
3
namespace Openbuildings\Spiderling;
4
5
/**
6
 * Xpath extension for simple driver
7
 *
8
 * @package    Openbuildings\Spiderling
9
 * @author     Ivan Kerin
10
 * @copyright  (c) 2013 OpenBuildings Ltd.
11
 * @license    http://spdx.org/licenses/BSD-3-Clause
12
 */
13
class Driver_Simple_Xpath extends \DOMXpath
14
{
15
	/**
16
	 * Find a DOMElement wit ha given xpath expression, optionally provide parent DOMNode to use as context.
17
	 * @param  string $expression
18
	 * @param  DOMNode $contextnode
19
	 * @return DOMNode
20
	 * @throws Exception_Xpath If no elements were found
21
	 */
22 15
	public function find($expression, $contextnode = NULL)
23
	{
24 15
		if ($expression instanceof \DOMNode)
25 4
			return $expression;
26
27 15
		@ $items = $contextnode ? $this->query($expression, $contextnode) : $this->query($expression);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
28
29 15
		if ( ! $items)
30
			throw new Exception_Xpath('Error in expression: ":expression"', array(':expression' => $expression));
31
32 15
		if ($items->length == 0)
33 1
			throw new Exception_Xpath('No element for selector ":expression"', array(':expression' => $expression));
34
35 15
		return $items->item(0);
36
37
	}
38
}
39