Skip to content

Commit

Permalink
fix: pint and psalm fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarin committed Jul 11, 2024
1 parent dfb3bea commit 04fcae9
Show file tree
Hide file tree
Showing 55 changed files with 165 additions and 163 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '8.1', '8.2' ]
php-versions: [ '8.1', '8.2', '8.3' ]
uses: 'tochka-developers/actions/.github/workflows/analyze.yml@v1'
with:
php-version: ${{ matrix.php-versions }}
Expand All @@ -60,7 +60,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '8.1', '8.2' ]
php-versions: [ '8.1', '8.2', '8.3' ]
uses: 'tochka-developers/actions/.github/workflows/tests.yml@v1'
with:
php-version: ${{ matrix.php-versions }}
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"laravel"
],
"require": {
"php": "8.1.*|8.2.*",
"php": "8.1.*|8.2.*|8.3.*",
"ext-json": "*",
"ext-pcntl": "*",
"bensampo/laravel-enum": "^2.1|^3.0|^4.0|^5.0|^6.0",
"laravel/framework": "^v8.37|^9.0|^10.0",
"nesbot/carbon": "^2.0"
"nesbot/carbon": "^2.0|^3.0"
},
"require-dev": {
"laravel/pint": "^1.4",
"laravel/pint": "^1.16",
"mockery/mockery": "^1.0",
"orchestra/testbench": "^6.13|^7.1|^8.0",
"phpunit/phpunit": "^8.0|^9.0",
Expand Down Expand Up @@ -56,6 +56,8 @@
"scripts": {
"lint": "php8.1 vendor/bin/pint --test",
"lint-fix": "php8.1 vendor/bin/pint",
"analyze": "php8.1 vendor/bin/psalm --php-version=8.1 --no-cache"
"analyze": "php8.1 vendor/bin/psalm --php-version=8.1 --no-cache",
"pint": "vendor/bin/pint",
"psalm": "vendor/bin/psalm --no-cache --threads=8 --output-format=phpstorm"
}
}
2 changes: 1 addition & 1 deletion config/promises.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@
*/
'promise_chunk_size' => 100,
'jobs_chunk_size' => 500,
]
],
];
10 changes: 5 additions & 5 deletions src/Commands/PromiseMakeMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ public function handle(): void
if ($migrationName === null) {
$migrationsToRun = array_filter(
$this->migrations,
fn (MigrationContract $migration) => $migration->isMainMigration()
fn(MigrationContract $migration) => $migration->isMainMigration(),
);
} else {
$migrationsToRun = array_filter(
$this->migrations,
fn (MigrationContract $migration) => $migration->getName() === $migrationName
fn(MigrationContract $migration) => $migration->getName() === $migrationName,
);
if (count($migrationsToRun) === 0) {
throw new \InvalidArgumentException(
sprintf('Migrations with name [%s] does not exists', $migrationName)
sprintf('Migrations with name [%s] does not exists', $migrationName),
);
}
}
Expand All @@ -76,7 +76,7 @@ public function handle(): void
$this->replaceMigration(
$this->createTableMigration($migrationName),
$migration->getStub(),
$tableName
$tableName,
);
$this->info(sprintf('Migration for table [%s] created!', $tableName));
}
Expand All @@ -98,7 +98,7 @@ protected function createTableMigration(string $migrationName): string

return $migrationCreator->create(
$migrationName,
$this->laravel->databasePath() . '/migrations'
$this->laravel->databasePath() . '/migrations',
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Conditions/AllJobsInStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function condition(BasePromise $basePromise): bool
function (bool $carry, PromiseJob $job) {
return $carry && $job->getBaseJob()->getState()->in($this->states);
},
true
true,
);
}
}
2 changes: 1 addition & 1 deletion src/Conditions/AndConditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function condition(BasePromise $basePromise): bool
static function (bool $carry, ConditionContract $item) use ($basePromise) {
return $carry && $item->condition($basePromise);
},
true
true,
);
}
}
2 changes: 1 addition & 1 deletion src/Conditions/OrConditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function condition(BasePromise $basePromise): bool
static function (bool $carry, ConditionContract $item) use ($basePromise) {
return $carry || $item->condition($basePromise);
},
false
false,
);
}
}
2 changes: 1 addition & 1 deletion src/Conditions/Timeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class Timeout implements ConditionContract
private Carbon $expired_at;

/**
* @param int|Carbon|\DateInterval $timeout Таймаут в минутах или время истечения
* @param int|Carbon|\DateInterval|string $timeout Таймаут в минутах или время истечения
*/
public function __construct($timeout)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Core/FakePromiseRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function assertRun(string $promiseHandler): void
PHPUnit::assertArrayHasKey(
$promiseHandler,
$this->promises,
sprintf('Check promise handler [%s] is run', $promiseHandler)
sprintf('Check promise handler [%s] is run', $promiseHandler),
);
}

