Passed
Push — master ( 52398c...8b85ea )
by Maurizio
08:44
created
src/Renderer/NativeRenderer.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     public function __construct(array $params)
26 26
     {
27 27
         $this->params = $params;
28
-        $this->tempFile = tempnam(sys_get_temp_dir(), 'mfonte_sitemap_nativerenderer_' . sha1(uniqid()));
28
+        $this->tempFile = tempnam(sys_get_temp_dir(), 'mfonte_sitemap_nativerenderer_'.sha1(uniqid()));
29 29
     }
30 30
 
31 31
     /**
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     public function render(string $type) : string
39 39
     {
40 40
         try {
41
-            switch($type) {
41
+            switch ($type) {
42 42
                 case 'sitemap':
43 43
                     $this->renderSitemap();
44 44
 
@@ -50,16 +50,16 @@  discard block
 block discarded – undo
50 50
                 default:
51 51
                     throw new \Exception('Invalid Render Type', 999);
52 52
             }
53
-        } catch(\Exception $e) {
53
+        } catch (\Exception $e) {
54 54
             if ($e->getCode() === 999) {
55 55
                 throw new \Exception('The render type must be "sitemap" or "sitemapIndex"');
56 56
             }
57 57
 
58
-            throw new \Exception('Error while rendering the xml: ' . $e->getMessage());
58
+            throw new \Exception('Error while rendering the xml: '.$e->getMessage());
59 59
         }
60 60
         
61 61
         // if the tidy extension is not available, return the xml as it was rendered natively.
62
-        if (! function_exists('tidy_parse_file')) {
62
+        if (!function_exists('tidy_parse_file')) {
63 63
             return $this->asString();
64 64
         }
65 65
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         }
79 79
 
80 80
         if ($tidyInstance->errorBuffer) {
81
-            throw new \Exception('Tidy: Errors while loading the Sitemap xml with tidy_parse_file(): ' . "\n" . $tidyInstance->errorBuffer);
81
+            throw new \Exception('Tidy: Errors while loading the Sitemap xml with tidy_parse_file(): '."\n".$tidyInstance->errorBuffer);
82 82
         }
83 83
 
84 84
         $formatted = tidy_clean_repair($tidyInstance);
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
             /** @var Sitemap $tag */
105 105
             
106 106
             $this->append('<sitemap>', 1);
