Skip to content

Commit

Permalink
Merge pull request #31 from placetopay-org/feature/upgrade-php-cs-fixer
Browse files Browse the repository at this point in the history
Feature/upgrade php cs fixer
  • Loading branch information
eduarguz authored Apr 3, 2024
2 parents 27637a9 + b82d635 commit 4587fb6
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 216 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: PHP CS Fixer
run: vendor/bin/php-cs-fixer fix --config=.php_cs
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php

- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.idea/
.php_cs.cache
.phpunit.result.cache
composer.lock
composer.lock
.php-cs-fixer.cache
21 changes: 21 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use PhpCsFixer\Finder;

$finder = Finder::create()
->notPath('bootstrap')
->notPath('storage')
->notPath('packages')
->notPath('vendor')
->in(getcwd())
->name('*.php')
->notName('*.blade.php')
->notName('index.php')
->notName('_ide_helper.php')
->notName('server.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return \ShiftCS\styles($finder, [
'no_unused_imports' => true,
]);
148 changes: 0 additions & 148 deletions .php_cs

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.3 (2023-04-03)](https://github.com/placetopay-org/cerberus/compare/3.0.2...3.0.3)

### Added

- `eduarguz/shift-php-cs` package.

### Changed

- Update `friendsofphp/php-cs-fixer` package to version 3.0
- Add return type `int` to `TenantAware.execute`

## [3.0.2 (2023-10-11)](https://github.com/placetopay-org/cerberus/compare/3.0.1...3.0.2)

### Changed
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"require": {
"php": "^8.0",
"ext-json": "*",
"spatie/laravel-multitenancy": "^3.0"
"spatie/laravel-multitenancy": "^3.0",
"eduarguz/shift-php-cs": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"orchestra/testbench": "^6.0",
"friendsofphp/php-cs-fixer": "^2.16",
"friendsofphp/php-cs-fixer": "^3.0",
"laravel/legacy-factories": "^1.0.4"
},
"autoload": {
Expand All @@ -47,7 +48,7 @@
}
},
"scripts": {
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --config=.php_cs",
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php",
"test": "vendor/bin/phpunit tests/"
}
}
1 change: 0 additions & 1 deletion config/multitenancy.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Illuminate\Broadcasting\BroadcastEvent;
use Illuminate\Encryption\Encrypter;
use Illuminate\Events\CallQueuedListener;
use Illuminate\Mail\SendQueuedMailable;
use Illuminate\Notifications\SendQueuedNotifications;
Expand Down
12 changes: 6 additions & 6 deletions src/Actions/MakeQueueTenantAwareAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function listenForJobsBeingQueued(): static
app('queue')->createPayloadUsing(function ($connectionName, $queue, $payload) {
$queueable = $payload['data']['command'];

if (!$this->isTenantAware($queueable)) {
if (! $this->isTenantAware($queueable)) {
return [];
}

Expand All @@ -42,7 +42,7 @@ protected function listenForJobsBeingQueued(): static
protected function listenForJobsBeingProcessed(): static
{
app('events')->listen(JobProcessing::class, function (JobProcessing $event) {
if (!array_key_exists('tenantDomain', $event->job->payload())) {
if (! array_key_exists('tenantDomain', $event->job->payload())) {
return;
}

Expand All @@ -55,7 +55,7 @@ protected function listenForJobsBeingProcessed(): static
protected function listenForJobsRetryRequested(): static
{
app('events')->listen(JobRetryRequested::class, function (JobRetryRequested $event) {
if (!array_key_exists('tenantDomain', $event->payload())) {
if (! array_key_exists('tenantDomain', $event->payload())) {
return;
}

Expand Down Expand Up @@ -84,14 +84,14 @@ protected function findTenant(JobProcessing|JobRetryRequested $event): Tenant
{
$tenantDomain = $this->getEventPayload($event)['tenantDomain'] ?? null;

if (!$tenantDomain) {
if (! $tenantDomain) {
$event->job->delete();

throw CurrentTenantCouldNotBeDeterminedInTenantAwareJob::noTenantFound($event);
}

/** @var \Placetopay\Cerberus\Models\Tenant $tenant */
if (!$tenant = (new DomainTenantFinder)->getTenant($tenantDomain)) {
if (! $tenant = (new DomainTenantFinder)->getTenant($tenantDomain)) {
$event->job->delete();

throw CurrentTenantCouldNotBeDeterminedInTenantAwareJob::noTenantFound($event);
Expand All @@ -104,7 +104,7 @@ protected function getJobFromQueueable(object $queueable)
{
$job = Arr::get(config('multitenancy.queueable_to_job'), $queueable::class);

if (!$job) {
if (! $job) {
return $queueable;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Concerns/TenantAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait TenantAware
use UsesMultitenancyConfig,
UsesTenantModel;

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$tenant = Arr::wrap($this->option('tenant'));
if (empty($tenant)) {
Expand All @@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

return $tenants
->map(fn ($tenant) => $tenant->execute(fn () => (int)$this->laravel->call([$this, 'handle'])))
->map(fn ($tenant) => $tenant->execute(fn () => (int) $this->laravel->call([$this, 'handle'])))
->sum();
}
}
4 changes: 2 additions & 2 deletions src/Commands/TenantsArtisanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class TenantsArtisanCommand extends TenantsArtisanParentCommand
*/
public function handle()
{
if (!$artisanCommand = $this->argument('artisanCommand')) {
if (! $artisanCommand = $this->argument('artisanCommand')) {
$artisanCommand = $this->ask('Which artisan command do you want to run for all tenants?');
}

if (!$this->option('no-slashes')) {
if (! $this->option('no-slashes')) {
$artisanCommand = addslashes($artisanCommand);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/TenantsListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle(): void

$tenantQuery->cursor()
->each(function (Tenant $tenant) {
$this->line("[Tenant] domain: {$tenant['domain']} @ " . $tenant['name']);
$this->line("[Tenant] domain: {$tenant['domain']} @ ".$tenant['name']);
});
}
}
3 changes: 2 additions & 1 deletion src/Commands/TenantsSkeletonStorageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class TenantsSkeletonStorageCommand extends Command

public function handle(): int
{
if (!config('multitenancy.suffix_storage_path')) {
if (! config('multitenancy.suffix_storage_path')) {
$this->error('Storage tenancies are not enabled.');

return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/TenantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function clean(Request $request): JsonResponse
});

return response()->json([
'message' => 'cache cleared',
'message' => 'cache cleared',
]);
}
}
5 changes: 3 additions & 2 deletions src/Http/Middlewares/AppCleanCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ class AppCleanCache
];

public const EMPTY_CONFIG_KEY = "You must configure the variable 'multitenancy.middleware_key' to perform this action";

public const UN_AUTHORIZED = 'You are not authorized to perform this action';

public function handle(Request $request, Closure $next)
{
if (!config('multitenancy.middleware_key')) {
if (! config('multitenancy.middleware_key')) {
$this->unAuthorized(self::EMPTY_CONFIG_KEY);
}

if (!$this->canClearCache($request) || !$this->allowedAction($request)) {
if (! $this->canClearCache($request) || ! $this->allowedAction($request)) {
$this->unAuthorized();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Models/Tenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected static function boot()
public function translate(string $key): string
{
$locale = $this->normalizeLocale($key);

return $this->getTranslations($key)[$locale] ?? '';
}

Expand All @@ -56,7 +57,7 @@ private function normalizeLocale(string $key): ?string
return $this->shortLocale($locale);
}

if (!is_null(app()->getFallbackLocale())) {
if (! is_null(app()->getFallbackLocale())) {
return app()->getFallbackLocale();
}

Expand Down
Loading

0 comments on commit 4587fb6

Please sign in to comment.