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   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 100
Duplicated Lines 18 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 13
c 4
b 0
f 2
lcom 1
cbo 1
dl 18
loc 100
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A __call() 0 4 1
A hasAttachments() 0 8 3
A bodyIsText() 9 9 2
A bodyIsHtml() 9 9 2
A attachments() 0 4 1
A setAttachments() 0 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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