Skip to content

Commit abd39ab

Browse files
committed
Remove everything other than __set from MagicMethodTraits
1 parent 4b6dc2d commit abd39ab

2 files changed

Lines changed: 12 additions & 98 deletions

File tree

src/API/MagicMethodsTrait.php

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,6 @@
1212

1313
trait MagicMethodsTrait
1414
{
15-
public function __call($name, $arguments)
16-
{
17-
$callTypeIndex = 3;
18-
if (substr($name, 0, 2) == "is") {
19-
$callTypeIndex = 2;
20-
}
21-
22-
$callType = substr($name, 0, $callTypeIndex);
23-
$propertyName = substr($name, $callTypeIndex);
24-
25-
if (in_array($callType, array('get', 'is')) && count($arguments) == 0) {
26-
return $this->{$callType}($propertyName);
27-
}
28-
29-
if (in_array($callType, array('add', 'set')) && count($arguments) == 1) {
30-
return $this->{$callType}($propertyName, $arguments[0]);
31-
}
32-
33-
throw new \Exception("The method you tried to call doesn't exist");
34-
}
35-
3615
public function __set($name, $value)
3716
{
3817
if (is_object($value) && !($value instanceof Type) && property_exists($value, "Entry")) {
@@ -60,75 +39,4 @@ public function methodExists($name)
6039
{
6140
return method_exists($this, $name);
6241
}
63-
64-
public function get($name)
65-
{
66-
$name = $this->getValidNameInCorrectCase([$name, "get$name"]);
67-
return $this->$name;
68-
}
69-
70-
public function set($name, $value)
71-
{
72-
$name = $this->getNameInCorrectCase($name);
73-
74-
$this->$name = $value;
75-
76-
return $this;
77-
}
78-
79-
public function add($name, $value)
80-
{
81-
$name = $this->getNameInCorrectCase($name);
82-
83-
if ($this->$name == null) {
84-
$this->$name = array();
85-
}
86-
87-
if (!is_array($this->$name)) {
88-
$this->$name = array($this->$name);
89-
}
90-
91-
$this->{$name}[] = $value;
92-
93-
return $this;
94-
}
95-
96-
public function is($name)
97-
{
98-
$nameWithIs = "Is$name";
99-
$name = $this->getValidNameInCorrectCase([$nameWithIs, $name]);
100-
101-
return ((bool) $this->$name);
102-
}
103-
104-
protected function getValidNameInCorrectCase($names)
105-
{
106-
foreach ($names as $name) {
107-
try {
108-
return $this->getNameInCorrectCase($name);
109-
} catch (\Exception $e) {
110-
//Nothing needed here. If everything errors out, we'll throw a new exception below
111-
}
112-
}
113-
114-
throw new \Exception('Property ' . $names[0] . ' does not exist');
115-
}
116-
117-
/**
118-
* @param $name
119-
* @return string
120-
* @throws \Exception
121-
*/
122-
protected function getNameInCorrectCase($name)
123-
{
124-
if (!$this->exists($name) && $this->exists(lcfirst($name))) {
125-
$name = lcfirst($name);
126-
}
127-
128-
if (!$this->exists($name)) {
129-
throw new \Exception('Property ' . $name . ' does not exist');
130-
}
131-
132-
return $name;
133-
}
13442
}

src/API/Type/MessageType.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public function setBody($body)
112112
$body = new BodyType($body);
113113
}
114114

115-
return parent::setBody($body);
115+
$this->body = $body;
116+
return $this;
116117
}
117118

118119
/**
@@ -121,27 +122,32 @@ public function setBody($body)
121122
*/
122123
public function setFrom($from)
123124
{
124-
return parent::setFrom(new SingleRecipientType(ensureIsMailbox($from)));
125+
$this->from = new SingleRecipientType(ensureIsMailbox($from));
126+
return $this;
125127
}
126128

127129
public function addToRecipients($recipient)
128130
{
129-
return parent::addToRecipients(ensureIsMailbox($recipient));
131+
$this->toRecipients[] = ensureIsMailbox($recipient);
132+
return $this;
130133
}
131134

132135
public function addCcRecipients($recipient)
133136
{
134-
return parent::addCcRecipients(ensureIsMailbox($recipient));
137+
$this->ccRecipients[] = ensureIsMailbox($recipient);
138+
return $this;
135139
}
136140

137141
public function addBccRecipients($recipient)
138142
{
139-
return parent::addBccRecipients(ensureIsMailbox($recipient));
143+
$this->bccRecipients[] = ensureIsMailbox($recipient);
144+
return $this;
140145
}
141146

142147
public function addReplyTo($recipient)
143148
{
144-
return parent::addReplyTo(ensureIsMailbox($recipient));
149+
$this->replyTo[] = ensureIsMailbox($recipient);
150+
return $this;
145151
}
146152

147153
public function setToRecipients($recipients)

0 commit comments

Comments
 (0)