diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index aeb1a62..f7166fa 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -29,7 +29,7 @@ jobs: - name: Run Pint run: pint - - name: Commit linted files - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: Fix code styling + #- name: Commit linted files + #uses: stefanzweifel/git-auto-commit-action@v5 + #with: + #commit_message: Fix code styling diff --git a/.github/workflows/deployTocPanel.yml b/.github/workflows/deployTocPanel.yml index c0badf7..fc6f71c 100644 --- a/.github/workflows/deployTocPanel.yml +++ b/.github/workflows/deployTocPanel.yml @@ -3,44 +3,44 @@ on: workflow_dispatch: inputs: logLevel: - description: 'Log level' + description: "Log level" required: true - default: 'warning' + default: "warning" type: choice options: - - info - - warning - - debug + - info + - warning + - debug jobs: FTP-Deploy-Action: name: FTP-Deploy-Action runs-on: ubuntu-latest steps: - - name: 🚚 Get latest code - uses: actions/checkout@v4 + - name: 🚚 Get latest code + uses: actions/checkout@v4 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 + #- name: Setup PHP + #uses: shivammathur/setup-php@v2 + #with: + #php-version: 8.2 - - name: Install Composer dependencies - run: composer install --prefer-dist --no-interaction + #- name: Install Composer dependencies + #run: composer install --prefer-dist --no-interaction - - name: Use Node.js 16 - uses: actions/setup-node@v3 - with: - node-version: '16' + - name: Use Node.js 16 + uses: actions/setup-node@v3 + with: + node-version: "16" - - name: 🔨 Build Project - run: | - npm install - npm run build + - name: 🔨 Build Project + run: | + npm install + npm run build - - name: FTP-Deploy-Action - uses: SamKirkland/FTP-Deploy-Action@v4.3.4 - with: - server: ${{ secrets.FTP_SERVER }} - username: ${{ secrets.FTP_USERNAME }} - password: ${{ secrets.FTP_PASSWORD }} + - name: FTP-Deploy-Action + uses: SamKirkland/FTP-Deploy-Action@v4.3.4 + with: + server: ${{ secrets.FTP_SERVER }} + username: ${{ secrets.FTP_USERNAME }} + password: ${{ secrets.FTP_PASSWORD }} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index f2b2251..6b7d571 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,7 +28,7 @@ protected function schedule(Schedule $schedule): void protected function commands(): void { - $this->load([__DIR__ . '/Commands']); + $this->load([__DIR__.'/Commands']); // $this->load([__DIR__.'/Commands',__DIR__.'/packages/laravel-subscriptions/src/Console/Commands']); diff --git a/app/Listeners/SendNewArticleNotification.php b/app/Listeners/SendNewArticleNotification.php index 1e0a6ca..9a41ee4 100644 --- a/app/Listeners/SendNewArticleNotification.php +++ b/app/Listeners/SendNewArticleNotification.php @@ -8,7 +8,7 @@ use App\Notifications\ArticleSubmitted; use Illuminate\Notifications\AnonymousNotifiable; -final readonly class SendNewArticleNotification +final class SendNewArticleNotification { public function __construct(private AnonymousNotifiable $notifiable) { diff --git a/app/Listeners/SendPaymentNotification.php b/app/Listeners/SendPaymentNotification.php index 6fa6b34..b5aa0b3 100644 --- a/app/Listeners/SendPaymentNotification.php +++ b/app/Listeners/SendPaymentNotification.php @@ -8,7 +8,7 @@ use App\Notifications\NewSponsorPaymentNotification; use Illuminate\Notifications\AnonymousNotifiable; -final readonly class SendPaymentNotification +final class SendPaymentNotification { public function __construct(private AnonymousNotifiable $notifiable) { diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 50557af..7e2a5cd 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -35,7 +35,7 @@ public function register(): void public function boot(): void { - date_default_timezone_set('Africa/Douala'); + date_default_timezone_set('Africa/Casablanca'); setlocale(LC_TIME, 'fr_FR', 'fr', 'FR', 'French', 'fr_FR.UTF-8'); setlocale(LC_ALL, 'fr_FR', 'fr', 'FR', 'French', 'fr_FR.UTF-8'); Carbon::setLocale('fr'); diff --git a/app/Services/Smtp/CheckSmtpConnection.php b/app/Services/Smtp/CheckSmtpConnection.php new file mode 100644 index 0000000..fb07e27 --- /dev/null +++ b/app/Services/Smtp/CheckSmtpConnection.php @@ -0,0 +1,24 @@ +setUsername(config('mail.mailers.smtp.username')); + $transport->setPassword(config('mail.mailers.smtp.password')); + $transport->start(); + + return true; + } catch (\Exception $e) { + //return info($e->getMessage(), ['error_smtp']); + return false; + } + } +} diff --git a/composer.lock b/composer.lock index 0ce5d93..52ae38a 100644 --- a/composer.lock +++ b/composer.lock @@ -4501,16 +4501,16 @@ }, { "name": "league/mime-type-detection", - "version": "1.13.0", + "version": "1.14.0", "source": { "type": "git", "url": "https://github.com/thephpleague/mime-type-detection.git", - "reference": "a6dfb1194a2946fcdc1f38219445234f65b35c96" + "reference": "b6a5854368533df0295c5761a0253656a2e52d9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/a6dfb1194a2946fcdc1f38219445234f65b35c96", - "reference": "a6dfb1194a2946fcdc1f38219445234f65b35c96", + "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/b6a5854368533df0295c5761a0253656a2e52d9e", + "reference": "b6a5854368533df0295c5761a0253656a2e52d9e", "shasum": "" }, "require": { @@ -4541,7 +4541,7 @@ "description": "Mime-type detection for Flysystem", "support": { "issues": "https://github.com/thephpleague/mime-type-detection/issues", - "source": "https://github.com/thephpleague/mime-type-detection/tree/1.13.0" + "source": "https://github.com/thephpleague/mime-type-detection/tree/1.14.0" }, "funding": [ { @@ -4553,7 +4553,7 @@ "type": "tidelift" } ], - "time": "2023-08-05T12:09:49+00:00" + "time": "2023-10-17T14:13:20+00:00" }, { "name": "league/oauth1-client", @@ -13140,16 +13140,16 @@ }, { "name": "maximebf/debugbar", - "version": "v1.19.0", + "version": "v1.19.1", "source": { "type": "git", "url": "https://github.com/maximebf/php-debugbar.git", - "reference": "30f65f18f7ac086255a77a079f8e0dcdd35e828e" + "reference": "03dd40a1826f4d585ef93ef83afa2a9874a00523" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/30f65f18f7ac086255a77a079f8e0dcdd35e828e", - "reference": "30f65f18f7ac086255a77a079f8e0dcdd35e828e", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/03dd40a1826f4d585ef93ef83afa2a9874a00523", + "reference": "03dd40a1826f4d585ef93ef83afa2a9874a00523", "shasum": "" }, "require": { @@ -13200,9 +13200,9 @@ ], "support": { "issues": "https://github.com/maximebf/php-debugbar/issues", - "source": "https://github.com/maximebf/php-debugbar/tree/v1.19.0" + "source": "https://github.com/maximebf/php-debugbar/tree/v1.19.1" }, - "time": "2023-09-19T19:53:10+00:00" + "time": "2023-10-12T08:10:52+00:00" }, { "name": "mockery/mockery", @@ -13542,24 +13542,24 @@ }, { "name": "pestphp/pest", - "version": "v2.23.2", + "version": "v2.24.0", "source": { "type": "git", "url": "https://github.com/pestphp/pest.git", - "reference": "b126e8e6e4afd6562e80c5dafcc2a973f17a09b3" + "reference": "811ef27ee4741661f70f629a10e31269d2e2895a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pestphp/pest/zipball/b126e8e6e4afd6562e80c5dafcc2a973f17a09b3", - "reference": "b126e8e6e4afd6562e80c5dafcc2a973f17a09b3", + "url": "https://api.github.com/repos/pestphp/pest/zipball/811ef27ee4741661f70f629a10e31269d2e2895a", + "reference": "811ef27ee4741661f70f629a10e31269d2e2895a", "shasum": "" }, "require": { "brianium/paratest": "^7.3.0", - "nunomaduro/collision": "^7.9.0|^8.0.0", + "nunomaduro/collision": "^7.10.0|^8.0.0", "nunomaduro/termwind": "^1.15.1|^2.0.0", "pestphp/pest-plugin": "^2.1.1", - "pestphp/pest-plugin-arch": "^2.4.0", + "pestphp/pest-plugin-arch": "^2.4.1", "php": "^8.1.0", "phpunit/phpunit": "^10.4.1" }, @@ -13629,7 +13629,7 @@ ], "support": { "issues": "https://github.com/pestphp/pest/issues", - "source": "https://github.com/pestphp/pest/tree/v2.23.2" + "source": "https://github.com/pestphp/pest/tree/v2.24.0" }, "funding": [ { @@ -13641,7 +13641,7 @@ "type": "github" } ], - "time": "2023-10-10T15:40:34+00:00" + "time": "2023-10-17T09:07:18+00:00" }, { "name": "pestphp/pest-plugin", @@ -14397,16 +14397,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.38", + "version": "1.10.39", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691" + "reference": "d9dedb0413f678b4d03cbc2279a48f91592c97c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5302bb402c57f00fb3c2c015bac86e0827e4b691", - "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d9dedb0413f678b4d03cbc2279a48f91592c97c4", + "reference": "d9dedb0413f678b4d03cbc2279a48f91592c97c4", "shasum": "" }, "require": { @@ -14455,7 +14455,7 @@ "type": "tidelift" } ], - "time": "2023-10-06T14:19:14+00:00" + "time": "2023-10-17T15:46:26+00:00" }, { "name": "phpunit/php-code-coverage", @@ -15858,35 +15858,35 @@ }, { "name": "spatie/flare-client-php", - "version": "1.4.2", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/spatie/flare-client-php.git", - "reference": "5f2c6a7a0d2c1d90c12559dc7828fd942911a544" + "reference": "5db2fdd743c3ede33f2a5367d89ec1a7c9c1d1ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/5f2c6a7a0d2c1d90c12559dc7828fd942911a544", - "reference": "5f2c6a7a0d2c1d90c12559dc7828fd942911a544", + "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/5db2fdd743c3ede33f2a5367d89ec1a7c9c1d1ec", + "reference": "5db2fdd743c3ede33f2a5367d89ec1a7c9c1d1ec", "shasum": "" }, "require": { - "illuminate/pipeline": "^8.0|^9.0|^10.0", + "illuminate/pipeline": "^8.0|^9.0|^10.0|^11.0", "nesbot/carbon": "^2.62.1", "php": "^8.0", "spatie/backtrace": "^1.5.2", - "symfony/http-foundation": "^5.0|^6.0", - "symfony/mime": "^5.2|^6.0", - "symfony/process": "^5.2|^6.0", - "symfony/var-dumper": "^5.2|^6.0" + "symfony/http-foundation": "^5.2|^6.0|^7.0", + "symfony/mime": "^5.2|^6.0|^7.0", + "symfony/process": "^5.2|^6.0|^7.0", + "symfony/var-dumper": "^5.2|^6.0|^7.0" }, "require-dev": { - "dms/phpunit-arraysubset-asserts": "^0.3.0", - "pestphp/pest": "^1.20", + "dms/phpunit-arraysubset-asserts": "^0.5.0", + "pestphp/pest": "^1.20|^2.0", "phpstan/extension-installer": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", - "spatie/phpunit-snapshot-assertions": "^4.0" + "spatie/phpunit-snapshot-assertions": "^4.0|^5.0" }, "type": "library", "extra": { @@ -15916,7 +15916,7 @@ ], "support": { "issues": "https://github.com/spatie/flare-client-php/issues", - "source": "https://github.com/spatie/flare-client-php/tree/1.4.2" + "source": "https://github.com/spatie/flare-client-php/tree/1.4.3" }, "funding": [ { @@ -15924,7 +15924,7 @@ "type": "github" } ], - "time": "2023-07-28T08:07:24+00:00" + "time": "2023-10-17T15:54:07+00:00" }, { "name": "spatie/ignition", diff --git a/config/app.php b/config/app.php index 44040e2..75ff9ec 100644 --- a/config/app.php +++ b/config/app.php @@ -169,7 +169,8 @@ */ App\Providers\FortifyServiceProvider::class, //LaravelFeature\Provider\FeatureServiceProvider::class, - + \Rinvex\Subscriptions\Providers\SubscriptionsServiceProvider::class, + \LaravelFeature\Provider\FeatureServiceProvider::class, /* * Application Service Providers... */ diff --git a/config/blade-heroicons.php b/config/blade-heroicons.php index e517a97..25e2ffb 100644 --- a/config/blade-heroicons.php +++ b/config/blade-heroicons.php @@ -1,5 +1,7 @@ false, 'helper_files' => [ - base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php', + base_path().'/vendor/laravel/framework/src/Illuminate/Support/helpers.php', ], /* diff --git a/config/ignition.php b/config/ignition.php index 5ff7937..8b61b84 100644 --- a/config/ignition.php +++ b/config/ignition.php @@ -1,5 +1,7 @@ 'App\Widgets', diff --git a/config/livewire-ui-modal.php b/config/livewire-ui-modal.php index 2950291..10e9fb3 100644 --- a/config/livewire-ui-modal.php +++ b/config/livewire-ui-modal.php @@ -1,5 +1,7 @@ [ - // + ], /* diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 0b084db..55f3550 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('users', function (Blueprint $table): void { diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_100000_create_password_resets_table.php index 1967e6d..a66ee84 100644 --- a/database/migrations/2014_10_12_100000_create_password_resets_table.php +++ b/database/migrations/2014_10_12_100000_create_password_resets_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('password_resets', function (Blueprint $table): void { diff --git a/database/migrations/2014_10_12_200000_add_two_factor_columns_to_users_table.php b/database/migrations/2014_10_12_200000_add_two_factor_columns_to_users_table.php index a98b10a..4448897 100644 --- a/database/migrations/2014_10_12_200000_add_two_factor_columns_to_users_table.php +++ b/database/migrations/2014_10_12_200000_add_two_factor_columns_to_users_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::table('users', function (Blueprint $table): void { diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php index 06d93fe..c572494 100644 --- a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php +++ b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('failed_jobs', function (Blueprint $table): void { diff --git a/database/migrations/2021_06_05_182615_create_social_accounts_table.php b/database/migrations/2021_06_05_182615_create_social_accounts_table.php index 79dd211..10f8ecc 100644 --- a/database/migrations/2021_06_05_182615_create_social_accounts_table.php +++ b/database/migrations/2021_06_05_182615_create_social_accounts_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('social_accounts', function (Blueprint $table): void { diff --git a/database/migrations/2021_07_29_164019_create_tags_table.php b/database/migrations/2021_07_29_164019_create_tags_table.php index ea4911a..55ed693 100644 --- a/database/migrations/2021_07_29_164019_create_tags_table.php +++ b/database/migrations/2021_07_29_164019_create_tags_table.php @@ -5,8 +5,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ + +return new class () extends Migration { public function up(): void { Schema::create('tags', function (Blueprint $table): void { diff --git a/database/migrations/2021_08_18_115000_create_articles_table.php b/database/migrations/2021_08_18_115000_create_articles_table.php index c4884cf..4239904 100644 --- a/database/migrations/2021_08_18_115000_create_articles_table.php +++ b/database/migrations/2021_08_18_115000_create_articles_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('articles', function (Blueprint $table): void { diff --git a/database/migrations/2021_09_14_172248_create_permission_tables.php b/database/migrations/2021_09_14_172248_create_permission_tables.php index 11fc161..1b21606 100644 --- a/database/migrations/2021_09_14_172248_create_permission_tables.php +++ b/database/migrations/2021_09_14_172248_create_permission_tables.php @@ -7,8 +7,7 @@ use Illuminate\Support\Facades\Schema; use Spatie\Permission\PermissionRegistrar; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { $tableNames = config('permission.table_names'); diff --git a/database/migrations/2021_10_02_062027_create_reactions_table.php b/database/migrations/2021_10_02_062027_create_reactions_table.php index 226350a..f2c6058 100644 --- a/database/migrations/2021_10_02_062027_create_reactions_table.php +++ b/database/migrations/2021_10_02_062027_create_reactions_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('reactions', function (Blueprint $table): void { diff --git a/database/migrations/2021_10_02_062115_create_reactables_table.php b/database/migrations/2021_10_02_062115_create_reactables_table.php index f6b3948..699d6f3 100644 --- a/database/migrations/2021_10_02_062115_create_reactables_table.php +++ b/database/migrations/2021_10_02_062115_create_reactables_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('reactables', function (Blueprint $table): void { diff --git a/database/migrations/2021_10_15_184151_create_media_table.php b/database/migrations/2021_10_15_184151_create_media_table.php index 9ff5487..17a283d 100644 --- a/database/migrations/2021_10_15_184151_create_media_table.php +++ b/database/migrations/2021_10_15_184151_create_media_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('media', function (Blueprint $table): void { diff --git a/database/migrations/2021_10_15_184203_create_temporary_uploads_table.php b/database/migrations/2021_10_15_184203_create_temporary_uploads_table.php index bf765ad..625ef96 100644 --- a/database/migrations/2021_10_15_184203_create_temporary_uploads_table.php +++ b/database/migrations/2021_10_15_184203_create_temporary_uploads_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('temporary_uploads', function (Blueprint $table): void { diff --git a/database/migrations/2021_10_19_220042_create_sessions_table.php b/database/migrations/2021_10_19_220042_create_sessions_table.php index 13398d5..661bef0 100644 --- a/database/migrations/2021_10_19_220042_create_sessions_table.php +++ b/database/migrations/2021_10_19_220042_create_sessions_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('sessions', function (Blueprint $table): void { diff --git a/database/migrations/2021_11_01_153134_create_activities_table.php b/database/migrations/2021_11_01_153134_create_activities_table.php index 7353b34..bf86f0c 100644 --- a/database/migrations/2021_11_01_153134_create_activities_table.php +++ b/database/migrations/2021_11_01_153134_create_activities_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('activities', function (Blueprint $table): void { diff --git a/database/migrations/2021_11_04_094343_create_views_table.php b/database/migrations/2021_11_04_094343_create_views_table.php index 519dec0..7367579 100644 --- a/database/migrations/2021_11_04_094343_create_views_table.php +++ b/database/migrations/2021_11_04_094343_create_views_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { /** * The database schema. * diff --git a/database/migrations/2021_11_05_132241_create_channels_table.php b/database/migrations/2021_11_05_132241_create_channels_table.php index 8961688..cf660a5 100644 --- a/database/migrations/2021_11_05_132241_create_channels_table.php +++ b/database/migrations/2021_11_05_132241_create_channels_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('channels', function (Blueprint $table): void { diff --git a/database/migrations/2021_11_06_062351_create_threads_table.php b/database/migrations/2021_11_06_062351_create_threads_table.php index bc5cdb6..d75d0d3 100644 --- a/database/migrations/2021_11_06_062351_create_threads_table.php +++ b/database/migrations/2021_11_06_062351_create_threads_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('threads', function (Blueprint $table): void { diff --git a/database/migrations/2021_11_06_073610_create_replies_table.php b/database/migrations/2021_11_06_073610_create_replies_table.php index 9d327f6..806b606 100644 --- a/database/migrations/2021_11_06_073610_create_replies_table.php +++ b/database/migrations/2021_11_06_073610_create_replies_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('replies', function (Blueprint $table): void { diff --git a/database/migrations/2021_11_11_084729_create_subscribes_table.php b/database/migrations/2021_11_11_084729_create_subscribes_table.php index 6753813..e100f41 100644 --- a/database/migrations/2021_11_11_084729_create_subscribes_table.php +++ b/database/migrations/2021_11_11_084729_create_subscribes_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('subscribes', function (Blueprint $table): void { diff --git a/database/migrations/2021_11_11_103416_create_notifications_table.php b/database/migrations/2021_11_11_103416_create_notifications_table.php index 34e95f5..8bb2f78 100644 --- a/database/migrations/2021_11_11_103416_create_notifications_table.php +++ b/database/migrations/2021_11_11_103416_create_notifications_table.php @@ -5,8 +5,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ + +return new class () extends Migration { public function up(): void { Schema::create('notifications', function (Blueprint $table): void { diff --git a/database/migrations/2021_11_16_191729_create_discussions_table.php b/database/migrations/2021_11_16_191729_create_discussions_table.php index cf9c65b..a8c1d79 100644 --- a/database/migrations/2021_11_16_191729_create_discussions_table.php +++ b/database/migrations/2021_11_16_191729_create_discussions_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('discussions', function (Blueprint $table): void { diff --git a/database/migrations/2021_11_29_114833_add_linkedin_profile_column_to_users_table.php b/database/migrations/2021_11_29_114833_add_linkedin_profile_column_to_users_table.php index a368eb6..c7030db 100644 --- a/database/migrations/2021_11_29_114833_add_linkedin_profile_column_to_users_table.php +++ b/database/migrations/2021_11_29_114833_add_linkedin_profile_column_to_users_table.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::table('users', function (Blueprint $table): void { diff --git a/database/migrations/2022_01_15_201921_create_gamify_tables.php b/database/migrations/2022_01_15_201921_create_gamify_tables.php index 584fb32..0bd7948 100644 --- a/database/migrations/2022_01_15_201921_create_gamify_tables.php +++ b/database/migrations/2022_01_15_201921_create_gamify_tables.php @@ -6,8 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { public function up(): void { Schema::create('reputations', function (Blueprint $table): void { diff --git a/database/seeders/FeatureTableSeeder.php b/database/seeders/FeatureTableSeeder.php index b905071..b4c25f6 100644 --- a/database/seeders/FeatureTableSeeder.php +++ b/database/seeders/FeatureTableSeeder.php @@ -5,9 +5,9 @@ namespace Database\Seeders; use Illuminate\Database\Seeder; -use Feature; +use LaravelFeature\Facade\Feature; -final class FeatureTableSeeder extends Seeder +class FeatureTableSeeder extends Seeder { public function run(): void { diff --git a/packages/laravel-feature/src/Config/features.php b/packages/laravel-feature/src/Config/features.php index c24af02..2f6be19 100644 --- a/packages/laravel-feature/src/Config/features.php +++ b/packages/laravel-feature/src/Config/features.php @@ -1,5 +1,7 @@ getOutput()->writeln(''); - if (count($features) === 0) { + if (0 === count($features)) { $this->error('No features were found in the project views!'); $this->getOutput()->writeln(''); return; } - $this->info(count($features) . ' features found in views:'); + $this->info(count($features).' features found in views:'); $this->getOutput()->writeln(''); foreach ($features as $feature) { - $this->getOutput()->writeln('- ' . $feature); + $this->getOutput()->writeln('- '.$feature); } $this->getOutput()->writeln(''); $this->info('All the new features were added to the database with the ' - . ($areEnabledByDefault ? 'ENABLED' : 'disabled') . + .($areEnabledByDefault ? 'ENABLED' : 'disabled'). ' status by default. Nothing changed for the already present ones.'); $this->getOutput()->writeln(''); diff --git a/packages/laravel-feature/src/Domain/Exception/FeatureException.php b/packages/laravel-feature/src/Domain/Exception/FeatureException.php index e6e4c71..6e8a19d 100644 --- a/packages/laravel-feature/src/Domain/Exception/FeatureException.php +++ b/packages/laravel-feature/src/Domain/Exception/FeatureException.php @@ -1,7 +1,11 @@ repository = $repository; } - public function add($featureName, $isEnabled) + public function add($featureName, $isEnabled): void { $feature = Feature::fromNameAndStatus($featureName, $isEnabled); $this->repository->save($feature); } - public function remove($featureName) + public function remove($featureName): void { $feature = $this->repository->findByName($featureName); $this->repository->remove($feature); } - public function rename($featureOldName, $featureNewName) + public function rename($featureOldName, $featureNewName): void { /** @var Feature $feature */ $feature = $this->repository->findByName($featureOldName); @@ -41,7 +43,7 @@ public function rename($featureOldName, $featureNewName) $this->repository->save($feature); } - public function enable($featureName) + public function enable($featureName): void { /** @var Feature $feature */ $feature = $this->repository->findByName($featureName); @@ -51,7 +53,7 @@ public function enable($featureName) $this->repository->save($feature); } - public function disable($featureName) + public function disable($featureName): void { /** @var Feature $feature */ $feature = $this->repository->findByName($featureName); @@ -68,12 +70,12 @@ public function isEnabled($featureName) return $feature->isEnabled(); } - public function enableFor($featureName, FeaturableInterface $featurable) + public function enableFor($featureName, FeaturableInterface $featurable): void { $this->repository->enableFor($featureName, $featurable); } - public function disableFor($featureName, FeaturableInterface $featurable) + public function disableFor($featureName, FeaturableInterface $featurable): void { $this->repository->disableFor($featureName, $featurable); } diff --git a/packages/laravel-feature/src/Domain/Model/Feature.php b/packages/laravel-feature/src/Domain/Model/Feature.php index 826e7da..627189a 100644 --- a/packages/laravel-feature/src/Domain/Model/Feature.php +++ b/packages/laravel-feature/src/Domain/Model/Feature.php @@ -1,8 +1,10 @@ isEnabled; } - public function setNewName($newName) + public function setNewName($newName): void { $this->name = $newName; } - public function enable() + public function enable(): void { $this->isEnabled = true; } - public function disable() + public function disable(): void { $this->isEnabled = false; } diff --git a/packages/laravel-feature/src/Domain/Repository/FeatureRepositoryInterface.php b/packages/laravel-feature/src/Domain/Repository/FeatureRepositoryInterface.php index 078720f..3450c39 100644 --- a/packages/laravel-feature/src/Domain/Repository/FeatureRepositoryInterface.php +++ b/packages/laravel-feature/src/Domain/Repository/FeatureRepositoryInterface.php @@ -1,5 +1,7 @@ first(); - if ((bool) $model->is_enabled === true) { + if (true === (bool) $model->is_enabled) { return true; } diff --git a/packages/laravel-feature/src/Featurable/FeaturableInterface.php b/packages/laravel-feature/src/Featurable/FeaturableInterface.php index 4e71452..9d3222f 100644 --- a/packages/laravel-feature/src/Featurable/FeaturableInterface.php +++ b/packages/laravel-feature/src/Featurable/FeaturableInterface.php @@ -1,5 +1,7 @@ increments('id'); $table->string('name'); @@ -29,7 +31,7 @@ public function up() * * @return void */ - public function down() + public function down(): void { Schema::drop('features'); } diff --git a/packages/laravel-feature/src/Migration/2016_12_17_163450_create_featurables_table.php b/packages/laravel-feature/src/Migration/2016_12_17_163450_create_featurables_table.php index cca6b88..558bfb4 100644 --- a/packages/laravel-feature/src/Migration/2016_12_17_163450_create_featurables_table.php +++ b/packages/laravel-feature/src/Migration/2016_12_17_163450_create_featurables_table.php @@ -1,19 +1,21 @@ bigIncrements('id'); $table->integer('feature_id'); @@ -27,7 +29,7 @@ public function up() * * @return void */ - public function down() + public function down(): void { Schema::drop('featurables'); } diff --git a/packages/laravel-feature/src/Model/Feature.php b/packages/laravel-feature/src/Model/Feature.php index de762ca..f2f1430 100644 --- a/packages/laravel-feature/src/Model/Feature.php +++ b/packages/laravel-feature/src/Model/Feature.php @@ -1,9 +1,11 @@ loadMigrationsFrom(__DIR__.'/../Migration'); @@ -30,48 +32,38 @@ public function boot() * * @return void */ - public function register() + public function register(): void { $this->mergeConfigFrom(__DIR__.'/../Config/features.php', 'features'); $config = $this->app->make('config'); - $this->app->bind(FeatureRepositoryInterface::class, function () use ($config) { - return app()->make($config->get('features.repository')); - }); + $this->app->bind(FeatureRepositoryInterface::class, fn () => app()->make($config->get('features.repository'))); $this->registerConsoleCommand(); } - private function registerBladeDirectives() + private function registerBladeDirectives(): void { $this->registerBladeFeatureDirective(); $this->registerBladeFeatureForDirective(); } - private function registerBladeFeatureDirective() + private function registerBladeFeatureDirective(): void { - Blade::directive('feature', function ($featureName) { - return "isEnabled($featureName)): ?>"; - }); + Blade::directive('feature', fn ($featureName) => "isEnabled({$featureName})): ?>"); - Blade::directive('endfeature', function () { - return ''; - }); + Blade::directive('endfeature', fn () => ''); } - private function registerBladeFeatureForDirective() + private function registerBladeFeatureForDirective(): void { - Blade::directive('featurefor', function ($args) { - return "isEnabledFor($args)): ?>"; - }); + Blade::directive('featurefor', fn ($args) => "isEnabledFor({$args})): ?>"); - Blade::directive('endfeaturefor', function () { - return ''; - }); + Blade::directive('endfeaturefor', fn () => ''); } - private function registerConsoleCommand() + private function registerConsoleCommand(): void { if ($this->app->runningInConsole()) { $this->commands([ diff --git a/packages/laravel-feature/src/Repository/EloquentFeatureRepository.php b/packages/laravel-feature/src/Repository/EloquentFeatureRepository.php index 02c2f17..edaa961 100644 --- a/packages/laravel-feature/src/Repository/EloquentFeatureRepository.php +++ b/packages/laravel-feature/src/Repository/EloquentFeatureRepository.php @@ -1,5 +1,7 @@ getName())->first(); - if (!$model) { + if ( ! $model) { $model = new Model(); } @@ -24,16 +27,16 @@ public function save(Feature $feature) try { $model->save(); - } catch (\Exception $e) { - throw new FeatureException('Unable to save the feature: ' . $e->getMessage()); + } catch (Exception $e) { + throw new FeatureException('Unable to save the feature: '.$e->getMessage()); } } - public function remove(Feature $feature) + public function remove(Feature $feature): void { /** @var Model $model */ $model = Model::where('name', '=', $feature->getName())->first(); - if (!$model) { + if ( ! $model) { throw new FeatureException('Unable to find the feature.'); } @@ -44,7 +47,7 @@ public function findByName($featureName) { /** @var Model $model */ $model = Model::where('name', '=', $featureName)->first(); - if (!$model) { + if ( ! $model) { throw new FeatureException('Unable to find the feature.'); } @@ -54,30 +57,30 @@ public function findByName($featureName) ); } - public function enableFor($featureName, FeaturableInterface $featurable) + public function enableFor($featureName, FeaturableInterface $featurable): void { /** @var Model $model */ $model = Model::where('name', '=', $featureName)->first(); - if (!$model) { + if ( ! $model) { throw new FeatureException('Unable to find the feature.'); } - if ((bool) $model->is_enabled === true || $featurable->hasFeature($featureName) === true) { + if (true === (bool) $model->is_enabled || true === $featurable->hasFeature($featureName)) { return; } $featurable->features()->attach($model->id); } - public function disableFor($featureName, FeaturableInterface $featurable) + public function disableFor($featureName, FeaturableInterface $featurable): void { /** @var Model $model */ $model = Model::where('name', '=', $featureName)->first(); - if (!$model) { + if ( ! $model) { throw new FeatureException('Unable to find the feature.'); } - if ((bool) $model->is_enabled === true || $featurable->hasFeature($featureName) === false) { + if (true === (bool) $model->is_enabled || false === $featurable->hasFeature($featureName)) { return; } @@ -88,7 +91,7 @@ public function isEnabledFor($featureName, FeaturableInterface $featurable) { /** @var Model $model */ $model = Model::where('name', '=', $featureName)->first(); - if (!$model) { + if ( ! $model) { throw new FeatureException('Unable to find the feature.'); } diff --git a/packages/laravel-feature/src/Service/FeaturesViewScanner.php b/packages/laravel-feature/src/Service/FeaturesViewScanner.php index f862f24..66a10dd 100644 --- a/packages/laravel-feature/src/Service/FeaturesViewScanner.php +++ b/packages/laravel-feature/src/Service/FeaturesViewScanner.php @@ -1,12 +1,14 @@ config->get('features.scanned_paths', [ 'resources/views' ]); + $pathsToBeScanned = $this->config->get('features.scanned_paths', ['resources/views']); $foundDirectives = []; @@ -57,7 +59,7 @@ private function getAllBladeViewsInPath($path) $bladeViews = []; foreach ($files as $file) { - $itemPath = $path . DIRECTORY_SEPARATOR . $file; + $itemPath = $path.DIRECTORY_SEPARATOR.$file; if (is_dir($itemPath)) { $bladeViews = array_merge($bladeViews, $this->getAllBladeViewsInPath($itemPath)); diff --git a/packages/laravel-feature/tests/Integration/Blade/BladeFeatureTest.php b/packages/laravel-feature/tests/Integration/Blade/BladeFeatureTest.php index b365831..99c0c1f 100644 --- a/packages/laravel-feature/tests/Integration/Blade/BladeFeatureTest.php +++ b/packages/laravel-feature/tests/Integration/Blade/BladeFeatureTest.php @@ -1,23 +1,25 @@ compiler = app(BladeCompiler::class); } - public function testFeatureStatementsAreCompiled() + public function testFeatureStatementsAreCompiled(): void { $string = '@feature(\'feature.name\') feature enabled @@ -30,7 +32,7 @@ public function testFeatureStatementsAreCompiled() $this->assertEquals($expected, $this->compiler->compileString($string)); } - public function testFeatureForStatementsAreCompiled() + public function testFeatureForStatementsAreCompiled(): void { $string = '@featurefor(\'feature.name\', $user) feature enabled diff --git a/packages/laravel-feature/tests/Integration/Repository/EloquentFeatureRepositoryTest.php b/packages/laravel-feature/tests/Integration/Repository/EloquentFeatureRepositoryTest.php index 5a33f5a..974bc29 100644 --- a/packages/laravel-feature/tests/Integration/Repository/EloquentFeatureRepositoryTest.php +++ b/packages/laravel-feature/tests/Integration/Repository/EloquentFeatureRepositoryTest.php @@ -1,5 +1,7 @@ addTestFeature(); @@ -70,7 +73,7 @@ public function testRemove() /** * Tests the removal operation throws an exception if the feature is not found. */ - public function testRemoveThrowsErrorOnFeatureNotFound() + public function testRemoveThrowsErrorOnFeatureNotFound(): void { $this->addTestFeature(); @@ -85,7 +88,7 @@ public function testRemoveThrowsErrorOnFeatureNotFound() /** * Tests a feature is found. */ - public function testFindByName() + public function testFindByName(): void { $this->addTestFeature(); @@ -98,7 +101,7 @@ public function testFindByName() /** * Tests an exception is thrown if the feature is not found. */ - public function testFindByNameThrowsErrorOnFeatureNotFound() + public function testFindByNameThrowsErrorOnFeatureNotFound(): void { $this->addTestFeature(); @@ -111,7 +114,7 @@ public function testFindByNameThrowsErrorOnFeatureNotFound() /** * Tests the enable operation for a specific FeaturableInterface entity. */ - public function testEnableFor() + public function testEnableFor(): void { $this->createTestEntityTable(); @@ -132,7 +135,7 @@ public function testEnableFor() /** * Tests the enable operation throws an error if the feature is not found. */ - public function testEnableForThrowsErrorOnFeatureNotFound() + public function testEnableForThrowsErrorOnFeatureNotFound(): void { $this->createTestEntityTable(); @@ -149,7 +152,7 @@ public function testEnableForThrowsErrorOnFeatureNotFound() /** * Tests nothing happens if the feature is already enabled globally. */ - public function testEnableForDoesNothingIfFeatureIsGloballyEnabled() + public function testEnableForDoesNothingIfFeatureIsGloballyEnabled(): void { $this->createTestEntityTable(); @@ -170,7 +173,7 @@ public function testEnableForDoesNothingIfFeatureIsGloballyEnabled() /** * Tests the disable of a feature for a specific FeaturableInterface entity. */ - public function testDisableFor() + public function testDisableFor(): void { $this->createTestEntityTable(); @@ -192,7 +195,7 @@ public function testDisableFor() /** * Tests the disable operation throws an error if the feature is not found. */ - public function testDisableForThrowsErrorOnFeatureNotFound() + public function testDisableForThrowsErrorOnFeatureNotFound(): void { $this->createTestEntityTable(); @@ -210,7 +213,7 @@ public function testDisableForThrowsErrorOnFeatureNotFound() /** * Tests nothing happens if the feature is already enabled globally. */ - public function testDisableForDoesNothingIfFeatureIsGloballyEnabled() + public function testDisableForDoesNothingIfFeatureIsGloballyEnabled(): void { $this->createTestEntityTable(); @@ -231,7 +234,7 @@ public function testDisableForDoesNothingIfFeatureIsGloballyEnabled() /** * Tests the enable status of a feature for a specific FeaturableInterface entity. */ - public function testIsEnabledFor() + public function testIsEnabledFor(): void { $this->createTestEntityTable(); @@ -249,7 +252,7 @@ public function testIsEnabledFor() /** * Tests an exception is thrown if the feature is not found. */ - public function testIsEnabledForThrowsExceptionOnFeatureNotFound() + public function testIsEnabledForThrowsExceptionOnFeatureNotFound(): void { $this->createTestEntityTable(); @@ -265,7 +268,7 @@ public function testIsEnabledForThrowsExceptionOnFeatureNotFound() private function addTestFeature($name = 'test.feature', $isEnabled = false) { - $feature = new FeatureModel; + $feature = new FeatureModel(); $feature->name = $name; $feature->is_enabled = $isEnabled; @@ -283,28 +286,28 @@ private function addTestEntity() return $entity; } - private function createTestEntityTable() + private function createTestEntityTable(): void { - \Schema::create('featurabletestentities', function (Blueprint $table) { + Schema::create('featurabletestentities', function (Blueprint $table): void { $table->increments('id'); $table->string('name'); $table->timestamps(); }); } - private function dropTestEntityTable() + private function dropTestEntityTable(): void { - \Schema::drop('featurabletestentities'); + Schema::drop('featurabletestentities'); } - private function enableTestFeatureOn($featurable) + private function enableTestFeatureOn($featurable): void { $feature = \LaravelFeature\Model\Feature::first(); $featurable->features()->attach($feature->id); } } -class FeaturableTestEntity extends Model implements FeaturableInterface +final class FeaturableTestEntity extends Model implements FeaturableInterface { use Featurable; protected $table = 'featurabletestentities'; diff --git a/packages/laravel-feature/tests/Integration/Service/FeaturesViewScannerTest.php b/packages/laravel-feature/tests/Integration/Service/FeaturesViewScannerTest.php index e177328..988749d 100644 --- a/packages/laravel-feature/tests/Integration/Service/FeaturesViewScannerTest.php +++ b/packages/laravel-feature/tests/Integration/Service/FeaturesViewScannerTest.php @@ -1,17 +1,19 @@ service->scan(); diff --git a/packages/laravel-feature/tests/TestCase.php b/packages/laravel-feature/tests/TestCase.php index 12601bd..5be41e1 100644 --- a/packages/laravel-feature/tests/TestCase.php +++ b/packages/laravel-feature/tests/TestCase.php @@ -1,10 +1,12 @@ set('features.scanned_paths', [ __DIR__ . '/Integration/Service/test_folder' ]); + $app['config']->set('features.scanned_paths', [__DIR__.'/Integration/Service/test_folder']); $app['config']->set('database.default', 'testing'); $app['config']->set('database.connections.testing', [ diff --git a/packages/laravel-feature/tests/Unit/Domain/FeatureManagerTest.php b/packages/laravel-feature/tests/Unit/Domain/FeatureManagerTest.php index 93a177e..37e3f8b 100644 --- a/packages/laravel-feature/tests/Unit/Domain/FeatureManagerTest.php +++ b/packages/laravel-feature/tests/Unit/Domain/FeatureManagerTest.php @@ -1,5 +1,7 @@ repositoryMock->expects($this->once()) ->method('save'); @@ -43,7 +46,7 @@ public function testAdd() /** * Tests an exception is thrown if something goes wrong during the saving of a new feature. */ - public function testAddThrowsExceptionOnError() + public function testAddThrowsExceptionOnError(): void { $this->repositoryMock->expects($this->once()) ->method('save') @@ -58,7 +61,7 @@ public function testAddThrowsExceptionOnError() /** * Tests that everything goes well during a feature removal. */ - public function testRemove() + public function testRemove(): void { $feature = $this->getMockBuilder(Feature::class) ->disableOriginalConstructor() @@ -74,7 +77,7 @@ public function testRemove() $this->manager->remove('my.feature'); } - public function testRemoveThrowsExceptionOnError() + public function testRemoveThrowsExceptionOnError(): void { $feature = $this->getMockBuilder(Feature::class) ->disableOriginalConstructor() @@ -97,7 +100,7 @@ public function testRemoveThrowsExceptionOnError() /** * Tests that everything goes well during a feature rename. */ - public function testRenameFeature() + public function testRenameFeature(): void { $feature = $this->getMockBuilder(Feature::class) ->disableOriginalConstructor() @@ -116,7 +119,7 @@ public function testRenameFeature() /** * Tests that an exception is thrown if the feature is not found. */ - public function testRenameFeatureThrowsError() + public function testRenameFeatureThrowsError(): void { $feature = $this->getMockBuilder(Feature::class) ->disableOriginalConstructor() @@ -139,7 +142,7 @@ public function testRenameFeatureThrowsError() /** * Tests everything goes well when a feature is globally enabled. */ - public function testEnableFeature() + public function testEnableFeature(): void { $feature = $this->getMockBuilder(Feature::class) ->disableOriginalConstructor() @@ -161,7 +164,7 @@ public function testEnableFeature() /** * Tests everything goes well when a feature is globally disabled. */ - public function testDisableFeature() + public function testDisableFeature(): void { $feature = $this->getMockBuilder(Feature::class) ->disableOriginalConstructor() @@ -183,7 +186,7 @@ public function testDisableFeature() /** * Tests the manager can correctly check if a feature is enabled or not. */ - public function testFeatureIsEnabled() + public function testFeatureIsEnabled(): void { $feature = $this->getMockBuilder(Feature::class) ->disableOriginalConstructor() @@ -200,9 +203,9 @@ public function testFeatureIsEnabled() $this->assertTrue($this->manager->isEnabled('my.feature')); } - public function testEnableFor() + public function testEnableFor(): void { - /** @var FeaturableInterface | \PHPUnit_Framework_MockObject_MockObject $featurableMock */ + /** @var FeaturableInterface|PHPUnit_Framework_MockObject_MockObject $featurableMock */ $featurableMock = $this->getMockBuilder(FeaturableInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -213,9 +216,9 @@ public function testEnableFor() $this->manager->enableFor('my.feature', $featurableMock); } - public function testDisableFor() + public function testDisableFor(): void { - /** @var FeaturableInterface | \PHPUnit_Framework_MockObject_MockObject $featurableMock */ + /** @var FeaturableInterface|PHPUnit_Framework_MockObject_MockObject $featurableMock */ $featurableMock = $this->getMockBuilder(FeaturableInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -226,9 +229,9 @@ public function testDisableFor() $this->manager->disableFor('my.feature', $featurableMock); } - public function testIsEnabledFor() + public function testIsEnabledFor(): void { - /** @var FeaturableInterface | \PHPUnit_Framework_MockObject_MockObject $featurableMock */ + /** @var FeaturableInterface|PHPUnit_Framework_MockObject_MockObject $featurableMock */ $featurableMock = $this->getMockBuilder(FeaturableInterface::class) ->disableOriginalConstructor() ->getMock(); diff --git a/packages/laravel-feature/tests/Unit/Domain/FeatureTest.php b/packages/laravel-feature/tests/Unit/Domain/FeatureTest.php index 637f757..05109f2 100644 --- a/packages/laravel-feature/tests/Unit/Domain/FeatureTest.php +++ b/packages/laravel-feature/tests/Unit/Domain/FeatureTest.php @@ -1,16 +1,18 @@ setNewName('new.name'); @@ -32,7 +34,7 @@ public function testNameChange() /** * Tests the enable operation of a feature. */ - public function testEnable() + public function testEnable(): void { $feature = Feature::fromNameAndStatus('my.feature', false); @@ -44,7 +46,7 @@ public function testEnable() /** * Tests the disable operation of a feature. */ - public function testDisable() + public function testDisable(): void { $feature = Feature::fromNameAndStatus('my.feature', true); diff --git a/packages/laravel-subscriptions/database/migrations/2020_01_01_000001_create_plans_table.php b/packages/laravel-subscriptions/database/migrations/2020_01_01_000001_create_plans_table.php index 92d0951..c6a7e7c 100755 --- a/packages/laravel-subscriptions/database/migrations/2020_01_01_000001_create_plans_table.php +++ b/packages/laravel-subscriptions/database/migrations/2020_01_01_000001_create_plans_table.php @@ -5,7 +5,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreatePlansTable extends Migration +final class CreatePlansTable extends Migration { /** * Run the migrations. @@ -14,7 +14,7 @@ class CreatePlansTable extends Migration */ public function up(): void { - Schema::create(config('rinvex.subscriptions.tables.plans'), function (Blueprint $table) { + Schema::create(config('rinvex.subscriptions.tables.plans'), function (Blueprint $table): void { // Columns $table->increments('id'); $table->uuid()->nullable(); diff --git a/packages/laravel-subscriptions/database/migrations/2020_01_01_000002_create_plan_features_table.php b/packages/laravel-subscriptions/database/migrations/2020_01_01_000002_create_plan_features_table.php index 76877b0..5002524 100755 --- a/packages/laravel-subscriptions/database/migrations/2020_01_01_000002_create_plan_features_table.php +++ b/packages/laravel-subscriptions/database/migrations/2020_01_01_000002_create_plan_features_table.php @@ -5,7 +5,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreatePlanFeaturesTable extends Migration +final class CreatePlanFeaturesTable extends Migration { /** * Run the migrations. @@ -14,7 +14,7 @@ class CreatePlanFeaturesTable extends Migration */ public function up(): void { - Schema::create(config('rinvex.subscriptions.tables.plan_features'), function (Blueprint $table) { + Schema::create(config('rinvex.subscriptions.tables.plan_features'), function (Blueprint $table): void { // Columns $table->increments('id'); $table->uuid()->nullable(); @@ -32,7 +32,7 @@ public function up(): void // Indexes $table->unique(['plan_id', 'slug']); $table->foreign('plan_id')->references('id')->on(config('rinvex.subscriptions.tables.plans')) - ->onDelete('cascade')->onUpdate('cascade'); + ->onDelete('cascade')->onUpdate('cascade'); }); } diff --git a/packages/laravel-subscriptions/database/migrations/2020_01_01_000003_create_plan_subscriptions_table.php b/packages/laravel-subscriptions/database/migrations/2020_01_01_000003_create_plan_subscriptions_table.php index fb10a7a..8b2030a 100755 --- a/packages/laravel-subscriptions/database/migrations/2020_01_01_000003_create_plan_subscriptions_table.php +++ b/packages/laravel-subscriptions/database/migrations/2020_01_01_000003_create_plan_subscriptions_table.php @@ -5,7 +5,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreatePlanSubscriptionsTable extends Migration +final class CreatePlanSubscriptionsTable extends Migration { /** * Run the migrations. @@ -14,7 +14,7 @@ class CreatePlanSubscriptionsTable extends Migration */ public function up(): void { - Schema::create(config('rinvex.subscriptions.tables.plan_subscriptions'), function (Blueprint $table) { + Schema::create(config('rinvex.subscriptions.tables.plan_subscriptions'), function (Blueprint $table): void { $table->increments('id'); $table->uuid()->nullable(); $table->morphs('subscriber'); @@ -34,7 +34,7 @@ public function up(): void // Indexes $table->unique('slug'); $table->foreign('plan_id')->references('id')->on(config('rinvex.subscriptions.tables.plans')) - ->onDelete('cascade')->onUpdate('cascade'); + ->onDelete('cascade')->onUpdate('cascade'); }); } diff --git a/packages/laravel-subscriptions/database/migrations/2020_01_01_000004_create_plan_subscription_usage_table.php b/packages/laravel-subscriptions/database/migrations/2020_01_01_000004_create_plan_subscription_usage_table.php index a960373..ec0e323 100755 --- a/packages/laravel-subscriptions/database/migrations/2020_01_01_000004_create_plan_subscription_usage_table.php +++ b/packages/laravel-subscriptions/database/migrations/2020_01_01_000004_create_plan_subscription_usage_table.php @@ -5,7 +5,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreatePlanSubscriptionUsageTable extends Migration +final class CreatePlanSubscriptionUsageTable extends Migration { /** * Run the migrations. @@ -14,7 +14,7 @@ class CreatePlanSubscriptionUsageTable extends Migration */ public function up(): void { - Schema::create(config('rinvex.subscriptions.tables.plan_subscription_usage'), function (Blueprint $table) { + Schema::create(config('rinvex.subscriptions.tables.plan_subscription_usage'), function (Blueprint $table): void { $table->increments('id'); $table->uuid()->nullable(); $table->integer('subscription_id')->unsigned(); @@ -27,9 +27,9 @@ public function up(): void $table->unique(['subscription_id', 'feature_id']); $table->foreign('subscription_id')->references('id')->on(config('rinvex.subscriptions.tables.plan_subscriptions')) - ->onDelete('cascade')->onUpdate('cascade'); + ->onDelete('cascade')->onUpdate('cascade'); $table->foreign('feature_id')->references('id')->on(config('rinvex.subscriptions.tables.plan_features')) - ->onDelete('cascade')->onUpdate('cascade'); + ->onDelete('cascade')->onUpdate('cascade'); }); } diff --git a/packages/laravel-subscriptions/src/Console/Commands/PublishCommand.php b/packages/laravel-subscriptions/src/Console/Commands/PublishCommand.php index 7c235dd..439bf97 100644 --- a/packages/laravel-subscriptions/src/Console/Commands/PublishCommand.php +++ b/packages/laravel-subscriptions/src/Console/Commands/PublishCommand.php @@ -6,7 +6,7 @@ use Illuminate\Console\Command; -class PublishCommand extends Command +final class PublishCommand extends Command { /** * The name and signature of the console command. @@ -31,7 +31,7 @@ public function handle(): void { $this->alert($this->description); - collect($this->option('resource') ?: ['config', 'migrations'])->each(function ($resource) { + collect($this->option('resource') ?: ['config', 'migrations'])->each(function ($resource): void { $this->call('vendor:publish', ['--tag' => "rinvex/subscriptions::{$resource}", '--force' => $this->option('force')]); }); diff --git a/packages/laravel-subscriptions/src/Console/Commands/RollbackCommand.php b/packages/laravel-subscriptions/src/Console/Commands/RollbackCommand.php index fa06fec..ae85dda 100644 --- a/packages/laravel-subscriptions/src/Console/Commands/RollbackCommand.php +++ b/packages/laravel-subscriptions/src/Console/Commands/RollbackCommand.php @@ -6,7 +6,7 @@ use Illuminate\Console\Command; -class RollbackCommand extends Command +final class RollbackCommand extends Command { /** * The name and signature of the console command. diff --git a/packages/laravel-subscriptions/src/Models/Plan.php b/packages/laravel-subscriptions/src/Models/Plan.php index bf79d93..299262f 100755 --- a/packages/laravel-subscriptions/src/Models/Plan.php +++ b/packages/laravel-subscriptions/src/Models/Plan.php @@ -15,66 +15,13 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Factories\HasFactory; -/** - * Rinvex\Subscriptions\Models\Plan. - * - * @property int $id - * @property string $slug - * @property array $name - * @property array $description - * @property bool $is_active - * @property float $price - * @property float $signup_fee - * @property string $currency - * @property int $trial_period - * @property string $trial_interval - * @property int $invoice_period - * @property string $invoice_interval - * @property int $grace_period - * @property string $grace_interval - * @property int $prorate_day - * @property int $prorate_period - * @property int $prorate_extend_due - * @property int $active_subscribers_limit - * @property int $sort_order - * @property \Carbon\Carbon|null $created_at - * @property \Carbon\Carbon|null $updated_at - * @property \Carbon\Carbon|null $deleted_at - * @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Subscriptions\Models\PlanFeature[] $features - * @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Subscriptions\Models\PlanSubscription[] $subscriptions - * - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan ordered($direction = 'asc') - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereActiveSubscribersLimit($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereCurrency($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereDeletedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereDescription($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereGraceInterval($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereGracePeriod($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereInvoiceInterval($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereInvoicePeriod($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereIsActive($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereName($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan wherePrice($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProrateDay($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProrateExtendDue($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereProratePeriod($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSignupFee($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSlug($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereSortOrder($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereTrialInterval($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereTrialPeriod($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\Plan whereUpdatedAt($value) - * @mixin \Eloquent - */ class Plan extends Model implements Sortable { - use HasSlug; use HasFactory; + use HasSlug; + use HasTranslations; use SoftDeletes; use SortableTrait; - use HasTranslations; use ValidatingTrait; /** @@ -177,7 +124,7 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.subscriptions.tables.plans')); $this->mergeRules([ 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plans').',slug', - 'name' => 'required|string|strip_tags|max:150', + 'name' => 'required|string|max:150', 'description' => 'nullable|string|max:32768', 'is_active' => 'sometimes|boolean', 'price' => 'required|numeric', @@ -202,11 +149,11 @@ public function __construct(array $attributes = []) /** * {@inheritdoc} */ - protected static function boot() + protected static function boot(): void { parent::boot(); - static::deleted(function ($plan) { + static::deleted(function ($plan): void { $plan->features()->delete(); $plan->planSubscriptions()->delete(); }); @@ -220,9 +167,9 @@ protected static function boot() public function getSlugOptions(): SlugOptions { return SlugOptions::create() - ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('name') - ->saveSlugsTo('slug'); + ->doNotGenerateSlugsOnUpdate() + ->generateSlugsFrom('name') + ->saveSlugsTo('slug'); } /** diff --git a/packages/laravel-subscriptions/src/Models/PlanFeature.php b/packages/laravel-subscriptions/src/Models/PlanFeature.php index 0f1e68c..2d3f6d9 100755 --- a/packages/laravel-subscriptions/src/Models/PlanFeature.php +++ b/packages/laravel-subscriptions/src/Models/PlanFeature.php @@ -18,48 +18,14 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Factories\HasFactory; -/** - * Rinvex\Subscriptions\Models\PlanFeature. - * - * @property int $id - * @property int $plan_id - * @property string $slug - * @property array $title - * @property array $description - * @property string $value - * @property int $resettable_period - * @property string $resettable_interval - * @property int $sort_order - * @property \Carbon\Carbon|null $created_at - * @property \Carbon\Carbon|null $updated_at - * @property \Carbon\Carbon|null $deleted_at - * @property-read \Rinvex\Subscriptions\Models\Plan $plan - * @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage[] $usage - * - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature byPlanId($planId) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature ordered($direction = 'asc') - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereDeletedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereDescription($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereTitle($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature wherePlanId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereResettableInterval($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereResettablePeriod($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereSlug($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereSortOrder($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereUpdatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanFeature whereValue($value) - * @mixin \Eloquent - */ class PlanFeature extends Model implements Sortable { - use HasSlug; + use BelongsToPlan; use HasFactory; + use HasSlug; + use HasTranslations; use SoftDeletes; - use BelongsToPlan; use SortableTrait; - use HasTranslations; use ValidatingTrait; /** @@ -142,7 +108,7 @@ public function __construct(array $attributes = []) $this->mergeRules([ 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_features').',slug', - 'name' => 'required|string|strip_tags|max:150', + 'name' => 'required|string|max:150', 'description' => 'nullable|string|max:32768', 'value' => 'required|string', 'resettable_period' => 'sometimes|integer', @@ -156,11 +122,11 @@ public function __construct(array $attributes = []) /** * {@inheritdoc} */ - protected static function boot() + protected static function boot(): void { parent::boot(); - static::deleted(function ($plan_feature) { + static::deleted(function ($plan_feature): void { $plan_feature->usage()->delete(); }); } @@ -173,9 +139,9 @@ protected static function boot() public function getSlugOptions(): SlugOptions { return SlugOptions::create() - ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('name') - ->saveSlugsTo('slug'); + ->doNotGenerateSlugsOnUpdate() + ->generateSlugsFrom('name') + ->saveSlugsTo('slug'); } /** diff --git a/packages/laravel-subscriptions/src/Models/PlanSubscription.php b/packages/laravel-subscriptions/src/Models/PlanSubscription.php index d166502..ca85d0b 100755 --- a/packages/laravel-subscriptions/src/Models/PlanSubscription.php +++ b/packages/laravel-subscriptions/src/Models/PlanSubscription.php @@ -19,59 +19,15 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Eloquent; -/** - * Rinvex\Subscriptions\Models\PlanSubscription. - * - * @property int $id - * @property int $subscriber_id - * @property string $subscriber_type - * @property int $plan_id - * @property string $slug - * @property array $title - * @property array $description - * @property \Carbon\Carbon|null $trial_ends_at - * @property \Carbon\Carbon|null $starts_at - * @property \Carbon\Carbon|null $ends_at - * @property \Carbon\Carbon|null $cancels_at - * @property \Carbon\Carbon|null $canceled_at - * @property \Carbon\Carbon|null $created_at - * @property \Carbon\Carbon|null $updated_at - * @property \Carbon\Carbon|null $deleted_at - * @property-read \Rinvex\Subscriptions\Models\Plan $plan - * @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage[] $usage - * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $subscriber - * - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription byPlanId($planId) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription findEndedPeriod() - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription findEndedTrial() - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription findEndingPeriod($dayRange = 3) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription findEndingTrial($dayRange = 3) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription ofSubscriber(\Illuminate\Database\Eloquent\Model $subscriber) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereCanceledAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereCancelsAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereDeletedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereDescription($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereEndsAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereTitle($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription wherePlanId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereSlug($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereStartsAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereTrialEndsAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereUpdatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereSubscriberId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscription whereSubscriberType($value) - * @mixin \Eloquent - */ class PlanSubscription extends Model { - use HasSlug; - use HasFactory; - use SoftDeletes; use BelongsToPlan; + use HasFactory; + use HasSlug; use HasTranslations; + use SoftDeletes; use ValidatingTrait; /** @@ -149,12 +105,12 @@ public function __construct(array $attributes = []) { $this->setTable(config('rinvex.subscriptions.tables.plan_subscriptions')); $this->mergeRules([ - 'name' => 'required|string|strip_tags|max:150', + 'name' => 'required|string|max:150', 'description' => 'nullable|string|max:32768', 'slug' => 'required|alpha_dash|max:150|unique:'.config('rinvex.subscriptions.tables.plan_subscriptions').',slug', 'plan_id' => 'required|integer|exists:'.config('rinvex.subscriptions.tables.plans').',id', 'subscriber_id' => 'required|integer', - 'subscriber_type' => 'required|string|strip_tags|max:150', + 'subscriber_type' => 'required|string|max:150', 'trial_ends_at' => 'nullable|date', 'starts_at' => 'required|date', 'ends_at' => 'required|date', @@ -168,17 +124,17 @@ public function __construct(array $attributes = []) /** * {@inheritdoc} */ - protected static function boot() + protected static function boot(): void { parent::boot(); - static::validating(function (self $model) { - if (! $model->starts_at || ! $model->ends_at) { + static::validating(function (self $model): void { + if ( ! $model->starts_at || ! $model->ends_at) { $model->setNewPeriod(); } }); - static::deleted(function ($subscription) { + static::deleted(function ($subscription): void { $subscription->usage()->delete(); }); } @@ -191,9 +147,9 @@ protected static function boot() public function getSlugOptions(): SlugOptions { return SlugOptions::create() - ->doNotGenerateSlugsOnUpdate() - ->generateSlugsFrom('name') - ->saveSlugsTo('slug'); + ->doNotGenerateSlugsOnUpdate() + ->generateSlugsFrom('name') + ->saveSlugsTo('slug'); } /** @@ -314,7 +270,7 @@ public function changePlan(Plan $plan) /** * Renew subscription period. * - * @throws \LogicException + * @throws LogicException * * @return $this */ @@ -326,7 +282,7 @@ public function renew() $subscription = $this; - DB::transaction(function () use ($subscription) { + DB::transaction(function () use ($subscription): void { // Clear usage data $subscription->usage()->delete(); @@ -466,7 +422,7 @@ public function recordFeatureUsage(string $featureSlug, int $uses = 1, bool $inc if ($feature->resettable_period) { // Set expiration date when the usage record is new or doesn't have one. - if (is_null($usage->valid_until)) { + if (null === $usage->valid_until) { // Set date from subscription creation date so the reset // period match the period specified by the subscription's plan. $usage->valid_until = $feature->getResetDate($this->created_at); @@ -497,7 +453,7 @@ public function reduceFeatureUsage(string $featureSlug, int $uses = 1): ?PlanSub { $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); - if (is_null($usage)) { + if (null === $usage) { return null; } @@ -520,13 +476,13 @@ public function canUseFeature(string $featureSlug): bool $featureValue = $this->getFeatureValue($featureSlug); $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); - if ($featureValue === 'true') { + if ('true' === $featureValue) { return true; } // If the feature value is zero, let's return false since // there's no uses available. (useful to disable countable features) - if (! $usage || $usage->expired() || is_null($featureValue) || $featureValue === '0' || $featureValue === 'false') { + if ( ! $usage || $usage->expired() || null === $featureValue || '0' === $featureValue || 'false' === $featureValue) { return false; } @@ -545,7 +501,7 @@ public function getFeatureUsage(string $featureSlug): int { $usage = $this->usage()->byFeatureSlug($featureSlug)->first(); - return (! $usage || $usage->expired()) ? 0 : $usage->used; + return ( ! $usage || $usage->expired()) ? 0 : $usage->used; } /** diff --git a/packages/laravel-subscriptions/src/Models/PlanSubscriptionUsage.php b/packages/laravel-subscriptions/src/Models/PlanSubscriptionUsage.php index 4c7123f..cbb6ea3 100755 --- a/packages/laravel-subscriptions/src/Models/PlanSubscriptionUsage.php +++ b/packages/laravel-subscriptions/src/Models/PlanSubscriptionUsage.php @@ -12,31 +12,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Factories\HasFactory; -/** - * Rinvex\Subscriptions\Models\PlanSubscriptionUsage. - * - * @property int $id - * @property int $subscription_id - * @property int $feature_id - * @property int $used - * @property \Carbon\Carbon|null $valid_until - * @property \Carbon\Carbon|null $created_at - * @property \Carbon\Carbon|null $updated_at - * @property \Carbon\Carbon|null $deleted_at - * @property-read \Rinvex\Subscriptions\Models\PlanFeature $feature - * @property-read \Rinvex\Subscriptions\Models\PlanSubscription $subscription - * - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage byFeatureSlug($featureSlug) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereDeletedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereFeatureId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereSubscriptionId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereUpdatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereUsed($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Subscriptions\Models\PlanSubscriptionUsage whereValidUntil($value) - * @mixin \Eloquent - */ class PlanSubscriptionUsage extends Model { use HasFactory; @@ -147,7 +122,7 @@ public function scopeByFeatureSlug(Builder $builder, string $featureSlug): Build */ public function expired(): bool { - if (is_null($this->valid_until)) { + if (null === $this->valid_until) { return false; } diff --git a/packages/laravel-subscriptions/src/Providers/SubscriptionsServiceProvider.php b/packages/laravel-subscriptions/src/Providers/SubscriptionsServiceProvider.php index abc02d2..345c53e 100755 --- a/packages/laravel-subscriptions/src/Providers/SubscriptionsServiceProvider.php +++ b/packages/laravel-subscriptions/src/Providers/SubscriptionsServiceProvider.php @@ -14,7 +14,7 @@ use Rinvex\Subscriptions\Console\Commands\PublishCommand; use Rinvex\Subscriptions\Console\Commands\RollbackCommand; -class SubscriptionsServiceProvider extends ServiceProvider +final class SubscriptionsServiceProvider extends ServiceProvider { use ConsoleTools; @@ -24,9 +24,9 @@ class SubscriptionsServiceProvider extends ServiceProvider * @var array */ protected $commands = [ - MigrateCommand::class => 'command.rinvex.subscriptions.migrate', - PublishCommand::class => 'command.rinvex.subscriptions.publish', - RollbackCommand::class => 'command.rinvex.subscriptions.rollback', + MigrateCommand::class, + PublishCommand::class, + RollbackCommand::class, ]; /** @@ -36,7 +36,7 @@ class SubscriptionsServiceProvider extends ServiceProvider */ public function register(): void { - $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.subscriptions'); + $this->mergeConfigFrom(realpath(__DIR__ . '/../../config/config.php'), 'rinvex.subscriptions'); // Bind eloquent models to IoC container $this->registerModels([ @@ -47,7 +47,7 @@ public function register(): void ]); // Register console commands - $this->registerCommands($this->commands); + $this->commands($this->commands); } /** @@ -58,8 +58,15 @@ public function register(): void public function boot(): void { // Publish Resources - $this->publishesConfig('rinvex/laravel-subscriptions'); - $this->publishesMigrations('rinvex/laravel-subscriptions'); - ! $this->autoloadMigrations('rinvex/laravel-subscriptions') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); + $this->publishes([ + __DIR__ . '/../config/config.php' => config_path('rinvex.subscriptions.php') + ], 'rinvex.subscriptions-config'); + + $this->publishes([ + __DIR__ . '/../database/migrations/' => database_path('migrations/rinvex') + ], 'rinvex.subscriptions-migrations'); + + //$this->publishesMigrations('rinvex/laravel-subscriptions'); + //! $this->autoloadMigrations('rinvex/laravel-subscriptions') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); } } diff --git a/packages/laravel-subscriptions/src/Services/Period.php b/packages/laravel-subscriptions/src/Services/Period.php index cbd0665..d133cd2 100755 --- a/packages/laravel-subscriptions/src/Services/Period.php +++ b/packages/laravel-subscriptions/src/Services/Period.php @@ -6,35 +6,35 @@ use Carbon\Carbon; -class Period +final class Period { /** * Starting date of the period. * * @var string */ - protected $start; + private $start; /** * Ending date of the period. * * @var string */ - protected $end; + private $end; /** * Interval. * * @var string */ - protected $interval; + private $interval; /** * Interval count. * * @var int */ - protected $period = 1; + private $period = 1; /** * Create a new Period instance. @@ -51,7 +51,7 @@ public function __construct($interval = 'month', $count = 1, $start = '') if (empty($start)) { $this->start = Carbon::now(); - } elseif (! $start instanceof Carbon) { + } elseif ( ! $start instanceof Carbon) { $this->start = new Carbon($start); } else { $this->start = $start; diff --git a/packages/laravel-subscriptions/src/Traits/HasPlanSubscriptions.php b/packages/laravel-subscriptions/src/Traits/HasPlanSubscriptions.php index 2a6fbab..10add99 100755 --- a/packages/laravel-subscriptions/src/Traits/HasPlanSubscriptions.php +++ b/packages/laravel-subscriptions/src/Traits/HasPlanSubscriptions.php @@ -31,9 +31,9 @@ abstract public function morphMany($related, $name, $type = null, $id = null, $l * * @return void */ - protected static function bootHasSubscriptions() + protected static function bootHasSubscriptions(): void { - static::deleted(function ($plan) { + static::deleted(function ($plan): void { $plan->planSubscriptions()->delete(); }); } diff --git a/packages/laravel-support/src/Providers/SupportServiceProvider.php b/packages/laravel-support/src/Providers/SupportServiceProvider.php index b7cf116..f20ba86 100644 --- a/packages/laravel-support/src/Providers/SupportServiceProvider.php +++ b/packages/laravel-support/src/Providers/SupportServiceProvider.php @@ -10,31 +10,23 @@ use Rinvex\Support\Validators\UniqueWithValidator; use Illuminate\Support\Facades\Validator as ValidatorFacade; -class SupportServiceProvider extends ServiceProvider +final class SupportServiceProvider extends ServiceProvider { /** * {@inheritdoc} */ - public function boot() + public function boot(): void { // Add strip_tags validation rule - Validator::extend('strip_tags', function ($attribute, $value) { - return is_string($value) && strip_tags($value) === $value; - }, trans('validation.invalid_strip_tags')); + Validator::extend('strip_tags', fn ($attribute, $value) => is_string($value) && strip_tags($value) === $value, trans('validation.invalid_strip_tags')); // Add time offset validation rule - Validator::extend('timeoffset', function ($attribute, $value) { - return array_key_exists($value, timeoffsets()); - }, trans('validation.invalid_timeoffset')); + Validator::extend('timeoffset', fn ($attribute, $value) => array_key_exists($value, timeoffsets()), trans('validation.invalid_timeoffset')); - Collection::macro('similar', function (Collection $newCollection) { - return $newCollection->diff($this)->isEmpty() && $this->diff($newCollection)->isEmpty(); - }); + Collection::macro('similar', fn (Collection $newCollection) => $newCollection->diff($this)->isEmpty() && $this->diff($newCollection)->isEmpty()); // Add support for unique_with validator ValidatorFacade::extend('unique_with', UniqueWithValidator::class.'@validateUniqueWith', trans('validation.unique_with')); - ValidatorFacade::replacer('unique_with', function () { - return call_user_func_array([new UniqueWithValidator(), 'replaceUniqueWith'], func_get_args()); - }); + ValidatorFacade::replacer('unique_with', fn () => call_user_func_array([new UniqueWithValidator(), 'replaceUniqueWith'], func_get_args())); } } diff --git a/packages/laravel-support/src/Support/helpers.php b/packages/laravel-support/src/Support/helpers.php index 43d4674..37c9c7c 100644 --- a/packages/laravel-support/src/Support/helpers.php +++ b/packages/laravel-support/src/Support/helpers.php @@ -2,7 +2,7 @@ declare(strict_types=1); -if (! function_exists('mimetypes')) { +if ( ! function_exists('mimetypes')) { /** * Get valid mime types. * @@ -17,7 +17,7 @@ function mimetypes() } } -if (! function_exists('timezones')) { +if ( ! function_exists('timezones')) { /** * Get valid timezones. * @@ -29,7 +29,7 @@ function timezones() } } -if (! function_exists('timeoffsets')) { +if ( ! function_exists('timeoffsets')) { /** * Get valid time offsets. * @@ -80,7 +80,7 @@ function timeoffsets() } } -if (! function_exists('array_search_recursive')) { +if ( ! function_exists('array_search_recursive')) { /** * Recursively searches the array for a given value and returns the corresponding key if successful. * @@ -93,7 +93,7 @@ function array_search_recursive($needle, $haystack) { foreach ($haystack as $key => $value) { $current_key = $key; - if ($needle === $value || (is_array($value) && array_search_recursive($needle, $value) !== false)) { + if ($needle === $value || (is_array($value) && false !== array_search_recursive($needle, $value))) { return $current_key; } } @@ -102,7 +102,7 @@ function array_search_recursive($needle, $haystack) } } -if (! function_exists('array_trim_recursive')) { +if ( ! function_exists('array_trim_recursive')) { /** * Recursively trim elements of the given array. * @@ -121,7 +121,7 @@ function array_trim_recursive($values, $charlist = " \t\n\r\0\x0B") } } -if (! function_exists('array_diff_assoc_recursive')) { +if ( ! function_exists('array_diff_assoc_recursive')) { /** * Computes the recursive difference of arrays with additional index check. * @@ -137,12 +137,12 @@ function array_diff_assoc_recursive(array $array1, array $array2, bool $onlyDiff foreach ($array1 as $key => $value) { if (is_array($value)) { - if (! isset($array2[$key]) || ! is_array($array2[$key])) { + if ( ! isset($array2[$key]) || ! is_array($array2[$key])) { $difference[$key] = $value; - } elseif (! empty($subDiff = array_diff_assoc_recursive($value, $array2[$key]))) { + } elseif ( ! empty($subDiff = array_diff_assoc_recursive($value, $array2[$key]))) { $difference[$key] = $onlyDiff ? $subDiff : array_merge($array2[$key], $subDiff); } - } elseif (! array_key_exists($key, $array2) || $array2[$key] !== $value) { + } elseif ( ! array_key_exists($key, $array2) || $array2[$key] !== $value) { $difference[$key] = $value; } } @@ -151,7 +151,7 @@ function array_diff_assoc_recursive(array $array1, array $array2, bool $onlyDiff } } -if (! function_exists('get_str_contains')) { +if ( ! function_exists('get_str_contains')) { /** * Get str contains the given string. * @@ -163,7 +163,7 @@ function array_diff_assoc_recursive(array $array1, array $array2, bool $onlyDiff function get_str_contains($haystack, $needles) { foreach ((array) $needles as $needle) { - if (! empty($needle) && mb_strpos($haystack, $needle) !== false) { + if ( ! empty($needle) && false !== mb_strpos($haystack, $needle)) { return $needle; } } @@ -172,7 +172,7 @@ function get_str_contains($haystack, $needles) } } -if (! function_exists('get_str_endswith')) { +if ( ! function_exists('get_str_endswith')) { /** * Get str ends with the given string. * @@ -184,7 +184,7 @@ function get_str_contains($haystack, $needles) function get_str_endswith($haystack, $needles) { foreach ((array) $needles as $needle) { - if (! empty($needle) && mb_substr($haystack, -mb_strlen($needle)) === (string) $needle) { + if ( ! empty($needle) && mb_substr($haystack, -mb_strlen($needle)) === (string) $needle) { return $needle; } } diff --git a/packages/laravel-support/src/Traits/ConsoleTools.php b/packages/laravel-support/src/Traits/ConsoleTools.php index 1a5a185..e6ed450 100644 --- a/packages/laravel-support/src/Traits/ConsoleTools.php +++ b/packages/laravel-support/src/Traits/ConsoleTools.php @@ -20,9 +20,9 @@ trait ConsoleTools * * @return void */ - protected function loadViewsFrom($path, $namespace) + protected function loadViewsFrom($path, $namespace): void { - $this->callAfterResolving('view', function ($view) use ($path, $namespace) { + $this->callAfterResolving('view', function ($view) use ($path, $namespace): void { $view->prependNamespace($namespace, $path); if (isset($this->app->config['view']['paths']) && is_array($this->app->config['view']['paths'])) { @@ -58,7 +58,7 @@ protected function publishMigrationsFrom(string $path, string $namespace): void $migrations = collect($stubs)->flatMap(function ($migration) use ($existing, $namespace) { $sequence = mb_substr(basename($migration), 0, 17); - $match = collect($existing)->first(fn ($item, $key) => mb_strpos($item, str_replace($sequence, '', basename($migration))) !== false); + $match = collect($existing)->first(fn ($item, $key) => false !== mb_strpos($item, str_replace($sequence, '', basename($migration)))); return [$migration => $this->app->databasePath('migrations/'.$namespace.'/'.($match ? basename($match) : date('Y_m_d_His', time() + mb_substr($sequence, -6)).str_replace($sequence, '', basename($migration))))]; })->toArray(); diff --git a/packages/laravel-support/src/Traits/HasSlug.php b/packages/laravel-support/src/Traits/HasSlug.php index 7679c5c..7764c60 100644 --- a/packages/laravel-support/src/Traits/HasSlug.php +++ b/packages/laravel-support/src/Traits/HasSlug.php @@ -14,13 +14,13 @@ trait HasSlug /** * Boot the trait. */ - protected static function bootHasSlug() + protected static function bootHasSlug(): void { // Auto generate slugs early before validation - static::validating(function (Model $model) { + static::validating(function (Model $model): void { if ($model->exists && $model->getSlugOptions()->generateSlugsOnUpdate) { $model->generateSlugOnUpdate(); - } elseif (! $model->exists && $model->getSlugOptions()->generateSlugsOnCreate) { + } elseif ( ! $model->exists && $model->getSlugOptions()->generateSlugsOnCreate) { $model->generateSlugOnCreate(); } }); diff --git a/packages/laravel-support/src/Traits/HasTimezones.php b/packages/laravel-support/src/Traits/HasTimezones.php index 0974d2f..c69bce9 100644 --- a/packages/laravel-support/src/Traits/HasTimezones.php +++ b/packages/laravel-support/src/Traits/HasTimezones.php @@ -21,9 +21,7 @@ protected function asDateTime($value) $datetime = $value; $timezone = request()->user()?->timezone; - $thisIsUpdateRequest = Arr::first(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 30), function ($trace) { - return $trace['function'] === 'setAttribute'; - }); + $thisIsUpdateRequest = Arr::first(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 30), fn ($trace) => 'setAttribute' === $trace['function']); if ($thisIsUpdateRequest) { if (is_string($datetime)) { @@ -35,7 +33,7 @@ protected function asDateTime($value) $datetime = parent::asDateTime($datetime); - if (! $timezone || $timezone === config('app.timezone')) { + if ( ! $timezone || $timezone === config('app.timezone')) { return $datetime; } @@ -53,6 +51,6 @@ public function freshTimestamp() $timezone = request()->user()?->timezone; - return (! $timezone || $timezone === config('app.timezone')) ? $now : $now->setTimezone($timezone); + return ( ! $timezone || $timezone === config('app.timezone')) ? $now : $now->setTimezone($timezone); } } diff --git a/packages/laravel-support/src/Traits/HasTranslations.php b/packages/laravel-support/src/Traits/HasTranslations.php index d4caa57..74af5d1 100644 --- a/packages/laravel-support/src/Traits/HasTranslations.php +++ b/packages/laravel-support/src/Traits/HasTranslations.php @@ -20,7 +20,7 @@ trait HasTranslations */ public function getAttributeValue($key) { - if (! $this->isTranslatableAttribute($key)) { + if ( ! $this->isTranslatableAttribute($key)) { return parent::getAttributeValue($key); } @@ -38,16 +38,16 @@ public function getAttributeValue($key) */ public function getTranslations(string $key = null): array { - if ($key !== null) { + if (null !== $key) { $this->guardAgainstNonTranslatableAttribute($key); $value = array_filter( json_decode($this->getAttributes()[$key] ?? '' ?: '{}', true) ?: [], - fn ($value) => $value !== null && $value !== '' + fn ($value) => null !== $value && '' !== $value ); // Inject default translation if none supplied - if (! is_array($value)) { + if ( ! is_array($value)) { $oldValue = $value; if ($this->hasSetMutator($key)) { @@ -78,9 +78,7 @@ public function getTranslations(string $key = null): array */ public function attributesToArray() { - $values = array_map(function ($attribute) { - return $this->getTranslation($attribute, config('app.locale')) ?: null; - }, $keys = $this->getTranslatableAttributes()); + $values = array_map(fn ($attribute) => $this->getTranslation($attribute, config('app.locale')) ?: null, $keys = $this->getTranslatableAttributes()); return array_replace(parent::attributesToArray(), array_combine($keys, $values)); } @@ -92,7 +90,7 @@ public function attributesToArray() * * @return void */ - public function mergeTranslatable($translatable) + public function mergeTranslatable($translatable): void { $this->translatable = array_merge($this->translatable, $translatable); } diff --git a/packages/laravel-support/src/Traits/HashidsTrait.php b/packages/laravel-support/src/Traits/HashidsTrait.php index 470337b..384504b 100644 --- a/packages/laravel-support/src/Traits/HashidsTrait.php +++ b/packages/laravel-support/src/Traits/HashidsTrait.php @@ -6,13 +6,14 @@ use Vinkla\Hashids\Facades\Hashids; use Illuminate\Database\Eloquent\Casts\Attribute; +use Exception; trait HashidsTrait { /** * Get the value of the model's route key. * - * @throws \Exception + * @throws Exception * * @return mixed */ @@ -58,7 +59,7 @@ public function unhashId($value) */ protected function shouldBeHashed(): bool { - $accessareas = app('accessareas')->active()->obscured()->keys()->when($this->obscure, fn($collection) => $collection->merge(collect($this->obscure)->intersect(app('accessareas')->active()->keys()))->unique())->toArray(); + $accessareas = app('accessareas')->active()->obscured()->keys()->when($this->obscure, fn ($collection) => $collection->merge(collect($this->obscure)->intersect(app('accessareas')->active()->keys()))->unique())->toArray(); return in_array(request()->accessarea(), $accessareas) && in_array($this->getRouteKeyName(), config('cortex.foundation.obscure.hashed_keys')); } diff --git a/packages/laravel-support/src/Traits/Macroable.php b/packages/laravel-support/src/Traits/Macroable.php index 16f60e6..1aa4b55 100644 --- a/packages/laravel-support/src/Traits/Macroable.php +++ b/packages/laravel-support/src/Traits/Macroable.php @@ -42,7 +42,7 @@ public function __call($method, $parameters) return $this->forwardCallTo($this->newQuery(), $method, $parameters); } catch (Error|BadMethodCallException $e) { - if ($method !== 'macroableCall') { + if ('macroableCall' !== $method) { return $this->macroableCall($method, $parameters); } } @@ -62,7 +62,7 @@ public static function __callStatic($method, $parameters) // Catch static calls for non-static methods return (new static())->{$method}(...$parameters); } catch (Exception $e) { - if ($method !== 'macroableCallStatic') { + if ('macroableCallStatic' !== $method) { return (new static())::macroableCallStatic($method, $parameters); } } diff --git a/packages/laravel-support/src/Traits/ValidatingTrait.php b/packages/laravel-support/src/Traits/ValidatingTrait.php index 2252ecc..67148b6 100644 --- a/packages/laravel-support/src/Traits/ValidatingTrait.php +++ b/packages/laravel-support/src/Traits/ValidatingTrait.php @@ -6,11 +6,12 @@ use Watson\Validating\Injectors\UniqueWithInjector; use Watson\Validating\ValidatingTrait as BaseValidatingTrait; +use Closure; trait ValidatingTrait { - use UniqueWithInjector; use BaseValidatingTrait; + use UniqueWithInjector; /** * Merge new validation rules with existing validation rules on the model. @@ -29,11 +30,11 @@ public function mergeRules(array $rules) /** * Register a validating event with the dispatcher. * - * @param \Closure|string $callback + * @param Closure|string $callback * * @return void */ - public static function validating($callback) + public static function validating($callback): void { static::registerModelEvent('validating', $callback); } @@ -41,11 +42,11 @@ public static function validating($callback) /** * Register a validated event with the dispatcher. * - * @param \Closure|string $callback + * @param Closure|string $callback * * @return void */ - public static function validated($callback) + public static function validated($callback): void { static::registerModelEvent('validated', $callback); } diff --git a/packages/laravel-support/src/Validators/UniqueWithRuleParser.php b/packages/laravel-support/src/Validators/UniqueWithRuleParser.php index 6e01403..ecaf53e 100644 --- a/packages/laravel-support/src/Validators/UniqueWithRuleParser.php +++ b/packages/laravel-support/src/Validators/UniqueWithRuleParser.php @@ -8,31 +8,31 @@ use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; -class UniqueWithRuleParser +final class UniqueWithRuleParser { - protected $table; + private $table; - protected $connection; + private $connection; - protected $primaryField; + private $primaryField; - protected $primaryValue; + private $primaryValue; - protected $additionalFields; + private $additionalFields; - protected $parsed = false; + private $parsed = false; - protected $ignoreColumn; + private $ignoreColumn; - protected $ignoreValue; + private $ignoreValue; - protected $dataFields; + private $dataFields; - protected $parameters; + private $parameters; - protected $attribute; + private $attribute; - protected $data; + private $data; public function __construct($attribute = null, $value = null, array $parameters = [], array $data = []) { @@ -42,7 +42,7 @@ public function __construct($attribute = null, $value = null, array $parameters $this->data = $data; } - protected function parse() + private function parse(): void { if ($this->parsed) { return; @@ -65,7 +65,7 @@ protected function parse() $this->parseFieldData(); } - protected function parseFieldData() + private function parseFieldData(): void { $this->additionalFields = []; $this->dataFields = [$this->primaryField]; @@ -90,7 +90,7 @@ protected function parseFieldData() continue; } - if (! Arr::has($this->data, $fieldName)) { + if ( ! Arr::has($this->data, $fieldName)) { continue; } @@ -129,7 +129,7 @@ public function getTable() * * @return bool */ - protected function isValidationScoped(Model $model): bool + private function isValidationScoped(Model $model): bool { return $model->isValidationScoped ?? true; } @@ -176,11 +176,11 @@ public function getDataFields() return $this->dataFields; } - protected function parseIgnore() + private function parseIgnore(): void { // Ignore has to be specified as the last parameter $lastParameter = end($this->parameters); - if (! $this->isIgnore($lastParameter)) { + if ( ! $this->isIgnore($lastParameter)) { return; } @@ -193,10 +193,10 @@ protected function parseIgnore() array_pop($this->parameters); } - protected function isIgnore($parameter) + private function isIgnore($parameter) { // An ignore_id can be specified by prefixing with 'ignore:' - if (mb_strpos($parameter, 'ignore:') !== false) { + if (false !== mb_strpos($parameter, 'ignore:')) { return true; } @@ -207,7 +207,7 @@ protected function isIgnore($parameter) return preg_match('/^[1-9][0-9]*$/', $parts[0]); } - protected function parseFieldName($field) + private function parseFieldName($field) { if (preg_match('/^\*\.|\.\*\./', $field)) { // This rule validates multiple times, because a wildcard * was used diff --git a/packages/laravel-support/src/Validators/UniqueWithValidator.php b/packages/laravel-support/src/Validators/UniqueWithValidator.php index ee67902..85e6c37 100644 --- a/packages/laravel-support/src/Validators/UniqueWithValidator.php +++ b/packages/laravel-support/src/Validators/UniqueWithValidator.php @@ -7,7 +7,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; -class UniqueWithValidator +final class UniqueWithValidator { public function validateUniqueWith($attribute, $value, $parameters, $validator) { @@ -22,7 +22,7 @@ public function validateUniqueWith($attribute, $value, $parameters, $validator) $presenceVerifier->setConnection($ruleParser->getConnection()); } - return $presenceVerifier->getCount($ruleParser->getTable(), $ruleParser->getPrimaryField(), $ruleParser->getPrimaryValue(), $ruleParser->getIgnoreValue(), $ruleParser->getIgnoreColumn(), $ruleParser->getAdditionalFields()) === 0; + return 0 === $presenceVerifier->getCount($ruleParser->getTable(), $ruleParser->getPrimaryField(), $ruleParser->getPrimaryValue(), $ruleParser->getIgnoreValue(), $ruleParser->getIgnoreColumn(), $ruleParser->getAdditionalFields()); } public function replaceUniqueWith($message, $attribute, $rule, $parameters, $validator) @@ -39,9 +39,7 @@ public function replaceUniqueWith($message, $attribute, $rule, $parameters, $val } // Check if translator has custom validation attributes for the fields - $fields = array_map(function ($field) use ($customAttributes) { - return Arr::get($customAttributes, $field) ?: str_replace('_', ' ', Str::snake($field)); - }, $fields); + $fields = array_map(fn ($field) => Arr::get($customAttributes, $field) ?: str_replace('_', ' ', Str::snake($field)), $fields); return str_replace(':fields', implode(', ', $fields), $message); } diff --git a/packages/tmp-watson-validating/src/Injectors/UniqueInjector.php b/packages/tmp-watson-validating/src/Injectors/UniqueInjector.php index a0afca8..1ea57e0 100644 --- a/packages/tmp-watson-validating/src/Injectors/UniqueInjector.php +++ b/packages/tmp-watson-validating/src/Injectors/UniqueInjector.php @@ -1,5 +1,7 @@ getModel()->getConnectionName()) !== null)) { + if (( ! str_contains($parameters[0], '.')) && (($connectionName = $this->getModel()->getConnectionName()) !== null)) { $parameters[0] = $connectionName.'.'.$parameters[0]; } // If the field name isn't get, infer it. - if (! isset($parameters[1])) { + if ( ! isset($parameters[1])) { $parameters[1] = $field; } if ($this->exists) { // If the identifier isn't set, infer it. - if (! isset($parameters[2]) || strtolower($parameters[2]) === 'null') { + if ( ! isset($parameters[2]) || 'null' === mb_strtolower($parameters[2])) { $parameters[2] = $this->getModel()->getKey(); } // If the primary key isn't set, infer it. - if (! isset($parameters[3])) { + if ( ! isset($parameters[3])) { $parameters[3] = $this->getModel()->getKeyName(); } // If the additional where clause isn't set, infer it. // Example: unique:users,email,123,id,username,NULL foreach ($parameters as $key => $parameter) { - if (strtolower((string) $parameter) === 'null') { + if ('null' === mb_strtolower((string) $parameter)) { // Maintain NULL as string in case the model returns a null value $value = $this->getModel()->{$parameters[$key - 1]}; - $parameters[$key] = is_null($value) ? 'NULL' : $value; + $parameters[$key] = null === $value ? 'NULL' : $value; } } } - return 'unique:' . implode(',', $parameters); + return 'unique:'.implode(',', $parameters); } } diff --git a/packages/tmp-watson-validating/src/Injectors/UniqueWithInjector.php b/packages/tmp-watson-validating/src/Injectors/UniqueWithInjector.php index 2412c2f..429cedc 100644 --- a/packages/tmp-watson-validating/src/Injectors/UniqueWithInjector.php +++ b/packages/tmp-watson-validating/src/Injectors/UniqueWithInjector.php @@ -1,5 +1,7 @@ getValidating()) { // Fire the namespaced validating event and prevent validation // if it returns a value. - if ($this->fireValidatingEvent($model, $event) !== null) { + if (null !== $this->fireValidatingEvent($model, $event)) { return; } - if ($model->isValid() === false) { + if (false === $model->isValid()) { // Fire the validating failed event. $this->fireValidatedEvent($model, 'failed'); @@ -72,7 +73,7 @@ protected function performValidation(Model $model, $event) * @param string $event * @return mixed */ - protected function fireValidatingEvent(Model $model, $event) + private function fireValidatingEvent(Model $model, $event) { return Event::until("eloquent.validating: ".get_class($model), [$model, $event]); } @@ -84,7 +85,7 @@ protected function fireValidatingEvent(Model $model, $event) * @param string $status * @return void */ - protected function fireValidatedEvent(Model $model, $status) + private function fireValidatedEvent(Model $model, $status): void { Event::dispatch("eloquent.validated: ".get_class($model), [$model, $status]); } diff --git a/packages/tmp-watson-validating/src/ValidatingTrait.php b/packages/tmp-watson-validating/src/ValidatingTrait.php index 816cc7b..511c395 100644 --- a/packages/tmp-watson-validating/src/ValidatingTrait.php +++ b/packages/tmp-watson-validating/src/ValidatingTrait.php @@ -1,5 +1,7 @@ validating; } - /** + /** * Set whether the model should attempt validation on saving. * * @param bool $value * @return void */ - public function setValidating($value) + public function setValidating($value): void { - $this->validating = (boolean) $value; + $this->validating = (bool) $value; } /** @@ -73,7 +76,7 @@ public function setValidating($value) */ public function getThrowValidationExceptions() { - return isset($this->throwValidationExceptions) ? $this->throwValidationExceptions : false; + return $this->throwValidationExceptions ?? false; } /** @@ -84,9 +87,9 @@ public function getThrowValidationExceptions() * @return void * @throws InvalidArgumentException */ - public function setThrowValidationExceptions($value) + public function setThrowValidationExceptions($value): void { - $this->throwValidationExceptions = (boolean) $value; + $this->throwValidationExceptions = (bool) $value; } /** @@ -97,7 +100,7 @@ public function setThrowValidationExceptions($value) */ public function getInjectUniqueIdentifier() { - return isset($this->injectUniqueIdentifier) ? $this->injectUniqueIdentifier : true; + return $this->injectUniqueIdentifier ?? true; } /** @@ -108,9 +111,9 @@ public function getInjectUniqueIdentifier() * @return void * @throws InvalidArgumentException */ - public function setInjectUniqueIdentifier($value) + public function setInjectUniqueIdentifier($value): void { - $this->injectUniqueIdentifier = (boolean) $value; + $this->injectUniqueIdentifier = (bool) $value; } /** @@ -153,7 +156,7 @@ public function getModelAttributes() */ public function getValidationMessages() { - return isset($this->validationMessages) ? $this->validationMessages : []; + return $this->validationMessages ?? []; } /** @@ -164,7 +167,7 @@ public function getValidationMessages() */ protected function modelValidationMessages() { - return (new static)->getValidationMessages(); + return (new static())->getValidationMessages(); } /** @@ -174,7 +177,7 @@ protected function modelValidationMessages() */ public function getValidationAttributeNames() { - return isset($this->validationAttributeNames) ? $this->validationAttributeNames : []; + return $this->validationAttributeNames ?? []; } /** @@ -185,7 +188,7 @@ public function getValidationAttributeNames() */ protected function modelValidationAttributeNames() { - return (new static)->getValidationAttributeNames(); + return (new static())->getValidationAttributeNames(); } /** @@ -194,7 +197,7 @@ protected function modelValidationAttributeNames() * @param array $attributeNames * @return void */ - public function setValidationAttributeNames(array $attributeNames = null) + public function setValidationAttributeNames(array $attributeNames = null): void { $this->validationAttributeNames = $attributeNames; } @@ -206,7 +209,7 @@ public function setValidationAttributeNames(array $attributeNames = null) */ public function getRules() { - return isset($this->rules) ? $this->rules : []; + return $this->rules ?? []; } /** @@ -236,7 +239,7 @@ protected function rules() * @param array $rules * @return void */ - public function setRules(array $rules = null) + public function setRules(array $rules = null): void { $this->rules = $rules; } @@ -248,7 +251,7 @@ public function setRules(array $rules = null) */ public function getErrors() { - return $this->validationErrors ?: new MessageBag; + return $this->validationErrors ?: new MessageBag(); } /** @@ -257,7 +260,7 @@ public function getErrors() * @param \Illuminate\Support\MessageBag $validationErrors * @return void */ - public function setErrors(MessageBag $validationErrors) + public function setErrors(MessageBag $validationErrors): void { $this->validationErrors = $validationErrors; } @@ -324,7 +327,7 @@ public function forceSave(array $options = []) * * @param array $options * @return bool - * @throws \Throwable + * @throws Throwable */ public function saveOrFail(array $options = []) { @@ -340,7 +343,7 @@ public function saveOrFail(array $options = []) * * @param array $options * @return bool - * @throws \Throwable + * @throws Throwable */ public function parentSaveOrFail($options) { @@ -374,7 +377,7 @@ public function getValidator() * * @param \Illuminate\Validation\Factory $validator */ - public function setValidator(Factory $validator) + public function setValidator(Factory $validator): void { $this->validator = $validator; } @@ -430,7 +433,7 @@ protected function performValidation($rules = []) * * @throws \Watson\Validating\ValidationException */ - public function throwValidationException() + public function throwValidationException(): void { $validator = $this->makeValidator($this->getRules()); @@ -443,7 +446,7 @@ public function throwValidationException() * * @return void */ - public function updateRulesUniques() + public function updateRulesUniques(): void { $rules = $this->getRules(); @@ -469,18 +472,18 @@ protected function injectUniqueIdentifierToRules(array $rules) $ruleset = is_string($ruleset) ? explode('|', $ruleset) : $ruleset; foreach ($ruleset as &$rule) { - // Only treat stringy definitions and leave Rule classes and Closures as-is. - if (is_string($rule)) { - $parameters = explode(':', $rule); - $validationRule = array_shift($parameters); - - if ($method = $this->getUniqueIdentifierInjectorMethod($validationRule)) { - $rule = call_user_func_array( - [$this, $method], - [explode(',', head($parameters)), $field] - ); - } - } + // Only treat stringy definitions and leave Rule classes and Closures as-is. + if (is_string($rule)) { + $parameters = explode(':', $rule); + $validationRule = array_shift($parameters); + + if ($method = $this->getUniqueIdentifierInjectorMethod($validationRule)) { + $rule = call_user_func_array( + [$this, $method], + [explode(',', head($parameters)), $field] + ); + } + } } } @@ -496,7 +499,7 @@ protected function injectUniqueIdentifierToRules(array $rules) */ protected function getUniqueIdentifierInjectorMethod($validationRule) { - $method = 'prepare' . Str::studly($validationRule) . 'Rule'; + $method = 'prepare'.Str::studly($validationRule).'Rule'; return method_exists($this, $method) ? $method : false; } diff --git a/packages/tmp-watson-validating/src/ValidationException.php b/packages/tmp-watson-validating/src/ValidationException.php index d2e5222..413b4ef 100644 --- a/packages/tmp-watson-validating/src/ValidationException.php +++ b/packages/tmp-watson-validating/src/ValidationException.php @@ -1,5 +1,7 @@ trait = Mockery::mock(UniqueValidatingStub::class)->makePartial(); } - public function testUpdateRulesUniquesWithoutUniques() + public function testUpdateRulesUniquesWithoutUniques(): void { $this->trait->setRules(['user_id' => ['required']]); @@ -25,7 +27,7 @@ public function testUpdateRulesUniquesWithoutUniques() $this->assertEquals(['user_id' => ['required']], $result); } - public function testUpdateRulesUniquesWithUniquesInfersAttributes() + public function testUpdateRulesUniquesWithUniquesInfersAttributes(): void { $this->trait->exists = true; @@ -40,7 +42,7 @@ public function testUpdateRulesUniquesWithUniquesInfersAttributes() $this->assertEquals(['user_id' => ['unique:sqlite.users,user_id,1,id']], $result); } - public function testGetPreparedRulesUniques() + public function testGetPreparedRulesUniques(): void { $this->trait->exists = true; @@ -53,7 +55,7 @@ public function testGetPreparedRulesUniques() $this->assertEquals(['user_id' => ['unique:sqlite.users,user_id,1,id']], $result); } - public function testUpdateRulesUniquesWithUniquesAndAdditionalWhereClauseInfersAttributes() + public function testUpdateRulesUniquesWithUniquesAndAdditionalWhereClauseInfersAttributes(): void { $this->trait->exists = true; @@ -68,7 +70,7 @@ public function testUpdateRulesUniquesWithUniquesAndAdditionalWhereClauseInfersA $this->assertEquals(['user_id' => ['unique:sqlite.users,user_id,1,id,username,test']], $result); } - public function testUpdateRulesUniquesWithUniquesAndAdditionalWhereClauseInfersAttributesMaintainingNULLValue() + public function testUpdateRulesUniquesWithUniquesAndAdditionalWhereClauseInfersAttributesMaintainingNULLValue(): void { $this->trait->exists = true; @@ -83,7 +85,7 @@ public function testUpdateRulesUniquesWithUniquesAndAdditionalWhereClauseInfersA $this->assertEquals(['user_id' => ['unique:sqlite.users,user_id,1,id,deleted,NULL']], $result); } - public function testUpdateRulesUniquesWithNonPersistedModelInfersAttributes() + public function testUpdateRulesUniquesWithNonPersistedModelInfersAttributes(): void { $this->trait->shouldReceive('getTable')->andReturn('users'); @@ -96,7 +98,7 @@ public function testUpdateRulesUniquesWithNonPersistedModelInfersAttributes() $this->assertEquals(['user_id' => ['unique:sqlite.users,user_id']], $result); } - public function testUpdateRulesUniquesWorksWithMultipleUniques() + public function testUpdateRulesUniquesWorksWithMultipleUniques(): void { $this->trait->shouldReceive('getTable')->andReturn('users'); @@ -115,7 +117,7 @@ public function testUpdateRulesUniquesWorksWithMultipleUniques() ], $result); } - public function testUpdateRulesUniquesDoesNotOverrideProvidedParameters() + public function testUpdateRulesUniquesDoesNotOverrideProvidedParameters(): void { $this->trait->setRules(['users' => 'unique:foo,bar,5,bat']); @@ -127,7 +129,7 @@ public function testUpdateRulesUniquesDoesNotOverrideProvidedParameters() } } -class UniqueValidatingStub extends \Illuminate\Database\Eloquent\Model +final class UniqueValidatingStub extends \Illuminate\Database\Eloquent\Model { use \Watson\Validating\ValidatingTrait; diff --git a/packages/tmp-watson-validating/tests/Injectors/UniqueWithInjectorTest.php b/packages/tmp-watson-validating/tests/Injectors/UniqueWithInjectorTest.php index a7aabc5..0a1abd1 100644 --- a/packages/tmp-watson-validating/tests/Injectors/UniqueWithInjectorTest.php +++ b/packages/tmp-watson-validating/tests/Injectors/UniqueWithInjectorTest.php @@ -1,11 +1,13 @@ trait = Mockery::mock(UniqueWithValidatingStub::class)->makePartial(); } - public function testUpdateRulesUniquesUniqueWithWithUniquesInfersAttributes() + public function testUpdateRulesUniquesUniqueWithWithUniquesInfersAttributes(): void { $this->trait->exists = true; @@ -29,7 +31,7 @@ public function testUpdateRulesUniquesUniqueWithWithUniquesInfersAttributes() $this->assertEquals(['first_name' => ['unique_with:users,last_name,1']], $result); } - public function testUpdateRulesUniquesUniqueWithDoesNotOverrideProvidedParameters() + public function testUpdateRulesUniquesUniqueWithDoesNotOverrideProvidedParameters(): void { $this->trait->exists = true; @@ -45,10 +47,10 @@ public function testUpdateRulesUniquesUniqueWithDoesNotOverrideProvidedParameter } } -class UniqueWithValidatingStub extends \Illuminate\Database\Eloquent\Model +final class UniqueWithValidatingStub extends \Illuminate\Database\Eloquent\Model { - use \Watson\Validating\ValidatingTrait; use \Watson\Validating\Injectors\UniqueWithInjector; + use \Watson\Validating\ValidatingTrait; public function getKey() { diff --git a/packages/tmp-watson-validating/tests/TestCase.php b/packages/tmp-watson-validating/tests/TestCase.php index 8575877..fbbb696 100644 --- a/packages/tmp-watson-validating/tests/TestCase.php +++ b/packages/tmp-watson-validating/tests/TestCase.php @@ -1,5 +1,7 @@ model = Mockery::mock('Illuminate\Database\Eloquent\Model'); - $this->observer = new ValidatingObserver; + $this->observer = new ValidatingObserver(); } - public function testPerformValidation() + public function testPerformValidation(): void { $this->model->shouldReceive('getValidating')->once()->andReturn(true); @@ -32,7 +34,7 @@ public function testPerformValidation() $this->assertNotFalse($response); } - public function testValidationStopsIfValidatingEventReturnsNonNull() + public function testValidationStopsIfValidatingEventReturnsNonNull(): void { $this->model->shouldReceive('getValidating')->once()->andReturn(true); @@ -43,7 +45,7 @@ public function testValidationStopsIfValidatingEventReturnsNonNull() $this->assertNull($result); } - public function testPerformValidationReturnsFalse() + public function testPerformValidationReturnsFalse(): void { $this->model->shouldReceive('getValidating')->once()->andReturn(true); @@ -59,7 +61,7 @@ public function testPerformValidationReturnsFalse() $this->assertFalse($response); } - public function testPerformValidationThrowsException() + public function testPerformValidationThrowsException(): void { $this->model->shouldReceive('getValidating')->once()->andReturn(true); @@ -78,7 +80,7 @@ public function testPerformValidationThrowsException() $this->assertFalse($response); } - public function testSavingPerformsValidation() + public function testSavingPerformsValidation(): void { $this->model->shouldReceive('getValidating')->once()->andReturn(true); @@ -95,7 +97,7 @@ public function testSavingPerformsValidation() $this->observer->saving($this->model); } - public function testRestoringPerformsValidation() + public function testRestoringPerformsValidation(): void { $this->model->shouldReceive('getValidating')->once()->andReturn(true); @@ -112,7 +114,7 @@ public function testRestoringPerformsValidation() $this->observer->restoring($this->model); } - public function testDisabledValidationFiresSkippedEvent() + public function testDisabledValidationFiresSkippedEvent(): void { $this->model->shouldReceive('getValidating')->once()->andReturn(false); diff --git a/packages/tmp-watson-validating/tests/ValidatingTraitTest.php b/packages/tmp-watson-validating/tests/ValidatingTraitTest.php index 43377b6..13ea8c9 100644 --- a/packages/tmp-watson-validating/tests/ValidatingTraitTest.php +++ b/packages/tmp-watson-validating/tests/ValidatingTraitTest.php @@ -1,15 +1,16 @@ trait = Mockery::mock(DatabaseValidatingTraitStub::class)->makePartial(); } - public function testGetValidatingDefaultsToTrue() + public function testGetValidatingDefaultsToTrue(): void { $this->assertTrue($this->trait->getValidating()); } - public function testSetValidatingSetsValue() + public function testSetValidatingSetsValue(): void { $this->trait->setValidating(false); @@ -31,12 +32,12 @@ public function testSetValidatingSetsValue() } - public function testGetThrowValidationExceptionsDefaultsToFalse() + public function testGetThrowValidationExceptionsDefaultsToFalse(): void { $this->assertFalse($this->trait->getThrowValidationExceptions()); } - public function testSetThrowValidationExceptionsSetsValue() + public function testSetThrowValidationExceptionsSetsValue(): void { $this->trait->setThrowValidationExceptions(false); @@ -44,12 +45,12 @@ public function testSetThrowValidationExceptionsSetsValue() } - public function testGetInjectUniqueIdentifierDefaultsToTrue() + public function testGetInjectUniqueIdentifierDefaultsToTrue(): void { $this->assertTrue($this->trait->getInjectUniqueIdentifier()); } - public function testSetInjectUniqueIdentifierSetsValue() + public function testSetInjectUniqueIdentifierSetsValue(): void { $this->trait->setInjectUniqueIdentifier(false); @@ -57,33 +58,33 @@ public function testSetInjectUniqueIdentifierSetsValue() } - public function testGetsModel() + public function testGetsModel(): void { $this->assertEquals($this->trait, $this->trait->getModel()); } - public function testGetValidationMessages() + public function testGetValidationMessages(): void { $this->assertEquals(['bar' => 'baz'], $this->trait->getValidationMessages()); } - public function testModelValidationMessages() + public function testModelValidationMessages(): void { $this->assertEquals(['bar' => 'baz'], DatabaseValidatingTraitStub::modelValidationMessages()); } - public function testGetValidationAttributeNames() + public function testGetValidationAttributeNames(): void { $this->assertEmpty($this->trait->getValidationAttributeNames()); } - public function testModelValidationAttributeNames() + public function testModelValidationAttributeNames(): void { $this->assertEmpty(DatabaseValidatingTraitStub::modelValidationAttributeNames()); } - public function testSetValidationAttributeNames() + public function testSetValidationAttributeNames(): void { $this->trait->setValidationAttributeNames(['bar' => 'baz']); @@ -91,12 +92,12 @@ public function testSetValidationAttributeNames() } - public function testGetRules() + public function testGetRules(): void { $this->assertEquals(['foo' => 'bar', 'def' => 'array'], $this->trait->getRules()); } - public function testRules() + public function testRules(): void { $this->trait->shouldReceive('getRules')->once()->andReturn('foo'); @@ -105,7 +106,7 @@ public function testRules() $this->assertEquals('foo', $result); } - public function testSetRules() + public function testSetRules(): void { $this->trait->setRules(['bar' => 'foo']); @@ -113,7 +114,7 @@ public function testSetRules() } - public function testAttributesAreMutated() + public function testAttributesAreMutated(): void { $expected = [ 'abc' => '123', @@ -126,12 +127,12 @@ public function testAttributesAreMutated() } - public function testGetErrors() + public function testGetErrors(): void { $this->assertEquals(0, $this->trait->getErrors()->count()); } - public function testSetErrors() + public function testSetErrors(): void { $messageBag = Mockery::mock(MessageBag::class); @@ -141,7 +142,7 @@ public function testSetErrors() } - public function testIsValidReturnsTrueWhenValidationPasses() + public function testIsValidReturnsTrueWhenValidationPasses(): void { Validator::shouldReceive('make') ->once() @@ -155,7 +156,7 @@ public function testIsValidReturnsTrueWhenValidationPasses() $this->assertTrue($result); } - public function testIsValidReturnFalseWhenValidationFails() + public function testIsValidReturnFalseWhenValidationFails(): void { $messageBag = Mockery::mock(MessageBag::class); @@ -172,7 +173,7 @@ public function testIsValidReturnFalseWhenValidationFails() $this->assertSame($messageBag, $this->trait->getErrors()); } - public function testIsValidClearsErrors() + public function testIsValidClearsErrors(): void { $this->trait->setErrors(Mockery::mock(MessageBag::class)); @@ -191,7 +192,7 @@ public function testIsValidClearsErrors() $this->assertSame($validMessageBag, $this->trait->getErrors()); } - public function testIsValidOrFailThrowsException() + public function testIsValidOrFailThrowsException(): void { $this->expectException('Watson\Validating\ValidationException'); @@ -204,7 +205,7 @@ public function testIsValidOrFailThrowsException() $this->trait->isValidOrFail(); } - public function testIsValidOrFailReturnsTrue() + public function testIsValidOrFailReturnsTrue(): void { $this->trait->shouldReceive('isValid')->once()->andReturn(true); @@ -213,7 +214,7 @@ public function testIsValidOrFailReturnsTrue() $this->assertTrue($result); } - public function testIsInvalidReturnsFalseIfIsValidIsTrue() + public function testIsInvalidReturnsFalseIfIsValidIsTrue(): void { $this->trait->shouldReceive('isValid')->once()->andReturn(true); @@ -222,7 +223,7 @@ public function testIsInvalidReturnsFalseIfIsValidIsTrue() $this->assertFalse($result); } - public function testIsInvalidReturnsTrueIfIsValidIsFalse() + public function testIsInvalidReturnsTrueIfIsValidIsFalse(): void { $this->trait->shouldReceive('isValid')->once()->andReturn(false); @@ -231,7 +232,7 @@ public function testIsInvalidReturnsTrueIfIsValidIsFalse() $this->assertTrue($result); } - public function testForceSaveSavesOnInvalidModel() + public function testForceSaveSavesOnInvalidModel(): void { $this->trait->shouldReceive('save') ->once() @@ -245,7 +246,7 @@ public function testForceSaveSavesOnInvalidModel() } - public function testSaveOrFailThrowsExceptionOnInvalidModel() + public function testSaveOrFailThrowsExceptionOnInvalidModel(): void { $this->expectException('Watson\Validating\ValidationException'); @@ -260,7 +261,7 @@ public function testSaveOrFailThrowsExceptionOnInvalidModel() $this->assertNull($result); } - public function testSaveOrFailReturnsTrueOnValidModel() + public function testSaveOrFailReturnsTrueOnValidModel(): void { $this->trait->shouldReceive('isInvalid')->once()->andReturn(false); @@ -271,7 +272,7 @@ public function testSaveOrFailReturnsTrueOnValidModel() $this->assertTrue($result); } - public function testParentSaveOrFailCallsParentSaveOrFail() + public function testParentSaveOrFailCallsParentSaveOrFail(): void { $result = $this->trait->parentSaveOrFail(['foo' => 'bar']); @@ -279,7 +280,7 @@ public function testParentSaveOrFailCallsParentSaveOrFail() } - public function testSaveOrReturn() + public function testSaveOrReturn(): void { $this->trait->shouldReceive('save')->once()->andReturn('foo'); @@ -288,7 +289,7 @@ public function testSaveOrReturn() $this->assertEquals('foo', $result); } - public function testPerformValidationReturnsFalseOnInvalidModel() + public function testPerformValidationReturnsFalseOnInvalidModel(): void { Validator::shouldReceive('make') ->once() @@ -304,7 +305,7 @@ public function testPerformValidationReturnsFalseOnInvalidModel() $this->assertFalse($result); } - public function testPerformValidationReturnsTrueOnValidModel() + public function testPerformValidationReturnsTrueOnValidModel(): void { Validator::shouldReceive('make') ->once() @@ -318,7 +319,7 @@ public function testPerformValidationReturnsTrueOnValidModel() $this->assertTrue($result); } - public function testGetValidatorReturnsFactory() + public function testGetValidatorReturnsFactory(): void { Validator::shouldReceive('getFacadeRoot') ->once() @@ -329,7 +330,7 @@ public function testGetValidatorReturnsFactory() $this->assertNotNull($validator); } - public function testSetValidator() + public function testSetValidator(): void { $this->trait->setValidator(Mockery::mock(ValidatorStub::class)); @@ -337,7 +338,7 @@ public function testSetValidator() $this->assertInstanceOf(ValidatorStub::class, $validator, get_class($validator)); } - public function testMakeValidatorSetsValidationAttributeNames() + public function testMakeValidatorSetsValidationAttributeNames(): void { $validatorMock = Mockery::mock(ValidatorStub::class); @@ -354,7 +355,7 @@ public function testMakeValidatorSetsValidationAttributeNames() $this->trait->makeValidator(); } - public function testThrowValidationException() + public function testThrowValidationException(): void { $this->expectException('Watson\Validating\ValidationException'); @@ -366,12 +367,11 @@ public function testThrowValidationException() } } -class ValidatorStub extends \Illuminate\Validation\Factory +final class ValidatorStub extends \Illuminate\Validation\Factory { - // } -class ModelStub extends Model +final class ModelStub extends Model { public function saveOrFail(array $options = []) { @@ -379,7 +379,7 @@ public function saveOrFail(array $options = []) } } -class DatabaseValidatingTraitStub extends ModelStub implements \Watson\Validating\ValidatingInterface +final class DatabaseValidatingTraitStub extends ModelStub implements \Watson\Validating\ValidatingInterface { use \Watson\Validating\ValidatingTrait; diff --git a/packages/tmp-watson-validating/tests/ValidationExceptionTest.php b/packages/tmp-watson-validating/tests/ValidationExceptionTest.php index bb3d480..c7de75d 100644 --- a/packages/tmp-watson-validating/tests/ValidationExceptionTest.php +++ b/packages/tmp-watson-validating/tests/ValidationExceptionTest.php @@ -1,11 +1,13 @@ validator = Mockery::mock(\Illuminate\Contracts\Validation\Validator::class); - $this->validator = Mockery::mock(\Illuminate\Contracts\Validation\Validator::class, function ($mock) { + $this->validator = Mockery::mock(\Illuminate\Contracts\Validation\Validator::class, function ($mock): void { $mock ->shouldReceive('errors') ->once() ->andReturn(); }); - + //$this->model = Mockery::mock('Illuminate\Database\Eloquent\Model'); - $this->model = Mockery::mock(\Illuminate\Database\Eloquent\Model::class, function ($mock) { + $this->model = Mockery::mock(\Illuminate\Database\Eloquent\Model::class, function ($mock): void { $mock ->shouldReceive([]) ->andReturn($this); @@ -38,26 +40,26 @@ public function setUp(): void ); } - public function testModel() + public function testModel(): void { $this->assertEquals($this->model, $this->exception->model()); } - public function testGetModel() + public function testGetModel(): void { $this->assertEquals($this->model, $this->exception->getModel()); } - public function testGetErrors() + public function testGetErrors(): void { - $this->validator->shouldReceive('errors') - ->once() - ->andReturn('errors'); + $this->validator->shouldReceive('errors') + ->once() + ->andReturn('errors'); - $this->assertEquals('errors', $this->exception->getErrors()); + $this->assertEquals('errors', $this->exception->getErrors()); } - public function testGetsMessageBag() + public function testGetsMessageBag(): void { $this->validator->shouldReceive('errors') ->once() diff --git a/phpstan.neon b/phpstan.neon index abf723e..250514b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,9 +13,15 @@ parameters: - app/Http/Controllers/OAuthController.php - app/Http/Controllers/Api/Auth/LoginController.php - app/Markdown/MarkdownHelper.php + + - app/Traits + - app/Spotlight + - app/Models + - app/Mail + - app/Listeners + - app/Http scanDirectories: - ./helpers - ignoreErrors: - - "#^Cannot access property \\$transaction on array\\|object\\.$#" + checkGenericClassInNonGenericObjectType: false checkMissingIterableValueType: false diff --git a/phpunit.xml b/phpunit.xml index 3d4d5c4..c72b0f6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,35 +1,32 @@ - - - - ./tests/Unit - - - ./tests/Integration - - - ./tests/Feature - - - - - ./app - - - - - - - - - - - - - - + + + + ./tests/Unit + + + ./tests/Integration + + + ./tests/Feature + + + + + + + + + + + + + + + + + + ./app + + diff --git a/phpunit.xml.bak b/phpunit.xml.bak new file mode 100644 index 0000000..3d4d5c4 --- /dev/null +++ b/phpunit.xml.bak @@ -0,0 +1,35 @@ + + + + + ./tests/Unit + + + ./tests/Integration + + + ./tests/Feature + + + + + ./app + + + + + + + + + + + + + + + diff --git a/resources/views/__feature.blade.php b/resources/views/__feature.blade.php new file mode 100644 index 0000000..67b3a69 --- /dev/null +++ b/resources/views/__feature.blade.php @@ -0,0 +1,76 @@ +@feature('premium') + @if ($plans->count() > 0) +
+ +
+
+
+
+ + + +

