Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PHP Coding Standards Fixer

on: [push]

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fixing php-cs
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: tests
name: Tests

on: [push, pull_request]
on:
push:
branches: [ main, develop ]
pull_request:

jobs:
run:
Expand Down Expand Up @@ -38,4 +41,4 @@ jobs:
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: vendor/bin/phpunit
run: vendor/bin/phpunit --testdox
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
composer.lock
.phpunit.result.cache
.phpunit.result.cache
.php-cs-fixer.cache
38 changes: 38 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('storage/*')
->notPath('resources/view/mail/*')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
])
->setFinder($finder);
6 changes: 3 additions & 3 deletions src/Sluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait Sluggable
*/
public function initializeSluggable()
{
if (!$this->sluggable) {
if (! $this->sluggable) {
throw new \Exception('You have to defined the public property `sluggable`.');
}

Expand All @@ -38,7 +38,7 @@ public function initializeSluggable()
protected static function bootSluggable()
{
static::saving(function (Model $model) {
$isCreating = config('pharaonic.sluggable.on_create') && !$model->getKey() && !$model->isDirty('slug');
$isCreating = config('pharaonic.sluggable.on_create') && ! $model->getKey() && ! $model->isDirty('slug');
$isUpdating = config('pharaonic.sluggable.on_update') && $model->getKey() && $model->isDirty($model->sluggable);

if ($isCreating || $isUpdating) {
Expand Down Expand Up @@ -82,7 +82,7 @@ private function generateSlug($value)
config('pharaonic.sluggable.ascii_only'),
config('pharaonic.sluggable.ascii_lang'),
);

if (empty($value)) {
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/SluggableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SluggableTest extends TestCase
public function test_it_can_generate_a_slug()
{
$article = Article::create([
'title' => 'Test Title',
'title' => 'Test Title',
]);

$this->assertSame('test-title', $article->slug);
Expand All @@ -21,7 +21,7 @@ public function test_it_can_generate_slug_in_ascii_only()
config(['pharaonic.sluggable.ascii_only' => true]);

$article = Article::create([
'title' => 'تجربة عنوان',
'title' => 'تجربة عنوان',
]);

$this->assertSame('tgrb-aanoan', $article->slug);
Expand All @@ -30,7 +30,7 @@ public function test_it_can_generate_slug_in_ascii_only()
public function test_it_can_find_by_slug()
{
Article::create([
'title' => 'Test Title',
'title' => 'Test Title',
]);

$this->assertModelExists(Article::findBySlug('test-title'));
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
'prefix' => '',
]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/database/migrations/create_articles_table.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;

return new class () extends Migration {
public function up(): void
Expand Down