Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
laravel pint formatting
pint pipeline
contribution page
  • Loading branch information
matteoc99 committed May 7, 2024
1 parent 6300993 commit 1305a44
Show file tree
Hide file tree
Showing 86 changed files with 754 additions and 943 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Coverage
on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
test:
Expand All @@ -29,3 +31,5 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
slug: matteoc99/laravel-preference
files: ./reports/coverage/coverage.xml
- name: Running Pint
run: composer pint-test
56 changes: 56 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Contributing to laravel-preference

Any suggestion/contribution is appreciated

> [!NOTE]
> This is my first "real" open source project.
> In this workflow, things might be missing or plainly wrong/unpractical. Feedback is appreciated

### Questions?

For any doubts, questions and suggestions about laravel preference,
or just to see what others are up to, head to the [Discussions](https://github.com/matteoc99/laravel-preference/discussions) section.



### Bug / Feature Request?

Head over to the Issue Tracker, open an issue and add the respective label
(bug/enhancement)



> [!IMPORTANT]
> Never post a security related problem in the issue tracker
#### Feature Request

Elaborate on the use case. The Feature will then be incorporated into the Roadmap if it fits the scope of the package
Once accepted, feel free to submit a PR along with the issue.

#### Bugfixes

There is no template yet, but consider adding all relevant information

package version:
php version:
interference with other packages or standalone issue?
Database:
Laravel version:
Is the error reproducible in a minimal configuration?

For a bug labeled issue, feel free to add your proposed solution in form of a Pull Request

## PR's

- create new branch from origin/main
- feature/>ISSUE_ID<
- fix/>ISSUE_ID<
- Add your changes
- Add some tests
- Ensure all test pass: `composer test`
- Ensure the code if formatted correctly:
- to format: `composer pint`
- to test the formatting `composer pint-test`
- push the changes and open a PR
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,16 @@ Additional validation, which can be way more complex than provided by the Cast

### Available Rules

| Rule | Example | Description |
|----------------|--------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| Rule | Example | Description |
|----------------|----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| AndRule | `new AndRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))` | Expects `n` ValidationRule, ensures all pass |
| OrRule | `new OrRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))` | Expects `n` ValidationRule, ensures at least one passes |
| LaravelRule | `new LaravelRule("required\|numeric")` | Expects a string, containing a Laravel Validation Rule |
| BetweenRule | `new BetweenRule(2.4, 5.5)` | For INT and FLOAT, check that the value is between min and max |
| InRule | `new InRule("it","en","de")` | Expects the value to be validated to be in that equal to one of the `n` params |
| 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` |
| IsRule | `new IsRule(Type::ITERABLE)` | Expects a `Matteoc99\LaravelPreference\Enums\Type` Enum. Checks e.g. if the value is iterable |
| LowerThanRule | `new LowerThanRule(5)` | For INT and FLOAT, check that the value to be validated is less than the one passed in the constructor |
| OrRule | `new OrRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))` | Expects `n` ValidationRule, ensures at least one passes |
| LaravelRule | `new LaravelRule("required\|numeric")` | Expects a string, containing a Laravel Validation Rule |
| BetweenRule | `new BetweenRule(2.4, 5.5)` | For INT and FLOAT, check that the value is between min and max |
| InRule | `new InRule("it","en","de")` | Expects the value to be validated to be in that equal to one of the `n` params |
| 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` |
| IsRule | `new IsRule(Type::ITERABLE)` | Expects a `Matteoc99\LaravelPreference\Enums\Type` Enum. Checks e.g. if the value is iterable |
| LowerThanRule | `new LowerThanRule(5)` | For INT and FLOAT, check that the value to be validated is less than the one passed in the constructor |

### Custom Rules

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

then run: `composer pipeline`

## Contributing

See [Contributing](CONTRIBUTING.md) for details.

## Security Vulnerabilities

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

## Support target

