Passed
Push — develop ( bdf49e...53bd5d )
by Paul
12:20
created
src/Helpers/Development.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
     protected $utility;
10 10
 
11
-    public function __construct(Utility $utility)
11
+    public function __construct( Utility $utility )
12 12
     {
13 13
         $this->utility = $utility;
14 14
     }
@@ -16,23 +16,23 @@  discard block
 block discarded – undo
16 16
     public function capture()
17 17
     {
18 18
         ob_start();
19
-        call_user_func_array([$this, 'printF'], func_get_args());
19
+        call_user_func_array( [$this, 'printF'], func_get_args() );
20 20
         return ob_get_clean();
21 21
     }
22 22
 
23
-    public function className($override = 'dev')
23
+    public function className( $override = 'dev' )
24 24
     {
25 25
         return $this->isDev() ? $override : '';
26 26
     }
27 27
 
28 28
     public function debug()
29 29
     {
30
-        call_user_func_array([$this, 'printF'], func_get_args());
30
+        call_user_func_array( [$this, 'printF'], func_get_args() );
31 31
     }
32 32
 
33 33
     public function isDev()
34 34
     {
35
-        return defined('DEV') && (bool) DEV && WP_ENV == 'development';
35
+        return defined( 'DEV' ) && (bool) DEV && WP_ENV == 'development';
36 36
     }
37 37
 
38 38
     public function isProduction()
@@ -40,24 +40,24 @@  discard block
 block discarded – undo
40 40
         return WP_ENV == 'production';
41 41
     }
42 42
 
