EmailAssertionFailedException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A describeMatchers() 0 10 2
1
<?php
2
/**
3
 * Thrown when an email assertion does not match
4
 *
5
 * @author    Andrew Coulton <[email protected]>
6
 * @copyright 2014 inGenerator Ltd
7
 * @licence   BSD
8
 */
9
10
namespace Ingenerator\Mailhook;
11
12
/**
13
 * Thrown when an assertion fails
14
 *
15
 * @package Ingenerator\Mailhook
16
 */
17
class EmailAssertionFailedException extends \Exception {
18
19
	/**
20
	 * @param string         $message
21
	 * @param EmailMatcher[] $matchers
22
	 */
23
	public function __construct($message, $matchers)
24
	{
25
		$message .= $this->describeMatchers($matchers);
26
		parent::__construct($message);
27
	}
28
29
	/**
30
	 * @param EmailMatcher[] $matchers
31
	 *
32
	 * @return string
33
	 */
34
	protected function describeMatchers($matchers)
35
	{
36
		$message = "\nMatchers: ";
37
		if ( ! $matchers)
0 ignored issues
show
Bug Best Practice introduced by
The expression $matchers of type Ingenerator\Mailhook\EmailMatcher[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
38
		{
39
			$matchers = array('none');
40
		}
41
42
		return $message.\implode(', ', $matchers);
43
	}
44
45
}
46