{{ __('Premium') }}

+
+

+ {{ __('Accès illimité avec un abonnement premium') }} +

+

+ {{ __('Devenir premium c\'est soutenir la communauté, les nouveaux contenus chaque semaine et accéder à du contenu exclusif pour apprendre et progresser.') }} +

+
+
+ @foreach ($plans as $plan) +
+
+

{{ $plan->title }}

+ @if ($plan->slug === 'le-pro') +

+ + + + {{ __('Populaire') }} +

+ @endif +

+ + + + {{ __('/mois') }} +

+ + +
    + @foreach ($plan->features as $feature) +
  • + + {{ $feature->name }} +
  • + @endforeach +
+
+ + {{ __('Souscrire Maintenant') }} +
+ @endforeach +
+
+
+
+ @endif +@endfeature diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 9c32c6f..4d37e20 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -5,22 +5,29 @@
-
-
+
+ -
--}}
- + {{ __('Votre logo ici ?') }}
@@ -71,13 +80,12 @@
- -
- @foreach($latestArticles as $article) - @if($loop->first) + +
+ @foreach ($latestArticles as $article) + @if ($loop->first)
@@ -92,31 +100,34 @@
{{ __('Voir tous les articles') }} - - + +
- @if($latestThreads->isNotEmpty()) + @if ($latestThreads->isNotEmpty())
- +
- @foreach($latestThreads as $thread) + @foreach ($latestThreads as $thread)
- - + + {{ '@' . $thread->user->username }} {{ __('a posé') }} - - + +
@@ -128,7 +139,8 @@

