Passed
Push — master ( 15c473...1ac4fd )
by Paul
06:19
created
plugin/Modules/Email.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
     /**
42 42
      * @return Email
43 43
      */
44
-    public function compose(array $email)
44
+    public function compose( array $email )
45 45
     {
46
-        $this->normalize($email);
46
+        $this->normalize( $email );
47 47
         $this->attachments = $this->email['attachments'];
48 48
         $this->headers = $this->buildHeaders();
49 49
         $this->message = $this->buildHtmlMessage();
50 50
         $this->subject = $this->email['subject'];
51 51
         $this->to = $this->email['to'];
52
-        add_action('phpmailer_init', [$this, 'buildPlainTextMessage']);
52
+        add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] );
53 53
         return $this;
54 54
     }
55 55
 
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
      * @param string $format
58 58
      * @return string|null
59 59
      */
60
-    public function read($format = '')
60
+    public function read( $format = '' )
61 61
     {
62
-        if ('plaintext' == $format) {
63
-            $message = $this->stripHtmlTags($this->message);
64
-            return apply_filters('site-reviews/email/message', $message, 'text', $this);
62
+        if( 'plaintext' == $format ) {
63
+            $message = $this->stripHtmlTags( $this->message );
64
+            return apply_filters( 'site-reviews/email/message', $message, 'text', $this );
65 65
         }
66 66
         return $this->message;
67 67
     }
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function send()
73 73
     {
74
-        if (!$this->message || !$this->subject || !$this->to) {
74
+        if( !$this->message || !$this->subject || !$this->to ) {
75 75
             return;
76 76
         }
77
-        add_action('wp_mail_failed', [$this, 'logMailError']);
77
+        add_action( 'wp_mail_failed', [$this, 'logMailError'] );
78 78
         $sent = wp_mail(
79 79
             $this->to,
80 80
             $this->subject,
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             $this->headers,
83 83
             $this->attachments
84 84
         );
85
-        remove_action('wp_mail_failed', [$this, 'logMailError']);
85
+        remove_action( 'wp_mail_failed', [$this, 'logMailError'] );
86 86
         $this->reset();
87 87
         return $sent;
88 88
     }
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
      * @return void
92 92
      * @action phpmailer_init
93 93
      */
94
-    public function buildPlainTextMessage($phpmailer)
94
+    public function buildPlainTextMessage( $phpmailer )
95 95
     {
96
-        if (empty($this->email)) {
96
+        if( empty($this->email) ) {
97 97
             return;
98 98
         }
99
-        if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) {
99
+        if( 'text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody) ) {
100 100
             return;
101 101
         }
102
-        $message = $this->stripHtmlTags($phpmailer->Body);
103
-        $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this);
102
+        $message = $this->stripHtmlTags( $phpmailer->Body );
103
+        $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this );
104 104
     }
105 105
 
106 106
     /**
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
         $allowed = [
112 112
             'bcc', 'cc', 'from', 'reply-to',
113 113
         ];
114
-        $headers = array_intersect_key($this->email, array_flip($allowed));
115
-        $headers = array_filter($headers);
116
-        foreach ($headers as $key => $value) {
114
+        $headers = array_intersect_key( $this->email, array_flip( $allowed ) );
115
+        $headers = array_filter( $headers );
116
+        foreach( $headers as $key => $value ) {
117 117
             unset($headers[$key]);
118 118
             $headers[] = $key.': '.$value;
119 119
         }
120 120
         $headers[] = 'Content-Type: text/html';
121
-        return apply_filters('site-reviews/email/headers', $headers, $this);
121
+        return apply_filters( 'site-reviews/email/headers', $headers, $this );
122 122
     }
123 123
 
124 124
     /**
@@ -126,54 +126,54 @@  discard block
 block discarded – undo
126 126
      */
127 127
     protected function buildHtmlMessage()
128 128
     {
129
-        $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message'));
130
-        if (!empty($template)) {
131
-            $message = glsr(Template::class)->interpolate(
129
+        $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) );
130
+        if( !empty($template) ) {
131
+            $message = glsr( Template::class )->interpolate(
132 132
                 $template, 
133 133
                 ['context' => $this->email['template-tags']], 
134 134
                 $this->email['template']
135 135
             );
136
-        } elseif ($this->email['template']) {
137
-            $message = glsr(Template::class)->build('templates/'.$this->email['template'], [
136
+        } elseif( $this->email['template'] ) {
137
+            $message = glsr( Template::class )->build( 'templates/'.$this->email['template'], [
138 138
                 'context' => $this->email['template-tags'],
139
-            ]);
139
+            ] );
140 140
         }
141
-        if (!isset($message)) {
141
+        if( !isset($message) ) {
142 142
             $message = $this->email['message'];
143 143
         }
144 144
         $message = $this->email['before'].$message.$this->email['after'];
145
-        $message = strip_shortcodes($message);
146
-        $message = wptexturize($message);
147
-        $message = wpautop($message);
148
-        $message = str_replace('<> ', '', $message);
149
-        $message = str_replace(']]>', ']]>', $message);
150
-        $message = glsr(Template::class)->build('partials/email/index', [
145
+        $message = strip_shortcodes( $message );
146
+        $message = wptexturize( $message );
147
+        $message = wpautop( $message );
148
+        $message = str_replace( '<> ', '', $message );
149
+        $message = str_replace( ']]>', ']]>', $message );
150
+        $message = glsr( Template::class )->build( 'partials/email/index', [
151 151
             'context' => ['message' => $message],
152
-        ]);
153
-        return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this);
152
+        ] );
153
+        return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this );
154 154
     }
