Completed
Push — update ( 3c072c...67888e )
by Haralan
06:13
created

NegativeLocatorConstraint   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A matches() 0 12 2
B failureDescription() 0 22 4
A toString() 0 4 1
1
<?php
2
3
namespace Openbuildings\PHPUnitSpiderling\Constraint;
4
5
use Openbuildings\Spiderling\Exception_Found;
6
7
class NegativeLocatorConstraint extends \PHPUnit\Framework\Constraint\Constraint {
8
9
	protected $_type;
10
	protected $_selector;
11
	protected $_filters;
12
13
	function __construct($type, $selector, array $filters = array())
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
	{
15
		$this->_type = $type;
16
		$this->_selector = $selector;
17
		$this->_filters = $filters;
18
	}
19
20
	protected function matches($other)
21
	{
22
		try
23
		{
24
			$other->not_present(array($this->_type, $this->_selector, $this->_filters));
25
			return TRUE;
26
		}
27
		catch (Exception_Found $excption)
28
		{
29
			return FALSE;
30
		}
31
	}
32
33
	public function failureDescription($other)
34
	{
35
		if ($other->is_root())
36
		{
37
			$node_string = 'HTML page';
38
		}
39
		else
40
		{
41
			$node_string = $other->tag_name();
42
43
			if ($id = $other->attribute('id'))
44
			{
45
				$node_string .= '#'.$id;
46
			}
47
48
			if ($class = $other->attribute('class'))
49
			{
50
				$node_string .= '.'.join('.', explode(' ', $class));
51
			}
52
		}
53
		return "$node_string ".$this->toString();
54
	}
55
56
	/**
57
	 * Returns a string representation of the constraint.
58
	 *
59
	 * @return string
60
	 */
61
	public function toString()
62
	{
63
		return "does not have '{$this->_type}' selector '{$this->_selector}', filter ".json_encode($this->_filters);
64
	}
65
}
66