@@ -139,8 +151,10 @@
{{ __('Voir tous les sujets') }} - - + +
@@ -148,23 +162,23 @@ @endif
- +
- @foreach($latestDiscussions as $discussion) + @foreach ($latestDiscussions as $discussion)
@@ -172,7 +186,8 @@

{!! $discussion->excerpt() !!}

@@ -183,8 +198,10 @@
{{ __('Voir toutes les discussions') }} - - + +
@@ -196,8 +213,11 @@
- Developer working on laptop - + Developer working on laptop +
@@ -254,68 +274,5 @@
- @feature('premium') - @if($plans->count() > 0) -
- -
-
-
-
- - - -

{{ __('Premium') }}

-
-

- {{ __('Accès illimité avec un abonnement premium') }} -

-

- {{ __('Devenir premium c\'est soutenir la communauté, les nouveaux contenus chaque semaine et accéder à du contenu exclusif pour apprendre et progresser.') }} -

-
-
- @foreach ($plans as $plan) -
-
-

{{ $plan->title }}

- @if($plan->slug === 'le-pro') -

- - - - {{ __('Populaire') }} -

- @endif -

- - - - {{ __('/mois') }} -

- - -
    - @foreach ($plan->features as $feature) -
  • - - {{ $feature->name }} -
  • - @endforeach -
-
- - {{ __('Souscrire Maintenant') }} -
- @endforeach -
-
-
-
- @endif - @endfeature + {{-- Feature Partie --}} @stop