Passed
Push — master ( ddf050...67acca )
by Daniel
01:53
created

HasHeaders::getHeader()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 12
nop 2
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
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
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()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
		/** @scrutinizer ignore-call */ 
22
  $headers = $this->getHeaders();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
23
		$value = null;
24
25
		foreach ( $headers as $header ) {
26
			if ( $header->key === $headerName ) {
27
				$value = $header->value;
28
				if ( ! is_null( $regex ) ) {
29
					preg_match_all( $regex, $header->value, $value );
30
				}
31
				break;
32
			}
33
		}
34
35
		if ( is_array( $value ) ) {
36
			return isset( $value[ 1 ] ) ? $value[ 1 ] : null;
37
		}
38
39
		return $value;
40
	}
41
42
}