Modifiable   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 36
c 2
b 0
f 0
dl 0
loc 114
rs 10
wmc 17

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A removeFromTrash() 0 6 2
A sendToTrash() 0 6 2
A addStar() 0 6 2
A markAsRead() 0 6 2
A markAsUnread() 0 6 2
A markAsNotImportant() 0 6 2
A markAsImportant() 0 6 2
A removeStar() 0 6 2
1
<?php
2
3
namespace Dacastro4\LaravelGmail\Traits;
4
5
use Dacastro4\LaravelGmail\Services\Message\Mail;
6
use Google_Service_Gmail;
7
8
/**
9
 * @property Google_Service_Gmail $service
10
 */
11
trait Modifiable
12
{
13
14
	use ModifiesLabels {
15
		ModifiesLabels::__construct as private __mlConstruct;
16
	}
17
18
	public function __construct()
19
	{
20
		/** @scrutinizer ignore-call */
21
		$this->__mlConstruct();
22
	}
23
24
	/**
25
	 * Marks emails as "READ". Returns string of message if fail
26
	 *
27
	 * @return Mail|string
28
	 */
29
	public function markAsRead()
30
	{
31
		try {
32
			return $this->removeLabel('UNREAD');
33
		} catch (\Exception $e) {
34
			return "Couldn't mark email as read: {$e->getMessage()}";
35
		}
36
	}
37
38
	/**
39
	 * Marks emails as unread
40
	 *
41
	 * @return Mail|string
42
	 * @throws \Exception
43
	 */
44
	public function markAsUnread()
45
	{
46
		try {
47
			return $this->addLabel('UNREAD');
48
		} catch (\Exception $e) {
49
			throw new \Exception("Couldn't mark email as unread: {$e->getMessage()}");
50
		}
51
	}
52
53
	/**
54
	 * @return Mail|string
55
	 * @throws \Exception
56
	 */
57
	public function markAsImportant()
58
	{
59
		try {
60
			return $this->addLabel('IMPORTANT');
61
		} catch (\Exception $e) {
62
			throw new \Exception("Couldn't remove mark email as important.: {$e->getMessage()}");
63
		}
64
	}
65
66
	/**
67
	 * @return Mail|string
68
	 * @throws \Exception
69
	 */
70
	public function markAsNotImportant()
71
	{
72
		try {
73
			return $this->removeLabel('IMPORTANT');
74
		} catch (\Exception $e) {
75
			throw new \Exception("Couldn't mark email as unread: {$e->getMessage()}");
76
		}
77
	}
78
79
	/**
80
	 * @return Mail|string
81
	 * @throws \Exception
82
	 */
83
	public function addStar()
84
	{
85
		try {
86
			return $this->addLabel('STARRED');
87
		} catch (\Exception $e) {
88
			throw new \Exception("Couldn't remove mark email as important.: {$e->getMessage()}");
89
		}
90
	}
91
92
	/**
93
	 * @return Mail|string
94
	 * @throws \Exception
95
	 */
96
	public function removeStar()
97
	{
98
		try {
99
			return $this->removeLabel('STARRED');
100
		} catch (\Exception $e) {
101
			throw new \Exception("Couldn't mark email as unread: {$e->getMessage()}");
102
		}
103
	}
104
105
	/**
106
	 * Send the email to the trash
107
	 *
108
	 * @return \Dacastro4\LaravelGmail\Services\Message\Mail|\Exception
109
	 */
110
	public function sendToTrash()
111
	{
112
		try {
113
			return $this->addLabel('TRASH');
114
		} catch (\Exception $e) {
115
			return new \Exception("Couldn't mark email as trash: {$e->getMessage()}");
116
		}
117
	}
118
119
	public function removeFromTrash()
120
	{
121
		try {
122
			return $this->removeLabel('TRASH');
123
		} catch (\Exception $e) {
124
			return new \Exception("Couldn't untrash the email: {$e->getMessage()}");
125
		}
126
	}
127
}
128