Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 54e6b58

Browse files
committed
cleaning code
1 parent 1da6c3b commit 54e6b58

File tree

4 files changed

+56
-31
lines changed

4 files changed

+56
-31
lines changed

lib/Postmark/Attachment.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44

55
Class Attachment extends \Postmark\Inbound {
66

7-
public function __construct($attachment) {
7+
public function __construct($attachment)
8+
{
89
$this->Attachment = $attachment;
910
$this->Name = $this->Attachment->Name;
1011
$this->ContentType = $this->Attachment->ContentType;
1112
$this->ContentLength = $this->Attachment->ContentLength;
1213
$this->Content = $this->Attachment->Content;
1314
}
1415

15-
private function _read() {
16+
private function _read()
17+
{
1618
return base64_decode(chunk_split($this->Attachment->Content));
1719
}
1820

19-
public function Download($directory) {
21+
public function Download($directory)
22+
{
2023
file_put_contents($directory . $this->Name, $this->_read());
2124
}
2225
}

lib/Postmark/Attachments.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,49 @@
22

33
namespace Postmark;
44

5-
Class Attachments extends \Postmark\Inbound implements \Iterator{
5+
Class Attachments extends \Postmark\Inbound implements \Iterator {
66

7-
public function __construct($attachments) {
7+
public function __construct($attachments)
8+
{
89
$this->attachments = $attachments;
910
$this->position = 0;
1011
}
1112

1213
function get($key) {
1314
$this->position = $key;
1415

15-
if( ! empty($this->attachments[$key])) {
16+
if( ! empty($this->attachments[$key]))
17+
{
1618
return new Attachment($this->attachments[$key]);
17-
} else {
19+
}
20+
else
21+
{
1822
return FALSE;
1923
}
2024
}
2125

22-
function rewind() {
26+
function rewind()
27+
{
2328
$this->position = 0;
2429
}
2530

26-
function current() {
31+
function current()
32+
{
2733
return new Attachment($this->attachments[$this->position]);
2834
}
2935

30-
function key() {
36+
function key()
37+
{
3138
return $this->position;
3239
}
3340

34-
function next() {
41+
function next()
42+
{
3543
++$this->position;
3644
}
3745

38-
function valid() {
46+
function valid()
47+
{
3948
return isset($this->attachments[$this->position]);
4049
}
4150

lib/Postmark/Autoloader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ static public function register()
1212

1313
static public function autoload($class)
1414
{
15-
if (0 !== strpos($class, 'Postmark\Inbound')) {
15+
if (0 !== strpos($class, 'Postmark\Inbound'))
16+
{
1617
return;
1718
}
1819

19-
if (file_exists($file = dirname(__FILE__) . '/' . str_replace('Postmark/', '', preg_replace("{\\\}", "/",($class))) . '.php')) {
20+
if (file_exists($file = dirname(__FILE__) . '/' . str_replace('Postmark/', '', preg_replace("{\\\}", "/",($class))) . '.php'))
21+
{
2022
require $file;
2123
}
2224
}

lib/Postmark/Inbound.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Postmark;
34

45
include('Exception.php');
@@ -22,7 +23,8 @@ class Inbound {
2223

2324
public function __construct($Json = FALSE)
2425
{
25-
if(empty($Json)) {
26+
if(empty($Json))
27+
{
2628
throw new InboundException('Posmark Inbound Error: you must provide a Json Source');
2729
}
2830

@@ -34,7 +36,8 @@ private function _jsonToArray()
3436
{
3537
$Source = Json_decode($this->Json, FALSE);
3638

37-
switch (json_last_error()) {
39+
switch (json_last_error())
40+
{
3841
case JSON_ERROR_NONE:
3942
return $Source;
4043
break;
@@ -64,16 +67,21 @@ public function FromName()
6467
return $this->Source->FromFull->Name;
6568
}
6669

67-
public function Headers($name = 'X-Spam-Status') {
68-
foreach($this->Source->Headers as $header) {
69-
if(isset($header->Name) AND $header->Name == $name) {
70-
if($header->Name == 'Received-SPF') {
70+
public function Headers($name = 'X-Spam-Status')
71+
{
72+
foreach($this->Source->Headers as $header)
73+
{
74+
if(isset($header->Name) AND $header->Name == $name)
75+
{
76+
if($header->Name == 'Received-SPF')
77+
{
7178
return self::_parseReceivedSpf($header->Value);
7279
}
7380

7481
return $header->Value;
7582
}
76-
else {
83+
else
84+
{
7785
unset($header);
7886
}
7987
}
@@ -89,40 +97,43 @@ private static function _parseReceivedSpf($header)
8997

9098
public function Recipients()
9199
{
92-
return self::_parseRecipientsAndUndisclosedRecipients($this->Source->ToFull);
100+
return self::_parseRecipients($this->Source->ToFull);
93101
}
94102

95103
public function UndisclosedRecipients()
96104
{
97-
return self::_parseRecipientsAndUndisclosedRecipients($this->Source->CcFull);
105+
return self::_parseRecipients($this->Source->CcFull);
98106
}
99107

100-
private static function _parseRecipientsAndUndisclosedRecipients($recipients)
108+
private static function _parseRecipients($recipients)
101109
{
102-
$objects = array_map(function ($object) {
110+
$objects = array_map(function ($object)
111+
{
103112
$object = get_object_vars($object);
104113

105-
if( ! empty($object['Name'])) {
114+
if( ! empty($object['Name']))
115+
{
106116
$object['Name'] = $object['Name'];
107117
}
108-
else {
118+
else
119+
{
109120
$object['Name'] = FALSE;
110121
}
111122

112-
$object['Email'] = $object['Email'];
113-
114123
return (object)$object;
115124

116125
}, $recipients);
117126

118127
return $objects;
119128
}
120129

121-
public function Attachments() {
130+
public function Attachments()
131+
{
122132
return new Attachments($this->Source->Attachments);
123133
}
124134

125-
public function HasAttachments() {
135+
public function HasAttachments()
136+
{
126137
return count($this->Source->Attachments) > 0 ? TRUE : FALSE;
127138
}
128139

0 commit comments

Comments
 (0)