107
-            if (! empty($tag->url)) {
108
-                $this->append('<loc>' . $this->format(url($tag->url)) . '</loc>', 2);
107
+            if (!empty($tag->url)) {
108
+                $this->append('<loc>'.$this->format(url($tag->url)).'</loc>', 2);
109 109
             }
110 110
 
111
-            if (! empty($tag->lastModificationDate)) {
112
-                $this->append('<lastmod>' . $tag->lastModificationDate->format(DateTime::ATOM) . '</lastmod>', 2);
111
+            if (!empty($tag->lastModificationDate)) {
112
+                $this->append('<lastmod>'.$tag->lastModificationDate->format(DateTime::ATOM).'</lastmod>', 2);
113 113
             }
114 114
 
115 115
             $this->append('</sitemap>', 1);
@@ -148,39 +148,39 @@  discard block
 block discarded – undo
148 148
     private function renderUrl(Url $tag)
149 149
     {
150 150
         $this->append('<url>', 1);
151
-        if (! empty($tag->url)) {
152
-            $this->append('<loc>' . $this->format(url($tag->url)) . '</loc>', 2);
151
+        if (!empty($tag->url)) {
152
+            $this->append('<loc>'.$this->format(url($tag->url)).'</loc>', 2);
153 153
         }
154 154
         if (count($tag->alternates)) {
155 155
             foreach ($tag->alternates as $alternate) {
156
-                $this->append('<xhtml:link rel="alternate" hreflang="' . $this->format($alternate->locale) . '" href="' . $this->format(url($alternate->url)) . '" />', 2);
156
+                $this->append('<xhtml:link rel="alternate" hreflang="'.$this->format($alternate->locale).'" href="'.$this->format(url($alternate->url)).'" />', 2);
157 157
             }
158 158
         }
159
-        if (! empty($tag->lastModificationDate)) {
160
-            $this->append('<lastmod>' . $tag->lastModificationDate->format(DateTime::ATOM) . '</lastmod>', 2);
159
+        if (!empty($tag->lastModificationDate)) {
160
+            $this->append('<lastmod>'.$tag->lastModificationDate->format(DateTime::ATOM).'</lastmod>', 2);
161 161
         }
162
-        if (! empty($tag->changeFrequency)) {
163
-            $this->append('<changefreq>' . $this->format($tag->changeFrequency) . '</changefreq>', 2);
162
+        if (!empty($tag->changeFrequency)) {
163
+            $this->append('<changefreq>'.$this->format($tag->changeFrequency).'</changefreq>', 2);
164 164
         }
165
-        if (! empty($tag->priority)) {
166
-            $this->append('<priority>' . number_format($tag->priority, 1) . '</priority>', 2);
165
+        if (!empty($tag->priority)) {
166
+            $this->append('<priority>'.number_format($tag->priority, 1).'</priority>', 2);
167 167
         }
168 168
         if (count($tag->images)) {
169 169
             foreach ($tag->images as $image) {
170
-                if (! empty($image->url)) {
170
+                if (!empty($image->url)) {
171 171
                     $this->append('<image:image>', 2);
172
-                    $this->append('<image:loc>' . url($image->url) . '</image:loc>', 3);
173
-                    if (! empty($image->caption)) {
174
-                        $this->append('<image:caption>' . $this->format($image->caption) . '</image:caption>', 3);
172
+                    $this->append('<image:loc>'.url($image->url).'</image:loc>', 3);
173
+                    if (!empty($image->caption)) {
174
+                        $this->append('<image:caption>'.$this->format($image->caption).'</image:caption>', 3);
175 175
                     }
176
-                    if (! empty($image->geo_location)) {
177
-                        $this->append('<image:geo_location>' . $this->format($image->geo_location) . '</image:geo_location>', 3);
176
+                    if (!empty($image->geo_location)) {
177
+                        $this->append('<image:geo_location>'.$this->format($image->geo_location).'</image:geo_location>', 3);
178 178
                     }
179
-                    if (! empty($image->title)) {
180
-                        $this->append('<image:title>' . $this->format($image->title) . '</image:title>', 3);
179
+                    if (!empty($image->title)) {
180
+                        $this->append('<image:title>'.$this->format($image->title).'</image:title>', 3);
181 181
                     }
182
-                    if (! empty($image->license)) {
183
-                        $this->append('<image:license>' . $this->format($image->license) . '</image:license>', 3);
182
+                    if (!empty($image->license)) {
183
+                        $this->append('<image:license>'.$this->format($image->license).'</image:license>', 3);
184 184
                     }
185 185
                     $this->append('</image:image>', 2);
186 186
                 }
@@ -189,20 +189,20 @@  discard block
 block discarded – undo
189 189
         if (count($tag->news)) {
190 190
             foreach ($tag->news as $new) {
191 191
                 $this->append('<news:news>', 2);
192
-                if (! empty($new->publication_date)) {
193
-                    $this->append('<news:publication_date>' . $new->publication_date->format('Y-m-d') . '</news:publication_date>', 3);
192
+                if (!empty($new->publication_date)) {
193
+                    $this->append('<news:publication_date>'.$new->publication_date->format('Y-m-d').'</news:publication_date>', 3);
194 194
                 }
195
-                if (! empty($new->title)) {
196
-                    $this->append('<news:title>' . $this->format($new->title) . '</news:title>', 3);
195
+                if (!empty($new->title)) {
196
+                    $this->append('<news:title>'.$this->format($new->title).'</news:title>', 3);
197 197
                 }
198
-                if (! empty($new->name) || ! empty($new->language)) {
198
+                if (!empty($new->name) || !empty($new->language)) {
199 199
                     $this->append('<news:publication>', 3);
200
-                    if (! empty($new->name)) {
201
-                        $this->append('<news:name>' . $this->format($new->name) . '</news:name>', 4);
200
+                    if (!empty($new->name)) {
201
+                        $this->append('<news:name>'.$this->format($new->name).'</news:name>', 4);
202 202
                     }
203 203
 
204
-                    if (! empty($new->language)) {
205
-                        $this->append('<news:language>' . $this->format($new->language) . '</news:language>', 4);
204
+                    if (!empty($new->language)) {
205
+                        $this->append('<news:language>'.$this->format($new->language).'</news:language>', 4);
206 206
                     }
207 207
                     $this->append('</news:publication>', 3);
208 208
                 }
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
             throw new \Exception('The temporary file is not writable');
263 263
         }
264 264
 
265
-        $content = ($indentLevel) ? str_repeat(' ', $indentLevel * 2) . $content : $content;
266
-        $content = ($newline) ? $content . "\n" : $content;
265
+        $content = ($indentLevel) ? str_repeat(' ', $indentLevel * 2).$content : $content;
266
+        $content = ($newline) ? $content."\n" : $content;
267 267
         $result = file_put_contents($this->tempFile, $content, FILE_APPEND);
268 268
 
269 269
         if ($result === false) {
Please login to merge, or discard this patch.