Skip to content

Commit 1305a44

Browse files
committed
feat:
laravel pint formatting pint pipeline contribution page
1 parent 6300993 commit 1305a44

File tree

86 files changed

+754
-943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+754
-943
lines changed

.github/workflows/coverage.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Coverage
33
on:
44
push:
55
branches: ['main']
6+
pull_request:
7+
branches: ['main']
68

79
jobs:
810
test:
@@ -29,3 +31,5 @@ jobs:
2931
token: ${{ secrets.CODECOV_TOKEN }}
3032
slug: matteoc99/laravel-preference
3133
files: ./reports/coverage/coverage.xml
34+
- name: Running Pint
35+
run: composer pint-test

CONTRIBUTING.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Contributing to laravel-preference
2+
3+
Any suggestion/contribution is appreciated
4+
5+
> [!NOTE]
6+
> This is my first "real" open source project.
7+
> In this workflow, things might be missing or plainly wrong/unpractical. Feedback is appreciated
8+
9+
10+
### Questions?
11+
12+
For any doubts, questions and suggestions about laravel preference,
13+
or just to see what others are up to, head to the [Discussions](https://github.com/matteoc99/laravel-preference/discussions) section.
14+
15+
16+
17+
### Bug / Feature Request?
18+
19+
Head over to the Issue Tracker, open an issue and add the respective label
20+
(bug/enhancement)
21+
22+
23+
24+
> [!IMPORTANT]
25+
> Never post a security related problem in the issue tracker
26+
27+
#### Feature Request
28+
29+
Elaborate on the use case. The Feature will then be incorporated into the Roadmap if it fits the scope of the package
30+
Once accepted, feel free to submit a PR along with the issue.
31+
32+
#### Bugfixes
33+
34+
There is no template yet, but consider adding all relevant information
35+
36+
package version:
37+
php version:
38+
interference with other packages or standalone issue?
39+
Database:
40+
Laravel version:
41+
Is the error reproducible in a minimal configuration?
42+
43+
For a bug labeled issue, feel free to add your proposed solution in form of a Pull Request
44+
45+
## PR's
46+
47+
- create new branch from origin/main
48+
- feature/>ISSUE_ID<
49+
- fix/>ISSUE_ID<
50+
- Add your changes
51+
- Add some tests
52+
- Ensure all test pass: `composer test`
53+
- Ensure the code if formatted correctly:
54+
- to format: `composer pint`
55+
- to test the formatting `composer pint-test`
56+
- push the changes and open a PR

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,16 @@ Additional validation, which can be way more complex than provided by the Cast
450450

451451
### Available Rules
452452

453-
| Rule | Example | Description |
454-
|----------------|--------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
453+
| Rule | Example | Description |
454+
|----------------|----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
455455
| AndRule | `new AndRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))` | Expects `n` ValidationRule, ensures all pass |
456-
| OrRule | `new OrRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))` | Expects `n` ValidationRule, ensures at least one passes |
457-
| LaravelRule | `new LaravelRule("required\|numeric")` | Expects a string, containing a Laravel Validation Rule |
458-
| BetweenRule | `new BetweenRule(2.4, 5.5)` | For INT and FLOAT, check that the value is between min and max |
459-
| InRule | `new InRule("it","en","de")` | Expects the value to be validated to be in that equal to one of the `n` params |
460-
| InstanceOfRule | `new InstanceOfRule(Theme::class)` | For non primitive casts, checks the instance of the value's class to validate. Tip: goes along well with the `OrRule` |
461-
| IsRule | `new IsRule(Type::ITERABLE)` | Expects a `Matteoc99\LaravelPreference\Enums\Type` Enum. Checks e.g. if the value is iterable |
462-
| LowerThanRule | `new LowerThanRule(5)` | For INT and FLOAT, check that the value to be validated is less than the one passed in the constructor |
456+
| OrRule | `new OrRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))` | Expects `n` ValidationRule, ensures at least one passes |
457+
| LaravelRule | `new LaravelRule("required\|numeric")` | Expects a string, containing a Laravel Validation Rule |
458+
| BetweenRule | `new BetweenRule(2.4, 5.5)` | For INT and FLOAT, check that the value is between min and max |
459+
| InRule | `new InRule("it","en","de")` | Expects the value to be validated to be in that equal to one of the `n` params |
460+
| InstanceOfRule | `new InstanceOfRule(Theme::class)` | For non primitive casts, checks the instance of the value's class to validate. Tip: goes along well with the `OrRule` |
461+
| IsRule | `new IsRule(Type::ITERABLE)` | Expects a `Matteoc99\LaravelPreference\Enums\Type` Enum. Checks e.g. if the value is iterable |
462+
| LowerThanRule | `new LowerThanRule(5)` | For INT and FLOAT, check that the value to be validated is less than the one passed in the constructor |
463463

464464
### Custom Rules
465465

@@ -705,6 +705,10 @@ install it via [gh](https://nektosact.com/installation/gh.html)
705705

706706
then run: `composer pipeline`
707707

708+
## Contributing
709+
710+
See [Contributing](CONTRIBUTING.md) for details.
711+
708712
## Security Vulnerabilities
709713

710714
Please review [our security policy](SECURITY.md) on how to report security vulnerabilities.
@@ -722,7 +726,7 @@ The MIT License (MIT). Please check the [License File](LICENSE) for more informa
722726

723727
## Support target
724728

725-
| Package Version | Laravel Version |
726-
|-----------------|-----------------|
727-
| 1.x | 10 |
728-
| 2.x | 10 & 11 |
729+
| Package Version | Laravel Version | Maintained |
730+
|-----------------|-----------------|------------|
731+
| 1.x | 10 ||
732+
| 2.x | 10 & 11 ||

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"scripts": {
2323
"analyse": "vendor/bin/phpstan analyse",
2424
"test": "vendor/bin/phpunit",
25+
"pint-test": "vendor/bin/pint --config pint.json --test",
26+
"pint": "vendor/bin/pint --config pint.json",
2527
"pipeline": "gh act -W '.github/workflows/tests.yml'",
2628
"coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit ./tests --coverage-clover='reports/coverage/coverage.xml' --coverage-html='reports/coverage'"
2729
},
@@ -38,7 +40,8 @@
3840
},
3941
"require-dev": {
4042
"orchestra/testbench": "^8.0",
41-
"phpunit/phpunit": "^10.0"
43+
"phpunit/phpunit": "^10.0",
44+
"laravel/pint": "^1.15"
4245
},
4346
"extra": {
4447
"laravel": {

config/user_preference.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
<?php
22

33
return [
4-
'db' => [
5-
'connection' => null,
6-
'preferences_table_name' => 'preferences',
4+
'db' => [
5+
'connection' => null,
6+
'preferences_table_name' => 'preferences',
77
'user_preferences_table_name' => 'users_preferences',
88
],
99
'xss_cleaning' => true,
10-
'routes' => [
11-
'enabled' => false,
10+
'routes' => [
11+
'enabled' => false,
1212
'middlewares' => [
1313
'web', // required for Auth::user() and policies
1414
'auth', // general middleware
15-
'user' => 'verified', // optional, scoped middleware
16-
'user.general' => 'verified' // optional, scoped & grouped middleware
15+
'user' => 'verified', // optional, scoped middleware
16+
'user.general' => 'verified', // optional, scoped & grouped middleware
1717
],
18-
'prefix' => 'preferences',
19-
'groups' => [
18+
'prefix' => 'preferences',
19+
'groups' => [
2020
//enum class list of preferences
2121
//'general'=>General::class
2222
],
23-
'scopes' => [
23+
'scopes' => [
2424
// as many preferenceable models as you want
25-
'user' => \Illuminate\Auth\Authenticatable::class
26-
]
27-
]
28-
];
25+
'user' => \Illuminate\Auth\Authenticatable::class,
26+
],
27+
],
28+
];

database/migrations/2024_03_08_100000_create_user_preferences.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
use Matteoc99\LaravelPreference\Models\Preference;
77
use Matteoc99\LaravelPreference\Models\UserPreference;
88

9-
return new class extends Migration {
10-
9+
return new class() extends Migration
10+
{
1111
public function up()
1212
{
1313

14-
$preferenceTable = (new Preference())->getTable();
14+
$preferenceTable = (new Preference())->getTable();
1515
$userPreferenceTable = (new UserPreference())->getTable();
1616

17-
if (!Schema::hasTable($preferenceTable)) {
17+
if (! Schema::hasTable($preferenceTable)) {
1818
Schema::create($preferenceTable, function (Blueprint $table) {
1919
$table->bigIncrements('id');
2020
$table->string('group')->default('general'); // find and organize preferences // group -> Collection<Preferences>
@@ -29,10 +29,10 @@ public function up()
2929
});
3030
}
3131

32-
if (!Schema::hasTable($userPreferenceTable)) {
32+
if (! Schema::hasTable($userPreferenceTable)) {
3333
Schema::create($userPreferenceTable, function (Blueprint $table) use ($preferenceTable) {
3434
$table->bigIncrements('id');
35-
$table->morphs('preferenceable','preference_preferenceable_index');
35+
$table->morphs('preferenceable', 'preference_preferenceable_index');
3636
$table->unsignedBigInteger('preference_id');
3737
$table->text('value')->nullable();
3838
$table->timestamps();
@@ -47,7 +47,7 @@ public function up()
4747

4848
public function down()
4949
{
50-
$preferenceTable = (new Preference())->getTable();
50+
$preferenceTable = (new Preference())->getTable();
5151
$userPreferenceTable = (new UserPreference())->getTable();
5252

5353
if (Schema::hasTable($userPreferenceTable)) {
@@ -57,4 +57,4 @@ public function down()
5757
Schema::dropIfExists($preferenceTable);
5858
}
5959
}
60-
};
60+
};

database/migrations/2024_04_09_100000_add_preference_guards.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Illuminate\Support\Facades\Schema;
66
use Matteoc99\LaravelPreference\Models\Preference;
77

8-
return new class extends Migration {
9-
8+
return new class() extends Migration
9+
{
1010
public function up()
1111
{
1212

@@ -25,4 +25,4 @@ public function down()
2525
$table->dropColumn('guard');
2626
});
2727
}
28-
};
28+
};

database/migrations/2024_04_09_100000_rename_preference_guards.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Illuminate\Support\Facades\Schema;
66
use Matteoc99\LaravelPreference\Models\Preference;
77

8-
return new class extends Migration {
9-
8+
return new class() extends Migration
9+
{
1010
public function up()
1111
{
1212

@@ -25,4 +25,4 @@ public function down()
2525
$table->renameColumn('policy', 'guard');
2626
});
2727
}
28-
};
28+
};

database/migrations/2024_04_12_100000_make_preference_nullable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Illuminate\Support\Facades\Schema;
66
use Matteoc99\LaravelPreference\Models\Preference;
77

8-
return new class extends Migration {
9-
8+
return new class() extends Migration
9+
{
1010
public function up()
1111
{
1212
$preferenceTable = (new Preference())->getTable();
@@ -24,4 +24,4 @@ public function down()
2424
$table->dropColumn('nullable');
2525
});
2626
}
27-
};
27+
};

database/migrations/2024_04_14_10000_switch_from_json_to_text.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Illuminate\Support\Facades\Schema;
66
use Matteoc99\LaravelPreference\Models\Preference;
77

8-
return new class extends Migration {
9-
8+
return new class() extends Migration
9+
{
1010
public function up()
1111
{
1212
$preferenceTable = (new Preference())->getTable();
@@ -28,4 +28,4 @@ public function down()
2828
$table->json('rule')->nullable()->change();
2929
});
3030
}
31-
};
31+
};

database/migrations/2024_04_21_10000_add_allowed_values.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Illuminate\Support\Facades\Schema;
66
use Matteoc99\LaravelPreference\Models\Preference;
77

8-
return new class extends Migration {
9-
8+
return new class() extends Migration
9+
{
1010
public function up()
1111
{
1212
$preferenceTable = (new Preference())->getTable();
@@ -24,4 +24,4 @@ public function down()
2424
$table->dropColumn('allowed_values');
2525
});
2626
}
27-
};
27+
};

