Skip to content

Commit 976a4d0

Browse files
committed
Fixed coding style and some other things.
1 parent ed7b5b6 commit 976a4d0

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

MailLibrary/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function isConnected()
3535

3636
/**
3737
* Connects to the server
38+
* @return Connection
3839
* @throws ConnectionException
3940
*/
4041
public function connect()
@@ -47,6 +48,7 @@ public function connect()
4748
throw new ConnectionException("Cannot connect to server.", $e->getCode(), $e);
4849
}
4950
}
51+
return $this;
5052
}
5153

5254
/**
@@ -59,12 +61,14 @@ public function getDriver()
5961

6062
/**
6163
* Flushes changes to server
64+
* @return Connection
6265
* @throws DriverException
6366
*/
6467
public function flush()
6568
{
6669
$this->connected || $this->connect();
6770
$this->driver->flush();
71+
return $this;
6872
}
6973

7074
/**

MailLibrary/Contact.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<?php
22
/**
33
* @author Martin Pecha
4+
* @author Tomáš Blatný
45
*/
56

67
namespace greeny\MailLibrary;
78

8-
/**
9-
* Class Contact
10-
* @package greeny\MailLibrary
11-
*/
12-
class Contact {
13-
14-
/** @var string */
9+
class Contact
10+
{
11+
/** @var string */
1512
private $mailbox;
16-
/** @var string */
13+
/** @var string */
1714
private $host;
18-
/** @var string */
15+
/** @var string */
1916
private $personal;
20-
/** @var string */
17+
/** @var string */
2118
private $adl;
2219

2320
/**
@@ -26,7 +23,8 @@ class Contact {
2623
* @param $personal
2724
* @param $adl
2825
*/
29-
public function __construct($mailbox=NULL, $host=NULL, $personal=NULL, $adl=NULL) {
26+
public function __construct($mailbox = NULL, $host = NULL, $personal = NULL, $adl = NULL)
27+
{
3028
$this->mailbox = $mailbox;
3129
$this->host = $host;
3230
$this->personal = $personal;
@@ -36,7 +34,8 @@ public function __construct($mailbox=NULL, $host=NULL, $personal=NULL, $adl=NULL
3634
/**
3735
* @return string
3836
*/
39-
public function __toString() {
37+
public function __toString()
38+
{
4039
$address = $this->getName() ? "\"" . $this->getName(). "\" " : "";
4140
$address .= $this->getAdl() ? $this->getAdl().":" : "";
4241
$address .= "<".$this->getEmail().">";
@@ -46,21 +45,24 @@ public function __toString() {
4645
/**
4746
* @return string
4847
*/
49-
public function getEmail() {
48+
public function getEmail()
49+
{
5050
return $this->mailbox."@".$this->host;
5151
}
5252

5353
/**
5454
* @return string
5555
*/
56-
public function getName() {
56+
public function getName()
57+
{
5758
return $this->personal;
5859
}
5960

6061
/**
6162
* @return string
6263
*/
63-
public function getAdl() {
64+
public function getAdl()
65+
{
6466
return $this->adl;
6567
}
6668

MailLibrary/ContactList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Iterator;
99
use Countable;
1010

11-
class ContactList implements Iterator, Countable{
11+
class ContactList implements Iterator, Countable
12+
{
13+
/** @var Contact[] */
1214
protected $contacts;
1315

1416
protected $builtContacts;
@@ -21,7 +23,6 @@ public function addContact($mailbox = NULL, $host = NULL, $personal = NULL, $adl
2123
public function build()
2224
{
2325
$return = array();
24-
/** @var Contact $contact */
2526
foreach($this->contacts as $contact) {
2627
$return[] = $contact->__toString();
2728
}
@@ -80,4 +81,3 @@ public function count()
8081
return count($this->builtContacts);
8182
}
8283
}
83-

MailLibrary/Mail.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,20 @@ public function __construct(Connection $connection, Mailbox $mailbox, $id)
6969
$this->id = $id;
7070
}
7171

72+
/**
73+
* Header checker
74+
*
75+
* @param $name
76+
* @return bool
77+
*/
7278
public function __isset($name)
7379
{
7480
$this->headers !== NULL || $this->initializeHeaders();
7581
return isset($this->headers[$this->formatHeaderName($name)]);
7682
}
7783

7884
/**
79-
* Gets header
85+
* Header getter
8086
*
8187
* @param string $name
8288
* @return mixed
@@ -121,6 +127,19 @@ public function getHeader($name)
121127
return $this->headers[$this->formatHeaderName($name)];
122128
}
123129

130+
/**
131+
* @return Contact|null
132+
*/
133+
public function getSender() {
134+
$from = $this->getHeader('from');
135+
if($from) {
136+
$contacts = $from->getContactsObjects();
137+
return (count($contacts) ? $contacts[0] : NULL);
138+
} else {
139+
return NULL;
140+
}
141+
}
142+
124143
/**
125144
* @return string
126145
*/
@@ -203,14 +222,6 @@ public function delete()
203222
$this->connection->getDriver()->deleteMail($this->id);
204223
}
205224

206-
/**
207-
* @return Contact|null
208-
*/
209-
public function getSender() {
210-
$contacts = $this->from->getContactsObjects();
211-
return (!empty($contacts[0]) ? $contacts[0] : null);
212-
}
213-
214225
/**
215226
* Initializes headers
216227
*/
@@ -248,4 +259,3 @@ protected function formatHeaderName($name)
248259
}, $name));
249260
}
250261
}
251-

0 commit comments

Comments
 (0)