| Package Version | Laravel Version |
|-----------------|-----------------|
| 1.x | 10 |
| 2.x | 10 & 11 |
| Package Version | Laravel Version | Maintained |
|-----------------|-----------------|------------|
| 1.x | 10 ||
| 2.x | 10 & 11 ||
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"scripts": {
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit",
"pint-test": "vendor/bin/pint --config pint.json --test",
"pint": "vendor/bin/pint --config pint.json",
"pipeline": "gh act -W '.github/workflows/tests.yml'",
"coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit ./tests --coverage-clover='reports/coverage/coverage.xml' --coverage-html='reports/coverage'"
},
Expand All @@ -38,7 +40,8 @@
},
"require-dev": {
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^10.0"
"phpunit/phpunit": "^10.0",
"laravel/pint": "^1.15"
},
"extra": {
"laravel": {
Expand Down
28 changes: 14 additions & 14 deletions config/user_preference.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?php

return [
'db' => [
'connection' => null,
'preferences_table_name' => 'preferences',
'db' => [
'connection' => null,
'preferences_table_name' => 'preferences',
'user_preferences_table_name' => 'users_preferences',
],
'xss_cleaning' => true,
'routes' => [
'enabled' => false,
'routes' => [
'enabled' => false,
'middlewares' => [
'web', // required for Auth::user() and policies
'auth', // general middleware
'user' => 'verified', // optional, scoped middleware
'user.general' => 'verified' // optional, scoped & grouped middleware
'user' => 'verified', // optional, scoped middleware
'user.general' => 'verified', // optional, scoped & grouped middleware
],
'prefix' => 'preferences',
'groups' => [
'prefix' => 'preferences',
'groups' => [
//enum class list of preferences
//'general'=>General::class
],
'scopes' => [
'scopes' => [
// as many preferenceable models as you want
'user' => \Illuminate\Auth\Authenticatable::class
]
]
];
'user' => \Illuminate\Auth\Authenticatable::class,
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use Matteoc99\LaravelPreference\Models\Preference;
use Matteoc99\LaravelPreference\Models\UserPreference;

return new class extends Migration {

return new class() extends Migration
{
public function up()
{

$preferenceTable = (new Preference())->getTable();
$preferenceTable = (new Preference())->getTable();
$userPreferenceTable = (new UserPreference())->getTable();

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

if (!Schema::hasTable($userPreferenceTable)) {
if (! Schema::hasTable($userPreferenceTable)) {
Schema::create($userPreferenceTable, function (Blueprint $table) use ($preferenceTable) {
$table->bigIncrements('id');
$table->morphs('preferenceable','preference_preferenceable_index');
$table->morphs('preferenceable', 'preference_preferenceable_index');
$table->unsignedBigInteger('preference_id');
$table->text('value')->nullable();
$table->timestamps();
Expand All @@ -47,7 +47,7 @@ public function up()

public function down()
{
$preferenceTable = (new Preference())->getTable();
$preferenceTable = (new Preference())->getTable();
$userPreferenceTable = (new UserPreference())->getTable();

if (Schema::hasTable($userPreferenceTable)) {
Expand All @@ -57,4 +57,4 @@ public function down()
Schema::dropIfExists($preferenceTable);
}
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Illuminate\Support\Facades\Schema;
use Matteoc99\LaravelPreference\Models\Preference;

return new class extends Migration {

return new class() extends Migration
{
public function up()
{

Expand All @@ -25,4 +25,4 @@ public function down()
$table->dropColumn('guard');
});
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Illuminate\Support\Facades\Schema;
use Matteoc99\LaravelPreference\Models\Preference;

return new class extends Migration {

return new class() extends Migration
{
public function up()
{

Expand All @@ -25,4 +25,4 @@ public function down()
$table->renameColumn('policy', 'guard');
});
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Illuminate\Support\Facades\Schema;
use Matteoc99\LaravelPreference\Models\Preference;

return new class extends Migration {

return new class() extends Migration
{
public function up()
{
$preferenceTable = (new Preference())->getTable();
Expand All @@ -24,4 +24,4 @@ public function down()
$table->dropColumn('nullable');
});
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Illuminate\Support\Facades\Schema;
use Matteoc99\LaravelPreference\Models\Preference;

return new class extends Migration {

return new class() extends Migration
{
public function up()
{
$preferenceTable = (new Preference())->getTable();
Expand All @@ -28,4 +28,4 @@ public function down()
$table->json('rule')->nullable()->change();
});
}
};
};
6 changes: 3 additions & 3 deletions database/migrations/2024_04_21_10000_add_allowed_values.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Illuminate\Support\Facades\Schema;
use Matteoc99\LaravelPreference\Models\Preference;

return new class extends Migration {

return new class() extends Migration
{
public function up()
{
$preferenceTable = (new Preference())->getTable();
Expand All @@ -24,4 +24,4 @@ public function down()
$table->dropColumn('allowed_values');
});
}
};
};
3 changes: 3 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "laravel"
}
10 changes: 5 additions & 5 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
foreach ($scopes as $scope) {
Route::group(['middleware' => ConfigHelper::getScopedMiddlewares($scope), 'prefix' => $scope], function () use ($scope, $groups) {
foreach ($groups as $group) {
$name = sprintf("%s%s.%s", ConfigHelper::getRoutePrefix(), $scope, $group);
$name = sprintf('%s%s.%s', ConfigHelper::getRoutePrefix(), $scope, $group);
Route::group(['middleware' => ConfigHelper::getScopeGroupedMiddlewares($scope, $group)], function () use ($name, $group) {
Route::get("{scope_id}/$group", [PreferenceController::class, 'index'])
->name($name . ".index");
->name($name.'.index');
Route::get("{scope_id}/$group/{preference}", [PreferenceController::class, 'get'])
->name($name . ".get");
->name($name.'.get');
Route::match(['PUT', 'PATCH'], "{scope_id}/$group/{preference}", [PreferenceController::class, 'update'])
->name($name . ".update");
->name($name.'.update');
Route::delete("{scope_id}/$group/{preference}", [PreferenceController::class, 'delete'])
->name($name . ".delete");
->name($name.'.delete');
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/Casts/SerializingCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function get(?Model $model, string $key, mixed $value, array $attributes)

public function set(?Model $model, string $key, mixed $value, array $attributes)
{
return empty($value) ? $value :serialize($value);
return empty($value) ? $value : serialize($value);
}
}
}
Loading

0 comments on commit 1305a44

Please sign in to comment.