Passed
Pull Request — master (#140)
by
unknown
04:07 queued 01:40
created

HasHeaders   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A getHeader() 0 21 6
1
<?php
2
3
namespace Ddomanskyi\LaravelGmail\Traits;
4
5
trait HasHeaders
6
{
7
8
	/**
9
	 * Gets a single header from an existing email by name.
10
	 *
11
	 * @param $headerName
12
	 *
13
	 * @param  string  $regex  if this is set, value will be evaluated with the give regular expression.
14
	 *
15
	 * @return null|string
16
	 */
17
	public function getHeader($headerName, $regex = null)
18
	{
19
		$headers = $this->getHeaders();
20
21
		$value = null;
22
23
		foreach ($headers as $header) {
24
			if ($header->key === $headerName) {
25
				$value = $header->value;
26
				if (!is_null($regex)) {
27
					preg_match_all($regex, $header->value, $value);
28
				}
29
				break;
30
			}
31
		}
32
33
		if (is_array($value)) {
34
			return isset($value[1]) ? $value[1] : null;
35
		}
36
37
		return $value;
38
	}
39
40
	public abstract function getHeaders();
41
42
}
43