EmailWithLinkMatcher   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A matches() 0 8 2
A __toString() 0 9 2
1
<?php
2
/**
3
 * Defines Ingenerator\Mailhook\Matcher\EmailWithLinkMatcher
4
 *
5
 * @copyright  2014 inGenerator Ltd
6
 * @licence    BSD
7
 */
8
9
namespace Ingenerator\Mailhook\Matcher;
10
use Ingenerator\Mailhook\Email;
11
use Ingenerator\Mailhook\EmailMatcher;
12
13
/**
14
 * Matches an email containing a link - optionally with a particular URL pattern
15
 *
16
 * @package Ingenerator\Mailhook\Matcher
17
 * @see     spec\Ingenerator\Mailhook\Matcher\EmailWithLinkMatcherSpec
18
 */
19
class EmailWithLinkMatcher implements EmailMatcher {
20
21
	/**
22
	 * @var string
23
	 */
24
	protected $url_pattern;
25
26
	/**
27
	 * @param string $url_pattern
0 ignored issues
show
Documentation introduced by
Should the type for parameter $url_pattern not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
28
	 */
29
	public function __construct($url_pattern = NULL)
30
	{
31
		$this->url_pattern = $url_pattern;
32
	}
33
34
	/**
35
	 * {@inheritdoc}
36
	 */
37
	public function matches(Email $email)
38
	{
39
		if ($this->url_pattern) {
40
			return (bool) $email->getLinksMatching($this->url_pattern);
41
		} else {
42
			return (bool) $email->getLinks();
43
		}
44
	}
45
46
	/**
47
	 * {@inheritdoc}
48
	 */
49
	public function __toString()
50
	{
51
		if ($this->url_pattern)
52
		{
53
			return \sprintf('With link matching "%s"', $this->url_pattern);
54
		} else {
55
			return 'With any link';
56
		}
57
	}
58
59
}
60