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

HasHeaders   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getHeader() 0 19 4
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
}