Skip to content

Commit

Permalink
Use Laravel Pint for code formatting (#141)
Browse files Browse the repository at this point in the history
Co-authored-by: jesseleite <[email protected]>
  • Loading branch information
jesseleite and jesseleite committed Jul 11, 2023
1 parent ea7f66b commit 0688f16
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 34 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/pint-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Fix PHP code style issues

on:
push:
paths:
- '**.php'

permissions:
contents: write

jobs:
fix-php-code-styling:
runs-on: ubuntu-latest
if: github.repository_owner == 'statamic'

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.PINT }}

- name: Fix PHP code style issues
uses: aglipanci/[email protected]

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
20 changes: 20 additions & 0 deletions .github/workflows/pint-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint PHP code style issues

on:
pull_request:
paths:
- '**.php'

jobs:
lint-php-code-styling:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Check PHP code style issues
uses: aglipanci/[email protected]
with:
testMode: true
verboseMode: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
/vendor
/composer.lock
11 changes: 11 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"preset": "laravel",
"rules": {
"class_attributes_separation": {
"elements": {
"method": "one"
}
},
"psr_autoloading": true
}
}
2 changes: 1 addition & 1 deletion src/Commands/StaticSiteClear.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Statamic\StaticSite\Commands;

use Illuminate\Console\Command;
use Statamic\StaticSite\Generator;
use Statamic\Console\RunsInPlease;
use Statamic\StaticSite\Generator;
use Wilderborn\Partyline\Facade as Partyline;

class StaticSiteClear extends Command
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/StaticSiteGenerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Statamic\StaticSite\Commands;

use Illuminate\Console\Command;
use Statamic\StaticSite\Generator;
use Statamic\Console\RunsInPlease;
use Statamic\StaticSite\GenerationFailedException;
use Statamic\StaticSite\Generator;
use Wilderborn\Partyline\Facade as Partyline;