155 155
 
156 156
     /**
157 157
      * @param \WP_Error $error
158 158
      * @return void
159 159
      */
160
-    protected function logMailError($error)
160
+    protected function logMailError( $error )
161 161
     {
162
-        glsr_log()->error('Email was not sent (wp_mail failed)')
163
-            ->debug($this)
164
-            ->debug($error);
162
+        glsr_log()->error( 'Email was not sent (wp_mail failed)' )
163
+            ->debug( $this )
164
+            ->debug( $error );
165 165
     }
166 166
 
167 167
     /**
168 168
      * @return void
169 169
      */
170
-    protected function normalize(array $email = [])
170
+    protected function normalize( array $email = [] )
171 171
     {
172
-        $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email);
173
-        if (empty($email['reply-to'])) {
172
+        $email = shortcode_atts( glsr( EmailDefaults::class )->defaults(), $email );
173
+        if( empty($email['reply-to']) ) {
174 174
             $email['reply-to'] = $email['from'];
175 175
         }
176
-        $this->email = apply_filters('site-reviews/email/compose', $email, $this);
176
+        $this->email = apply_filters( 'site-reviews/email/compose', $email, $this );
177 177
     }
178 178
 
179 179
     /**
@@ -192,21 +192,21 @@  discard block
 block discarded – undo
192 192
     /**
193 193
      * @return string
194 194
      */
195
-    protected function stripHtmlTags($string)
195
+    protected function stripHtmlTags( $string )
196 196
     {
197 197
         // remove invisible elements
198
-        $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string);
198
+        $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string );
199 199
         // replace certain elements with a line-break
200
-        $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string);
200
+        $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string );
201 201
         // replace other elements with a space
202
-        $string = preg_replace('@</(td|th)@iu', ' $0', $string);
202
+        $string = preg_replace( '@</(td|th)@iu', ' $0', $string );
203 203
         // add a placeholder for plain-text bullets to list elements
204
-        $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string);
204
+        $string = preg_replace( '@<(li)[^>]*?>@siu', '$0-o-^-o-', $string );
205 205
         // strip all remaining HTML tags
206
-        $string = wp_strip_all_tags($string);
207
-        $string = wp_specialchars_decode($string, ENT_QUOTES);
208
-        $string = preg_replace('/\v(?:[\v\h]+){2,}/u', "\r\n\r\n", $string);
209
-        $string = str_replace('-o-^-o-', ' - ', $string);
210
-        return html_entity_decode($string, ENT_QUOTES, 'UTF-8');
206
+        $string = wp_strip_all_tags( $string );
207
+        $string = wp_specialchars_decode( $string, ENT_QUOTES );
208
+        $string = preg_replace( '/\v(?:[\v\h]+){2,}/u', "\r\n\r\n", $string );
209
+        $string = str_replace( '-o-^-o-', ' - ', $string );
210
+        return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
211 211
     }
212 212
 }
Please login to merge, or discard this patch.