Skip to content

Commit 2237a36

Browse files
thejmitchenergithub-actions[bot]
authored andcommitted
Fix styling
1 parent a9382e6 commit 2237a36

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

src/Commands/InstallCommand.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace Fuelviews\Sitemap\Commands;
44

55
use Illuminate\Console\Command;
6-
use function Laravel\Prompts\select;
6+
77
use function Laravel\Prompts\confirm;
8+
use function Laravel\Prompts\select;
89

910
class InstallCommand extends Command
1011
{
@@ -24,11 +25,11 @@ class InstallCommand extends Command
2425
public function handle(): int
2526
{
2627
if (confirm(
27-
label:'Do you want to publish the configuration file?',
28+
label: 'Do you want to publish the configuration file?',
2829
)) {
2930
$this->call('vendor:publish', [
30-
'--provider' => "Fuelviews\\Sitemap\\SitemapServiceProvider",
31-
'--tag' => "config"
31+
'--provider' => 'Fuelviews\\Sitemap\\SitemapServiceProvider',
32+
'--tag' => 'config',
3233
]);
3334
}
3435

@@ -70,12 +71,14 @@ protected function insertSitemapGenerationCommand($frequency)
7071
$scheduleMethodPos = strpos($kernelContents, 'function schedule(');
7172
if ($scheduleMethodPos === false) {
7273
$this->error('Unable to find the schedule method in Kernel.php.');
74+
7375
return;
7476
}
7577

7678
$insertPos = strpos($kernelContents, '//', $scheduleMethodPos);
7779
if ($insertPos === false) {
7880
$this->error('Unable to find the insertion point in Kernel.php.');
81+
7982
return;
8083
}
8184

@@ -84,6 +87,7 @@ protected function insertSitemapGenerationCommand($frequency)
8487

8588
if (file_put_contents($kernelPath, $newKernelContents) === false) {
8689
$this->error('Failed to write to Kernel.php.');
90+
8791
return;
8892
}
8993
}
@@ -93,18 +97,18 @@ protected function insertSitemapGenerationCommand($frequency)
9397
*/
9498
protected function openInBrowser($url)
9599
{
96-
switch(PHP_OS_FAMILY) {
100+
switch (PHP_OS_FAMILY) {
97101
case 'Windows':
98-
exec("start " . escapeshellarg($url));
102+
exec('start '.escapeshellarg($url));
99103
break;
100104
case 'Linux':
101-
exec("xdg-open " . escapeshellarg($url));
105+
exec('xdg-open '.escapeshellarg($url));
102106
break;
103107
case 'Darwin': // macOS
104-
exec("open " . escapeshellarg($url));
108+
exec('open '.escapeshellarg($url));
105109
break;
106110
default:
107-
$this->error("Platform not supported.");
111+
$this->error('Platform not supported.');
108112
$this->info("Please visit: $url");
109113
break;
110114
}

src/Commands/SitemapGenerateCommand.php

+19-17
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
use GuzzleHttp\Exception\GuzzleException;
77
use Illuminate\Console\Command;
88
use Illuminate\Support\Facades\Config;
9-
use Illuminate\Support\Facades\Route;
10-
Use Illuminate\Support\Facades\Storage;
119
use Illuminate\Support\Facades\Log;
12-
use Spatie\Sitemap\SitemapGenerator;
13-
use Spatie\Sitemap\Tags\Url;
10+
use Illuminate\Support\Facades\Route;
1411
use Spatie\Crawler\Crawler;
12+
use Spatie\Sitemap\SitemapGenerator;
1513
use Spatie\Sitemap\SitemapIndex;
14+
use Spatie\Sitemap\Tags\Url;
1615

1716
class SitemapGenerateCommand extends Command
1817
{
@@ -52,7 +51,7 @@ public function handle()
5251
$this->diskName = Config::get('fv-sitemap.disk', 'public');
5352

5453
try {
55-
$SitemapIndex = !Config::get('fv-sitemap.exclude_index');
54+
$SitemapIndex = ! Config::get('fv-sitemap.exclude_index');
5655

5756
if ($SitemapIndex) {
5857
$this->generatePagesSitemap();
@@ -69,9 +68,9 @@ public function handle()
6968

7069
$this->info('Sitemap generated successfully.');
7170
} catch (\Exception $e) {
72-
Log::error('Sitemap generation failed: ' . $e->getMessage());
71+
Log::error('Sitemap generation failed: '.$e->getMessage());
7372

74-
$this->error('Sitemap generation failed: ' . $e->getMessage());
73+
$this->error('Sitemap generation failed: '.$e->getMessage());
7574

7675
return 1;
7776
}
@@ -84,12 +83,12 @@ public function handle()
8483
* It filters out URLs based on various criteria, including predefined excluded routes, paths,
8584
* and specific URLs. The resulting sitemap is then saved to a specified filename.
8685
*
87-
* @param string $filename The filename for the generated sitemap, defaulting to 'pages_sitemap.xml'.
86+
* @param string $filename The filename for the generated sitemap, defaulting to 'pages_sitemap.xml'.
8887
*/
8988
protected function generatePagesSitemap($filename = 'pages_sitemap.xml')
9089
{
91-
$filename = 'sitemap/' . $filename;
92-
90+
$filename = 'sitemap/'.$filename;
91+
9392
$excludedRouteNameUrls = $this->mapExcludedRouteNamesToUrls();
9493
$excludedPaths = $this->getExcludedPaths();
9594
$excludedUrls = $this->getExcludedUrls();
@@ -114,7 +113,7 @@ protected function generatePagesSitemap($filename = 'pages_sitemap.xml')
114113
$normalizedUrl = rtrim($url->url, '/');
115114
if ($normalizedUrl !== $baseUrlWithoutSlash) {
116115
$url->setUrl($normalizedUrl);
117-
} else if ($url->url === $baseUrlWithoutSlash . '/') {
116+
} elseif ($url->url === $baseUrlWithoutSlash.'/') {
118117
return null;
119118
}
120119

@@ -138,41 +137,44 @@ protected function generatePostsSitemap()
138137
/**
139138
* Determine if a path matches any of the excluded patterns.
140139
*
141-
* @param string $path
142-
* @param array $excludedPatterns
140+
* @param string $path
141+
* @param array $excludedPatterns
143142
* @return bool
144143
*/
145144
protected function isPathExcluded($path, $excludedPatterns)
146145
{
147146
foreach ($excludedPatterns as $pattern) {
148-
if (preg_match("#^" . preg_quote($pattern, '#') . "#", $path)) {
147+
if (preg_match('#^'.preg_quote($pattern, '#').'#', $path)) {
149148
return true;
150149
}
151150
}
151+
152152
return false;
153153
}
154154

155155
/**
156156
* Check if a given URL is a redirect.
157157
*
158-
* @param string $url
158+
* @param string $url
159159
* @return bool
160160
*/
161161
protected function isRedirect($url)
162162
{
163163
$excludeRedirects = Config::get('fv-sitemap.exclude_redirects');
164164

165-
if (!$excludeRedirects) {
165+
if (! $excludeRedirects) {
166166
return false;
167167
}
168168

169169
$client = new Client();
170170
try {
171171
$response = $client->request('HEAD', $url, ['allow_redirects' => false]);
172172
$statusCode = $response->getStatusCode();
173+
173174
return in_array($statusCode, [301, 302, 307, 308]);
174175
} catch (GuzzleException $e) {
175-
Log::error('Error checking URL: ' . $e->getMessage());
176+
Log::error('Error checking URL: '.$e->getMessage());
177+
176178
return false;
177179
}
178180
}

src/Http/Controllers/SitemapController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Fuelviews\Sitemap\Http\Controllers;
44

5+
use Illuminate\Routing\Controller as BaseController;
56
use Illuminate\Support\Facades\Config;
67
use Illuminate\Support\Facades\Response;
78
use Illuminate\Support\Facades\Storage;
8-
use Illuminate\Routing\Controller as BaseController;
99

1010
class SitemapController extends BaseController
1111
{
@@ -15,10 +15,11 @@ class SitemapController extends BaseController
1515
public function index($filename)
1616
{
1717
$disk = Config::get('fv-sitemap.disk', 'public');
18-
$filePath = 'sitemap/' . $filename;
18+
$filePath = 'sitemap/'.$filename;
1919

2020
if (Storage::disk($disk)->exists($filePath)) {
2121
$content = Storage::disk($disk)->get($filePath);
22+
2223
return Response::make($content, 200, ['Content-Type' => 'application/xml']);
2324
}
2425

src/SitemapServiceProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use Fuelviews\Sitemap\Commands\InstallCommand;
66
use Fuelviews\Sitemap\Commands\SitemapGenerateCommand;
77
use Fuelviews\Sitemap\Http\Controllers\SitemapController;
8+
use Illuminate\Support\Facades\Route;
89
use Spatie\LaravelPackageTools\Package;
910
use Spatie\LaravelPackageTools\PackageServiceProvider;
10-
use Illuminate\Support\Facades\Route;
1111

1212
class SitemapServiceProvider extends PackageServiceProvider
1313
{
@@ -27,7 +27,7 @@ public function configurePackage(Package $package): void
2727
->publishesServiceProvider('SitemapServiceProvider')
2828
->hasCommands([
2929
SitemapGenerateCommand::class,
30-
InstallCommand::class
30+
InstallCommand::class,
3131
]);
3232
}
3333

0 commit comments

Comments
 (0)