pint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "laravel"
3+
}

routes/api.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
foreach ($scopes as $scope) {
1313
Route::group(['middleware' => ConfigHelper::getScopedMiddlewares($scope), 'prefix' => $scope], function () use ($scope, $groups) {
1414
foreach ($groups as $group) {
15-
$name = sprintf("%s%s.%s", ConfigHelper::getRoutePrefix(), $scope, $group);
15+
$name = sprintf('%s%s.%s', ConfigHelper::getRoutePrefix(), $scope, $group);
1616
Route::group(['middleware' => ConfigHelper::getScopeGroupedMiddlewares($scope, $group)], function () use ($name, $group) {
1717
Route::get("{scope_id}/$group", [PreferenceController::class, 'index'])
18-
->name($name . ".index");
18+
->name($name.'.index');
1919
Route::get("{scope_id}/$group/{preference}", [PreferenceController::class, 'get'])
20-
->name($name . ".get");
20+
->name($name.'.get');
2121
Route::match(['PUT', 'PATCH'], "{scope_id}/$group/{preference}", [PreferenceController::class, 'update'])
22-
->name($name . ".update");
22+
->name($name.'.update');
2323
Route::delete("{scope_id}/$group/{preference}", [PreferenceController::class, 'delete'])
24-
->name($name . ".delete");
24+
->name($name.'.delete');
2525
});
2626
}
2727
});

src/Casts/SerializingCaster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public function get(?Model $model, string $key, mixed $value, array $attributes)
1414

1515
public function set(?Model $model, string $key, mixed $value, array $attributes)
1616
{
17-
return empty($value) ? $value :serialize($value);
17+
return empty($value) ? $value : serialize($value);
1818
}
19-
}
19+
}

0 commit comments

Comments
 (0)