Completed
Push — master ( 2d3dcc...9dbdcf )
by Daniel
04:02
created

HasHeaders::getHeader()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 2
1
<?php
2
3
namespace Dacastro4\LaravelGmail\Traits;
4
5
use Google_Service_Gmail_MessagePartHeader;
6
7
trait HasHeaders
8
{
9
10
	/**
11
	 * Gets a single header from an existing email by name.
12
	 *
13
	 * @param $headerName
14
	 *
15
	 * @param string $regex if this is set, value will be evaluated with the give regular expression.
16
	 *
17
	 * @return null|string|array
18
	 */
19
	public function getHeader( $headerName, $regex = null )
20
	{
21
		$headers = $this->getHeaders();
0 ignored issues
show
Bug introduced by
The method getHeaders() does not exist on Dacastro4\LaravelGmail\Traits\HasHeaders. Did you maybe mean getHeader()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
22
23
		$value = null;
24
25
		/** @var Google_Service_Gmail_MessagePartHeader $header */
26
		foreach ( $headers as $header ) {
27
			if ( $header->getName() === $headerName ) {
28
				$value = $header->getValue();
29
				if ( ! is_null( $regex ) ) {
30
					preg_match_all( $regex, $header->getValue(), $value );
31
				}
32
				break;
33
			}
34
		}
35
36
		return $value;
37
	}
38
39
}