43
-    public function printFiltersFor($hook = '')
43
+    public function printFiltersFor( $hook = '' )
44 44
     {
45 45
         global $wp_filter;
46
-        if (empty($hook) || !isset($wp_filter[$hook])) {
46
+        if( empty( $hook ) || !isset( $wp_filter[$hook] ) ) {
47 47
             return;
48 48
         }
49
-        $this->printF($wp_filter[$hook]);
49
+        $this->printF( $wp_filter[$hook] );
50 50
     }
51 51
 
52 52
     public function printTemplatePaths()
53 53
     {
54
-        $this->printF(implode("\n", $this->templatePaths()));
54
+        $this->printF( implode( "\n", $this->templatePaths() ) );
55 55
     }
56 56
 
57
-    public function storeTemplatePath($template)
57
+    public function storeTemplatePath( $template )
58 58
     {
59
-        if (is_string($template)) {
60
-            $this->templatePaths[] = $this->utility->trimLeft($template, trailingslashit(WP_CONTENT_DIR));
59
+        if( is_string( $template ) ) {
60
+            $this->templatePaths[] = $this->utility->trimLeft( $template, trailingslashit( WP_CONTENT_DIR ) );
61 61
         }
62 62
     }
63 63
 
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
     {
66 66
         $args = func_num_args();
67 67
 
68
-        if (1 == $args) {
69
-            printf('<div class="print__r"><pre>%s</pre></div>',
70
-                htmlspecialchars(print_r(func_get_arg(0), true), ENT_QUOTES, 'UTF-8')
68
+        if( 1 == $args ) {
69
+            printf( '<div class="print__r"><pre>%s</pre></div>',
70
+                htmlspecialchars( print_r( func_get_arg( 0 ), true ), ENT_QUOTES, 'UTF-8' )
71 71
             );
72
-        } elseif ($args > 1) {
72
+        } elseif( $args > 1 ) {
73 73
             echo '<div class="print__r_group">';
74
-            foreach (func_get_args() as $value) {
75
-                $this->printF($value);
74
+            foreach( func_get_args() as $value ) {
75
+                $this->printF( $value );
76 76
             }
77 77
             echo '</div>';
78 78
         }
Please login to merge, or discard this patch.
src/Services/Email.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     protected $to;
38 38
 
39
-    public function __construct(Template $template)
39
+    public function __construct( Template $template )
40 40
     {
41 41
         $this->template = $template;
42 42
     }
@@ -44,21 +44,21 @@  discard block
 block discarded – undo
44 44
     /**
45 45
      * @return Email
46 46
      */
47
-    public function compose(array $email)
47
+    public function compose( array $email )
48 48
     {
49
-        $email = $this->normalize($email);
49
+        $email = $this->normalize( $email );
50 50
 
51 51
         $this->attachments = $email['attachments'];
52
-        $this->headers = $this->buildHeaders($email);
53
-        $this->message = $this->buildHtmlMessage($email);
52
+        $this->headers = $this->buildHeaders( $email );
53
+        $this->message = $this->buildHtmlMessage( $email );
54 54
         $this->subject = $email['subject'];
55 55
         $this->to = $email['to'];
56 56
 
57
-        add_action('phpmailer_init', function ($phpmailer) {
58
-            if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) {
57
+        add_action( 'phpmailer_init', function( $phpmailer ) {
58
+            if( 'text/plain' === $phpmailer->ContentType || !empty( $phpmailer->AltBody ) ) {
59 59
                 return;
60 60
             }
61
-            $phpmailer->AltBody = $this->buildPlainTextMessage($phpmailer->Body);
61
+            $phpmailer->AltBody = $this->buildPlainTextMessage( $phpmailer->Body );
62 62
         });
63 63
 
64 64
         return $this;
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
      *
70 70
      * @return string|null
71 71
      */
72
-    public function read($plaintext = false)
72
+    public function read( $plaintext = false )
73 73
     {
74 74
         return $plaintext
75
-            ? $this->buildPlainTextMessage($this->message)
75
+            ? $this->buildPlainTextMessage( $this->message )
76 76
             : $this->message;
77 77
     }
78 78
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function send()
83 83
     {
84
-        if (!$this->message || !$this->subject || !$this->to) {
84
+        if( !$this->message || !$this->subject || !$this->to ) {
85 85
             return;
86 86
         }
87 87
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     /**
102 102
      * @return array
103 103
      */
104
-    protected function buildHeaders(array $email)
104
+    protected function buildHeaders( array $email )
105 105
     {
106 106
         $allowed = [
107 107
             'bcc',
@@ -110,33 +110,33 @@  discard block
 block discarded – undo
110 110
             'reply-to',
111 111
         ];
112 112
 
113
-        $headers = array_intersect_key($email, array_flip($allowed));
114
-        $headers = array_filter($headers);
113
+        $headers = array_intersect_key( $email, array_flip( $allowed ) );
114
+        $headers = array_filter( $headers );
115 115
 
116
-        foreach ($headers as $key => $value) {
117
-            unset($headers[$key]);
118
-            $headers[] = sprintf('%s: %s', $key, $value);
116
+        foreach( $headers as $key => $value ) {
117
+            unset( $headers[$key] );
118
+            $headers[] = sprintf( '%s: %s', $key, $value );
119 119
         }
120 120
 
121 121
         $headers[] = 'Content-Type: text/html';
122 122
 
123
-        return apply_filters('castor/email/headers', $headers, $this);
123
+        return apply_filters( 'castor/email/headers', $headers, $this );
124 124
     }
125 125
 
126 126
     /**
127 127
      * @return string
128 128
      */
129
-    protected function buildHtmlMessage(array $email)
129
+    protected function buildHtmlMessage( array $email )
130 130
     {
131
-        $body = $this->renderTemplate('index');
132
-        $message = !empty($email['template'])
133
-            ? $this->renderTemplate($email['template'], $email['template-tags'])
131
+        $body = $this->renderTemplate( 'index' );
132
+        $message = !empty( $email['template'] )
133
+            ? $this->renderTemplate( $email['template'], $email['template-tags'] )
134 134
             : $email['message'];
135 135
 
136
-        $message = $this->filterHtml($email['before'].$message.$email['after']);
137
-        $message = str_replace('{message}', $message, $body);
136
+        $message = $this->filterHtml( $email['before'].$message.$email['after'] );
137
+        $message = str_replace( '{message}', $message, $body );
138 138
 
139
-        return apply_filters('castor/email/message', $message, 'html', $this);
139
+        return apply_filters( 'castor/email/message', $message, 'html', $this );
140 140
     }
141 141
 
142 142
     /**
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
      *
145 145
      * @return string
146 146
      */
147
-    protected function buildPlainTextMessage($message)
147
+    protected function buildPlainTextMessage( $message )
148 148
     {
149
-        return apply_filters('castor/email/message', $this->stripHtmlTags($message), 'text', $this);
149
+        return apply_filters( 'castor/email/message', $this->stripHtmlTags( $message ), 'text', $this );
150 150
     }
151 151
 
152 152
     /**
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
      *
155 155
      * @return string
156 156
      */
157
-    protected function filterHtml($message)
157
+    protected function filterHtml( $message )
158 158
     {
159
-        $message = strip_shortcodes($message);
160
-        $message = wptexturize($message);
161
-        $message = wpautop($message);
162
-        $message = str_replace(['&lt;&gt; ', ']]>'], ['', ']]&gt;'], $message);
163
-        $message = stripslashes($message);
159
+        $message = strip_shortcodes( $message );
160
+        $message = wptexturize( $message );
161
+        $message = wpautop( $message );
162
+        $message = str_replace( ['&lt;&gt; ', ']]>'], ['', ']]&gt;'], $message );
163
+        $message = stripslashes( $message );
164 164
         return $message;
165 165
     }
166 166
 
@@ -169,33 +169,33 @@  discard block
 block discarded – undo
169 169
      */
170 170
     protected function getDefaultFrom()
171 171
     {
172
-        return sprintf('%s <%s>',
173
-            wp_specialchars_decode((string) get_option('blogname'), ENT_QUOTES),
174
-            (string) get_option('admin_email')
172
+        return sprintf( '%s <%s>',
173
+            wp_specialchars_decode( (string) get_option( 'blogname' ), ENT_QUOTES ),
174
+            (string) get_option( 'admin_email' )
175 175
         );
176 176
     }
177 177
 
178 178
     /**
179 179
      * @return array
180 180
      */
181
-    protected function normalize($email)
181
+    protected function normalize( $email )
182 182
     {
183
-        $defaults = array_fill_keys([
183
+        $defaults = array_fill_keys( [
184 184
             'after', 'attachments', 'bcc', 'before', 'cc', 'from', 'message', 'reply-to', 'subject',
185 185
             'template', 'template-tags', 'to',
186
-        ], '');
186
+        ], '' );
187 187
         $defaults['from'] = $this->getDefaultFrom();
188 188
 
189
-        $email = shortcode_atts($defaults, $email);
189
+        $email = shortcode_atts( $defaults, $email );
190 190
 
191
-        foreach (['attachments', 'template-tags'] as $key) {
192
-            $email[$key] = array_filter((array) $email[$key]);
191
+        foreach( ['attachments', 'template-tags'] as $key ) {
192
+            $email[$key] = array_filter( (array) $email[$key] );
193 193
         }
194
-        if (empty($email['reply-to'])) {
194
+        if( empty( $email['reply-to'] ) ) {
195 195
             $email['reply-to'] = $email['from'];
196 196
         }
197 197
 
198
-        return apply_filters('castor/email/compose', $email, $this);
198
+        return apply_filters( 'castor/email/compose', $email, $this );
199 199
     }
200 200
 
201 201
     /**
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
      *
206 206
      * @return void|string
207 207
      */
208
-    protected function renderTemplate($templatePath, array $args = [])
208
+    protected function renderTemplate( $templatePath, array $args = [] )
209 209
     {
210
-        $file = $this->template->get('castor/email/'.$templatePath);
210
+        $file = $this->template->get( 'castor/email/'.$templatePath );
211 211
 
212
-        if (!file_exists($file)) {
213
-            $file = sprintf('%s/templates/email/%s.php', dirname(dirname(__DIR__)), $templatePath);
212
+        if( !file_exists( $file ) ) {
213
+            $file = sprintf( '%s/templates/email/%s.php', dirname( dirname( __DIR__ ) ), $templatePath );
214 214
         }
215
-        if (!file_exists($file)) {
215
+        if( !file_exists( $file ) ) {
216 216
             return;
217 217
         }
218 218
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
         include $file;
221 221
         $template = ob_get_clean();
222 222
 
223
-        return $this->renderTemplateString($template, $args);
223
+        return $this->renderTemplateString( $template, $args );
224 224
     }
225 225
 
226 226
     /**
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
      *
229 229
      * @return string
230 230
      */
231
-    protected function renderTemplateString($template, array $args = [])
231
+    protected function renderTemplateString( $template, array $args = [] )
232 232
     {
233
-        foreach ($args as $key => $value) {
234
-            $template = str_replace('{'.$key.'}', $value, $template);
233
+        foreach( $args as $key => $value ) {
234
+            $template = str_replace( '{'.$key.'}', $value, $template );
235 235
         }
236
-        return trim($template);
236
+        return trim( $template );
237 237
     }
238 238
 
239 239
     /**
@@ -256,16 +256,16 @@  discard block
 block discarded – undo
256 256
      * - strip all remaining HTML tags.
257 257
      * @return string
258 258
      */
259
-    protected function stripHtmlTags($string)
259
+    protected function stripHtmlTags( $string )
260 260
     {
261
-        $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string);
262
-        $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string);
263
-        $string = preg_replace('@</(td|th)@iu', ' $0', $string);
264
-        $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string);
265
-        $string = wp_strip_all_tags($string);
266
-        $string = wp_specialchars_decode($string, ENT_QUOTES);
267
-        $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string);
268
-        $string = str_replace('-o-^-o-', ' - ', $string);
269
-        return html_entity_decode($string, ENT_QUOTES, 'UTF-8');
261
+        $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string );
262
+        $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string );
263
+        $string = preg_replace( '@</(td|th)@iu', ' $0', $string );
264
+        $string = preg_replace( '@<(li)[^>]*?>@siu', '$0-o-^-o-', $string );
265
+        $string = wp_strip_all_tags( $string );
266
+        $string = wp_specialchars_decode( $string, ENT_QUOTES );
267
+        $string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string );
268
+        $string = str_replace( '-o-^-o-', ' - ', $string );
269
+        return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
270 270
     }
271 271
 }
Please login to merge, or discard this patch.