class StaticSiteGenerate extends Command
Expand Down Expand Up @@ -63,6 +63,7 @@ public function handle()
} catch (GenerationFailedException $e) {
$this->line($e->getConsoleMessage());
$this->error('Static site generation failed.');

return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/StaticSiteLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Statamic\StaticSite\Commands;

use Illuminate\Console\Command;
use Statamic\StaticSite\Generator;
use Statamic\Console\RunsInPlease;
use Statamic\StaticSite\Generator;
use Wilderborn\Partyline\Facade as Partyline;

class StaticSiteLinks extends Command
Expand Down
2 changes: 1 addition & 1 deletion src/GeneratedPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function consoleMessage()
$message = vsprintf('%s%s %s', [
"\x1B[1A\x1B[2K",
$this->hasWarning() ? '<comment>[!]</comment>' : '<info>[✔]</info>',
$this->url()
$this->url(),
]);

if ($this->isRedirect()) {
Expand Down
38 changes: 21 additions & 17 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
namespace Statamic\StaticSite;

use Carbon\Carbon;
use Spatie\Fork\Fork;
use Statamic\Statamic;
use Facades\Statamic\View\Cascade;
use Statamic\Facades\URL;
use Statamic\Support\Str;
use Statamic\Facades\Site;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Routing\Router;
use Illuminate\Support\Arr;
use League\Flysystem\Filesystem as Flysystem;
use Spatie\Fork\Fork;
use Statamic\Contracts\Imaging\UrlBuilder;
use Statamic\Facades\Collection;
use Statamic\Facades\Entry;
use Statamic\Facades\Glide;
use Statamic\Facades\Site;
use Statamic\Facades\Term;
use League\Flysystem\Adapter\Local;
use Statamic\Facades\URL;
use Statamic\Http\Controllers\FrontendController;
use Statamic\Imaging\ImageGenerator;
use Illuminate\Filesystem\Filesystem;
use Statamic\Imaging\StaticUrlBuilder;
use Statamic\Contracts\Imaging\UrlBuilder;
use League\Flysystem\Filesystem as Flysystem;
use Statamic\Statamic;
use Statamic\Support\Str;
use Wilderborn\Partyline\Facade as Partyline;
use Illuminate\Contracts\Foundation\Application;
use Statamic\Http\Controllers\FrontendController;

class Generator
{
Expand Down Expand Up @@ -115,12 +114,12 @@ public function bindGlide()
: '\League\Flysystem\Local\LocalFilesystemAdapter';

$this->app['League\Glide\Server']->setCache(
new Flysystem(new $localAdapter($this->config['destination'] . '/' . $directory))
new Flysystem(new $localAdapter($this->config['destination'].'/'.$directory))
);

$this->app->bind(UrlBuilder::class, function () use ($directory) {
return new StaticUrlBuilder($this->app[ImageGenerator::class], [
'route' => URL::tidy($this->config['base_url'] . '/' . $directory)
'route' => URL::tidy($this->config['base_url'].'/'.$directory),
]);
});

Expand All @@ -137,7 +136,7 @@ public function clearDirectory()
public function createSymlinks()
{
foreach ($this->config['symlinks'] as $source => $dest) {
$dest = $this->config['destination'] . '/' . $dest;
$dest = $this->config['destination'].'/'.$dest;

if ($this->files->exists($dest)) {
Partyline::line("Symlink not created. $dest already exists.");
Expand All @@ -153,7 +152,7 @@ public function createSymlinks()
public function copyFiles()
{
foreach ($this->config['copy'] ?? [] as $source => $dest) {
$dest = $this->config['destination'] . '/' . $dest;
$dest = $this->config['destination'].'/'.$dest;

if (is_file($source)) {
$this->files->copy($source, $dest);
Expand Down Expand Up @@ -234,7 +233,9 @@ protected function pages()
->reject(function ($page) {
foreach ($this->config['exclude'] as $url) {
if (Str::endsWith($url, '*')) {
if (Str::is($url, $page->url())) return true;
if (Str::is($url, $page->url())) {
return true;
}
}
}

Expand Down Expand Up @@ -274,6 +275,7 @@ protected function makeContentGenerationClosures($pages, $request)
}

$errors[] = $e->consoleMessage();

continue;
} finally {
Carbon::setToStringFormat($oldCarbonFormat);
Expand Down Expand Up @@ -305,7 +307,7 @@ protected function outputTasksResults()
protected function outputSummary()
{
Partyline::info('');
Partyline::info('Static site generated into ' . $this->config['destination']);
Partyline::info('Static site generated into '.$this->config['destination']);

$total = $this->taskResults['count'];

Expand Down Expand Up @@ -378,6 +380,7 @@ protected function urls()

return collect($this->config['urls'] ?? [])->merge($extra)->map(function ($url) {
$url = URL::tidy(Str::start($url, $this->config['base_url'].'/'));

return $this->createPage(new Route($url));
});
}
Expand All @@ -389,6 +392,7 @@ protected function routes()
&& ! Str::contains($route->uri(), '{');
})->map(function ($route) {
$url = URL::tidy(Str::start($route->uri(), $this->config['base_url'].'/'));

return $this->createPage(new StatamicRoute($url));
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/NotGeneratedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Statamic\StaticSite;

use Facade\Ignition\Exceptions\ViewException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Statamic\Exceptions\NotFoundHttpException as StatamicNotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException as SymfonyNotFoundHttpException;

class NotGeneratedException extends \Exception
Expand Down Expand Up @@ -37,12 +37,12 @@ public function consoleMessage()
$message = 'Resulted in 404';
break;
case HttpException::class:
$message = 'Resulted in ' . $exception->getStatusCode();
$message = 'Resulted in '.$exception->getStatusCode();
break;
default:
$message = $this->getMessage();
}

return sprintf('%s %s (%s)', "<fg=red>[✘]</>", $this->getPage()->url(), $message);
return sprintf('%s %s (%s)', '<fg=red>[✘]</>', $this->getPage()->url(), $message);
}
}
6 changes: 3 additions & 3 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Exception;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\RedirectResponse;

class Page
{
Expand Down Expand Up @@ -67,14 +67,14 @@ public function directory()
public function path()
{
if ($this->is404()) {
return $this->config['destination'] . '/404.html';
return $this->config['destination'].'/404.html';
}

$url = $this->url();

$ext = pathinfo($url, PATHINFO_EXTENSION) ?: 'html';

$url = $this->config['destination'] . $url;
$url = $this->config['destination'].$url;

if ($ext === 'html') {
$url .= '/index.html';
Expand Down
3 changes: 1 addition & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace Statamic\StaticSite;

use Spatie\Fork\Fork;
use Statamic\StaticSite\Generator;
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
use Spatie\Fork\Fork;

class ServiceProvider extends LaravelServiceProvider
{
Expand Down
2 changes: 2 additions & 0 deletions tests/ConsecutiveTasksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public function it_runs_callbacks()

$one = function () use (&$callbacksRan) {
$callbacksRan++;

return 'one';
};

$two = function () use (&$callbacksRan) {
$callbacksRan++;

return 'two';
};

Expand Down
1 change: 0 additions & 1 deletion tests/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Tests;

use Illuminate\Filesystem\Filesystem;
use Mockery;
use Statamic\Contracts\Entries\Entry;
use Statamic\StaticSite\Page;

Expand Down
5 changes: 2 additions & 3 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Tests;

use Mockery;
use Statamic\Facades\Site;
use Statamic\Entries\Collection;
use Statamic\Entries\Entry;
use Statamic\Facades\Site;
use Statamic\StaticSite\Page;
use Statamic\Entries\Collection;
use Statamic\StaticSite\Request;

class RequestTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Tests;

use Statamic\Providers\StatamicServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Statamic\Providers\StatamicServiceProvider;
use Statamic\Statamic;

class TestCase extends OrchestraTestCase
Expand Down

0 comments on commit 0688f16

Please sign in to comment.