GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Email::hasAttachments()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 3
nop 0
1
<?php namespace Camelcased\Postmark\Inbound;
2
3
use Camelcased\Postmark\Inbound\Attachment as Attachment;
4
5
class Email {
6
	/**
7
	 * @var array
8
	 */
9
	protected $data;
10
11
	/**
12
	 * @var array
13
	 */
14
	protected $attachments = [];
15
16
	public function __construct(array $data)
17
	{
18
		$this->data = $data;
19
20
		// Does the email contain attachments?
21
		if ($this->hasAttachments())
22
		{
23
			// Then setup the array with Attachment objects
24
			$this->setAttachments();
25
		}
26
	}
27
28
	/**
29
	 * Maps undefined functions to the correct field in the email
30
	 *
31
	 * @return mixed
32
	 */
33
	public function __call($name, $arguments)
34
	{
35
		return $this->data[$name];
36
	}
37
38
	/**
39
	 * Check for if the email has any attachments
40
	 *
41
	 * @return boolean
42
	 */
43
	public function hasAttachments()
44
	{
45
		if (array_key_exists('Attachments', $this->data)) {
46
			return count($this->data["Attachments"]) > 0 ? true : false;
47
		}
48
49
		return false;
50
	}
51
52
	/**
53
	 * Is the body in the email plain text?
54
	 *
55
	 * @return boolean
56
	 */
57 View Code Duplication
	public function bodyIsText()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
	{
59
		if ($this->data['body'] == strip_tags($this->data['body']))
60
		{
61
			return true;
62
		}
63
64
		return false;
65
	}
66
67
	/**
68
	 * Is the body in the email HTML?
69
	 *
70
	 * @return boolean
71
	 */
72 View Code Duplication
	public function bodyIsHtml()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
	{
74
		if ($this->data['body'] != strip_tags($this->data['body']))
75
		{
76
			return true;
77
		}
78
79
		return false;
80
	}
81
82
	/**
83
	 * Return the array of Attachment objects
84
	 *
85
	 * @return array
86
	 */
87
	public function attachments()
88
	{
89
		return $this->attachments;
90
	}
91
92
	/**
93
	 * Loops through the attachments and creates an Attachment object for each attachemnt then pushes each object into an array.
94
	 *
95
	 * @return void
96
	 */
97
	private function setAttachments()
98
	{
99
		foreach ($this->data['Attachments'] as $attachment)
100
		{
101
			array_push($this->attachments, new Attachment($attachment));
102
		}
103
	}
104
}
105