Expand All @@ -41,7 +41,7 @@ public function assertNotRun(string $promiseHandler): void
PHPUnit::assertArrayNotHasKey(
$promiseHandler,
$this->promises,
sprintf('Check promise handler [%s] is not run', $promiseHandler)
sprintf('Check promise handler [%s] is not run', $promiseHandler),
);
}

Expand All @@ -50,12 +50,12 @@ public function assertAddedJobsCount(string $promiseHandler, int $expected): voi
PHPUnit::assertArrayHasKey(
$promiseHandler,
$this->jobs,
sprintf('Check promised job added count [%s]', $promiseHandler)
sprintf('Check promised job added count [%s]', $promiseHandler),
);
PHPUnit::assertCount(
$expected,
$this->jobs[$promiseHandler] ?? [],
sprintf('Check promised job added count [%s]', $promiseHandler)
sprintf('Check promised job added count [%s]', $promiseHandler),
);
}

Expand All @@ -64,12 +64,12 @@ public function assertAddedJobs(string $promiseHandler, array $expected): void
PHPUnit::assertArrayHasKey(
$promiseHandler,
$this->jobs,
sprintf('Check promised job added [%s]', $promiseHandler)
sprintf('Check promised job added [%s]', $promiseHandler),
);
PHPUnit::assertEquals(
$expected,
$this->jobs[$promiseHandler] ?? [],
sprintf('Check promised job added [%s]', $promiseHandler)
sprintf('Check promised job added [%s]', $promiseHandler),
);
}
}
8 changes: 4 additions & 4 deletions src/Core/GarbageCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public function handle(?callable $shouldQuitCallback = null, ?callable $shouldPa
public function clean(?callable $shouldQuitCallback = null, ?callable $shouldPausedCallback = null): void
{
if ($shouldQuitCallback === null) {
$shouldQuitCallback = fn () => false;
$shouldQuitCallback = fn() => false;
}

if ($shouldPausedCallback === null) {
$shouldPausedCallback = fn () => false;
$shouldPausedCallback = fn() => false;
}

while (!$shouldQuitCallback() && !$shouldPausedCallback()) {
Expand All @@ -79,7 +79,7 @@ public function clean(?callable $shouldQuitCallback = null, ?callable $shouldPau
$this->promiseJobsTable,
$this->promiseJobsColumn('id'),
'=',
$this->promiseColumn('parent_job_id')
$this->promiseColumn('parent_job_id'),
)
->whereIn($this->promiseColumn('state'), $this->states)
->where($this->promiseColumn('updated_at'), '<', Carbon::now()->subSeconds($this->deleteOlderThen))
Expand Down Expand Up @@ -115,7 +115,7 @@ private function handlePromiseChunks(array $promiseIds, callable $shouldQuitCall
->whereIn('promise_id', $promiseIds)
->chunkById(
$this->jobsChunkSize,
$this->handleJobsChunks(...)
$this->handleJobsChunks(...),
);

DB::table($this->promisesTable)->whereIn('id', $promiseIds)->delete();
Expand Down
14 changes: 7 additions & 7 deletions src/Core/PromiseWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function __construct(
public function watch(?callable $shouldQuitCallback = null, ?callable $shouldPausedCallback = null): void
{
if ($shouldQuitCallback === null) {
$shouldQuitCallback = fn () => false;
$shouldQuitCallback = fn() => false;
}

if ($shouldPausedCallback === null) {
$shouldPausedCallback = fn () => false;
$shouldPausedCallback = fn() => false;
}

$this->daemon(function () use ($shouldQuitCallback, $shouldPausedCallback) {
Expand Down Expand Up @@ -89,7 +89,7 @@ public function watchIteration(callable $shouldQuitCallback, callable $shouldPau
private function handlePromiseChunks(
array $promiseIds,
callable $shouldQuitCallback,
callable $shouldPausedCallback
callable $shouldPausedCallback,
): bool {
foreach ($promiseIds as $promise) {
if ($shouldQuitCallback() || $shouldPausedCallback()) {
Expand Down Expand Up @@ -123,7 +123,7 @@ function () use ($promiseId) {
ConditionTransitionHandler::checkConditionAndApplyTransition(
$basePromise,
$basePromise,
$basePromise
$basePromise,
);
}

Expand All @@ -139,7 +139,7 @@ function () use ($promiseId) {

return $basePromise;
},
3
3,
);

if ($basePromise === null) {
Expand All @@ -162,7 +162,7 @@ public function checkJobConditions(int $jobId, BasePromise $basePromise): void
DB::transaction(
function () use ($jobId, $basePromise) {
/** @var PromiseJob|null $lockedJob */
$lockedJob = PromiseJob::lockForUpdate()->find($jobId);
$lockedJob = PromiseJob::query()->lockForUpdate()->find($jobId);
if ($lockedJob === null) {
return;
}
Expand All @@ -172,7 +172,7 @@ function () use ($jobId, $basePromise) {
PromiseJob::saveBaseJob($baseJob);
}
},
3
3,
);
}
}
6 changes: 3 additions & 3 deletions src/Core/Support/ConditionTransition.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function fromArray(array $value): self
|| !array_key_exists('to_state', $value)
) {
throw new IncorrectResolvingClass(
'ConditionTransition array must contains required elements [condition,from_state,to_state]'
'ConditionTransition array must contains required elements [condition,from_state,to_state]',
);
}

Expand All @@ -67,8 +67,8 @@ public static function fromArray(array $value): self
sprintf(
'Condition must implements contract [%s], but class [%s] is incorrect',
ConditionContract::class,
get_class($condition)
)
get_class($condition),
),
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Core/Support/ConditionTransitionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class ConditionTransitionHandler
*/
public function getConditionsForState(
StatesContract $state,
ConditionTransitionsContract $conditionTransitions
ConditionTransitionsContract $conditionTransitions,
): array {
$conditions = $conditionTransitions->getConditions();

return array_filter(
$conditions,
static function (ConditionTransition $conditionTransition) use ($state) {
return $conditionTransition->getFromState()->is($state->getState());
}
},
);
}

Expand All @@ -49,7 +49,7 @@ public function getTransitionForConditions(array $conditionTransitions, BaseProm
public function checkConditionAndApplyTransition(
StatesContract $statesInstance,
ConditionTransitionsContract $conditionTransitionsInstance,
BasePromise $basePromise
BasePromise $basePromise,
): bool {
$conditions = $this->getConditionsForState($statesInstance, $conditionTransitionsInstance);
$transition = $this->getTransitionForConditions($conditions, $basePromise);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Support/DaemonWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ trait DaemonWorker
public function daemon(callable $callback, ?callable $shouldQuitCallback = null, ?callable $shouldPausedCallback = null): void
{
if ($shouldQuitCallback === null) {
$shouldQuitCallback = fn () => false;
$shouldQuitCallback = fn() => false;
}
if ($shouldPausedCallback === null) {
$shouldPausedCallback = fn () => false;
$shouldPausedCallback = fn() => false;
}

while (true) {
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Support/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function updateEventState(PromisedEvent $event, WaitEvent $waitEvent): vo
function () use ($event, $waitEvent) {
$cloneWaitEvent = clone $waitEvent;

$job = PromiseJob::lockForUpdate()->find($cloneWaitEvent->getBaseJobId());
$job = PromiseJob::query()->lockForUpdate()->find($cloneWaitEvent->getBaseJobId());
if ($job !== null) {
$cloneWaitEvent->setEvent($event);
$cloneWaitEvent->setAttachedModel(null);
Expand All @@ -43,7 +43,7 @@ function () use ($event, $waitEvent) {
PromiseJob::saveBaseJob($baseJob);
}
},
3
3,
);
}
}
6 changes: 3 additions & 3 deletions src/Core/Support/PromiseQueueJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ protected function dispatchMethodWithParams(string $method)
sprintf(
'Error while dispatch promise handler method [%s]. Parameter [%s] not allow null value, but result for this parameter is empty',
$reflectionMethod->getDeclaringClass()->getName() . '::' . $method,
$parameter->getName()
)
$parameter->getName(),
),
);
}

Expand Down Expand Up @@ -162,7 +162,7 @@ private function getParamType(\ReflectionParameter $parameter): string
{
$paramType = $parameter->getType();
if (!$paramType instanceof \ReflectionNamedType) {
return (string)$paramType;
return (string) $paramType;
}

return $paramType->getName();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Support/QueuePromiseMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function setJobStateAndResult(MayPromised $queueJob, BaseJob $baseJob): v
[
StateEnum::WAITING(),
StateEnum::RUNNING(),
]
],
)) {
$baseJob->setState($queueJob->getState());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Facades/BaseJobDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Tochka\Promises\Contracts\MayPromised;

/**
* @method static addDispatcher(DispatcherContract $dispatcher)
* @method static dispatch(MayPromised $job)
* @method static void addDispatcher(DispatcherContract $dispatcher)
* @method static void dispatch(MayPromised $job)
* @see \Tochka\Promises\Core\Support\BaseJobDispatcher
* @codeCoverageIgnore
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Tochka\Promises\Contracts\PromisedEvent;

/**
* @method static dispatch(PromisedEvent $event)
* @method static void dispatch(PromisedEvent $event)
* @see \Tochka\Promises\Core\Support\EventDispatcher
* @codeCoverageIgnore
*/
Expand Down
Loading

0 comments on commit 04fcae9

Please sign in to comment.