@@ -121,13 +121,13 @@ |
||
| 121 | 121 | public function segments(?int $index = null) |
| 122 | 122 | { |
| 123 | 123 | $segments = collect(explode('/', $this->path())) |
| 124 | - ->filter(function ($value) { |
|
| 124 | + ->filter(function($value) { |
|
| 125 | 125 | return $value !== ''; |
| 126 | 126 | }) |
| 127 | 127 | ->values() |
| 128 | 128 | ->toArray(); |
| 129 | 129 | |
| 130 | - if (! is_null($index)) { |
|
| 130 | + if (!is_null($index)) { |
|
| 131 | 131 | return $this->segment($index); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $tag = Url::create($tag); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if (! in_array($tag, $this->tags)) { |
|
| 49 | + if (!in_array($tag, $this->tags)) { |
|
| 50 | 50 | $this->tags[] = $tag; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | public function getUrl(string $url): ?Url |
| 62 | 62 | { |
| 63 | - return collect($this->tags)->first(function (Tag $tag) use ($url) { |
|
| 63 | + return collect($this->tags)->first(function(Tag $tag) use ($url) { |
|
| 64 | 64 | return $tag->getType() === 'url' && $tag->url === $url; |
| 65 | 65 | }); |
| 66 | 66 | } |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | public function hasImages() : bool |
| 74 | 74 | { |
| 75 | - return (bool) collect($this->tags)->first(function (Tag $tag) { |
|
| 76 | - return $tag->getType() === 'url' && ! empty($tag->images); |
|
| 75 | + return (bool) collect($this->tags)->first(function(Tag $tag) { |
|
| 76 | + return $tag->getType() === 'url' && !empty($tag->images); |
|
| 77 | 77 | }); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public function hasNews() : bool |
| 81 | 81 | { |
| 82 | - return (bool) collect($this->tags)->first(function (Tag $tag) { |
|
| 83 | - return $tag->getType() === 'url' && ! empty($tag->news); |
|
| 82 | + return (bool) collect($this->tags)->first(function(Tag $tag) { |
|
| 83 | + return $tag->getType() === 'url' && !empty($tag->news); |
|
| 84 | 84 | }); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $hasImages = $this->hasImages(); |
| 99 | 99 | $hasNews = $this->hasNews(); |
| 100 | 100 | |
| 101 | - if (! $nativeRenderer) { |
|
| 101 | + if (!$nativeRenderer) { |
|
| 102 | 102 | return view('sitemap::sitemap') |
| 103 | 103 | ->with(compact('tags', 'hasImages', 'hasNews')) |
| 104 | 104 | ->render(); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function getSitemap(string $url): ?Sitemap |
| 42 | 42 | { |
| 43 | - return collect($this->tags)->first(function (Tag $tag) use ($url) { |
|
| 43 | + return collect($this->tags)->first(function(Tag $tag) use ($url) { |
|
| 44 | 44 | return $tag->getType() === 'sitemap' && $tag->url === $url; |
| 45 | 45 | }); |
| 46 | 46 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | $tags = $this->tags; |
| 64 | 64 | |
| 65 | - if (! $nativeRenderer) { |
|
| 65 | + if (!$nativeRenderer) { |
|
| 66 | 66 | return view('sitemap::sitemapIndex/index') |
| 67 | 67 | ->with(compact('tags')) |
| 68 | 68 | ->render(); |
@@ -25,7 +25,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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) { |