Skip to content

Commit abab77c

Browse files
author
Oliver Stark
authored
Merge pull request #54 from ostark/feature/craft4
Feature/craft4
2 parents 7839e42 + 1889037 commit abab77c

17 files changed

+127
-58
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [3.0.0] - 2022-05-12
6+
- Craft 4 support
7+
- PHP 8 syntax
8+
59
## [2.3.0] - 2021-05-04
610
### Changed
711
- Added dependency `treeware/plant`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This package is [Treeware](https://treeware.earth). If you use it in production,
2424

2525
## Requirements
2626

27-
* Craft 3
27+
* Craft 3 or 4
2828
* Permissions to execute a php binary
2929
* proc_open()
3030
* **PHP >=7.1** (for PHP 7.0 use `ostark/craft-async-queue:1.3.*`)

composer.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
}
2222
],
2323
"require": {
24-
"php": ">=7.1",
25-
"craftcms/cms": "^3.0.0",
26-
"symfony/process": "^4.2|^5.0",
24+
"php": "^8.0",
25+
"craftcms/cms": "^4.0.0",
26+
"symfony/process": "^5.0",
2727
"treeware/plant": "^0.1.0"
2828
},
2929
"autoload": {
@@ -40,11 +40,21 @@
4040
"changelogUrl": "https://raw.githubusercontent.com/ostark/craft-async-queue/master/CHANGELOG.md"
4141
},
4242
"require-dev": {
43-
"phpunit/phpunit": "^7.0|^8.0",
44-
"vimeo/psalm": "^4.4"
43+
"phpunit/phpunit": "^8.0|^9.0",
44+
"craftcms/phpstan": "*",
45+
"craftcms/rector": "dev-main"
4546
},
4647
"scripts": {
47-
"psalm": "vendor/bin/psalm",
48+
"phpstan": "vendor/bin/phpstan",
4849
"tests": "vendor/bin/phpunit --testdox"
49-
}
50+
},
51+
"config": {
52+
"allow-plugins": {
53+
"yiisoft/yii2-composer": true,
54+
"craftcms/plugin-installer": true,
55+
"treeware/plant": true
56+
}
57+
},
58+
"prefer-stable": true,
59+
"minimum-stability": "dev"
5060
}

phpstan.neon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
includes:
2+
- vendor/craftcms/phpstan/phpstan.neon
3+
parameters:
4+
level: 6
5+
bootstrapFiles:
6+
- tests/bootstrap.php
7+
paths:
8+
- src
9+
- tests
10+
tmpDir: build/phpstan
11+
checkMissingIterableValueType: false
12+
ignoreErrors:
13+
- "#Negated boolean expression is always false#"

rector.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use craft\rector\SetList as CraftSetList;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Core\ValueObject\PhpVersion;
8+
use Rector\PHPUnit\Set\PHPUnitSetList;
9+
use Rector\Renaming\Rector\Name\RenameClassRector;
10+
use Rector\Set\ValueObject\LevelSetList;
11+
use Rector\Set\ValueObject\SetList;
12+
13+
return static function (RectorConfig $rectorConfig): void {
14+
15+
// PHP 8.0
16+
$rectorConfig->phpVersion(PhpVersion::PHP_80);
17+
$rectorConfig->import(LevelSetList::UP_TO_PHP_80);
18+
19+
// Misc
20+
$rectorConfig->import(CraftSetList::CRAFT_CMS_40);
21+
$rectorConfig->import(SetList::DEAD_CODE);
22+
$rectorConfig->import(SetList::TYPE_DECLARATION);
23+
$rectorConfig->import(SetList::CODE_QUALITY);
24+
$rectorConfig->import(SetList::CODING_STYLE);
25+
$rectorConfig->import(PHPUnitSetList::PHPUNIT_90);
26+
27+
$rectorConfig->skip([
28+
\Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
29+
\Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector::class,
30+
\Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector::class,
31+
\Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector::class,
32+
\Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector::class,
33+
\Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
34+
\Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector::class,
35+
\Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector::class,
36+
\Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector::class,
37+
\Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector::class,
38+
\Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector::class,
39+
\Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector::class,
40+
\Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector::class,
41+
\Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector::class,
42+
\Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class,
43+
\Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector::class,
44+
\Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector::class
45+
]);
46+
47+
48+
};
49+
50+
51+
52+
53+

src/BackgroundProcess.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function start()
4141

4242
try {
4343
$process->run();
44-
} catch (\Symfony\Component\Process\Exception\RuntimeException $e) {
45-
$e = new RuntimeException($e->getMessage());
46-
$e->setProcess($process);
47-
throw $e;
48-
} catch (\Symfony\Component\Process\Exception\LogicException $e) {
49-
$e = new LogicException($e->getMessage());
50-
$e->setProcess($process);
51-
throw $e;
44+
} catch (\Symfony\Component\Process\Exception\RuntimeException $runtimeException) {
45+
$runtimeException = new RuntimeException($runtimeException->getMessage());
46+
$runtimeException->setProcess($process);
47+
throw $runtimeException;
48+
} catch (\Symfony\Component\Process\Exception\LogicException $logicException) {
49+
$logicException = new LogicException($logicException->getMessage());
50+
$logicException->setProcess($process);
51+
throw $logicException;
5252
}
5353

5454
return $process;

src/Exceptions/LogicException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class LogicException extends \LogicException implements ProcessException
66
{
7-
protected $process;
7+
protected Process $process;
88

99
public function setProcess(Process $process): void
1010
{

src/Handlers/BackgroundQueueHandler.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ class BackgroundQueueHandler
1818

1919
/**
2020
* BackgroundQueue constructor.
21-
*
22-
* @param \ostark\AsyncQueue\Plugin $plugin
2321
*/
2422
public function __construct(Plugin $plugin)
2523
{
2624
$this->plugin = $plugin;
2725
}
2826

29-
public function __invoke(PushEvent $event)
27+
public function __invoke(PushEvent $event): void
3028
{
3129
$context = ($event->job instanceof JobInterface)
3230
? $event->job->getDescription()
@@ -39,7 +37,7 @@ public function __invoke(PushEvent $event)
3937
$this->plugin->getRateLimiter()->increment();
4038
$handled = true;
4139

42-
} catch (PhpExecutableNotFound $e) {
40+
} catch (PhpExecutableNotFound) {
4341
Craft::debug(
4442
'QueueHandler::startBackgroundProcess() (PhpExecutableNotFound)',
4543
'async-queue'
@@ -69,6 +67,7 @@ protected function logPushEvent(PushEvent $event, bool $handled = false): void
6967
if (!YII_DEBUG) {
7068
return;
7169
}
70+
7271
if ($event->job instanceof BaseJob) {
7372
Craft::debug(
7473
Craft::t(

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getRateLimiter(): RateLimiter
7474
/**
7575
* Creates and returns the model used to store the plugin’s settings.
7676
*/
77-
protected function createSettingsModel() : Settings
77+
protected function createSettingsModel() : ?\craft\base\Model
7878
{
7979
return new Settings();
8080
}

src/QueueCommand.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77

88
class QueueCommand extends Component
99
{
10-
const DEFAULT_SCRIPT = "craft";
11-
const DEFAULT_ARGS = "queue/run";
12-
const EVENT_PREPARE_COMMAND = 'prepareCommand';
10+
public const DEFAULT_SCRIPT = "craft";
1311

14-
protected $scriptName;
15-
protected $scriptArgs;
12+
public const DEFAULT_ARGS = "queue/run";
13+
14+
public const EVENT_PREPARE_COMMAND = 'prepareCommand';
15+
16+
protected string $scriptName;
17+
18+
protected string $scriptArgs;
1619

1720
/**
1821
* QueueCommand constructor.
1922
*
2023
* @param string|null $scriptName
2124
* @param string|null $scriptArgs
22-
* @param array $config
2325
*/
2426
public function __construct(string $scriptName = null, string $scriptArgs = null, array $config = [])
2527
{
@@ -32,7 +34,6 @@ public function __construct(string $scriptName = null, string $scriptArgs = null
3234
/**
3335
* @param callable|null $wrapper
3436
*
35-
* @return string
3637
* @throws \ostark\AsyncQueue\Exceptions\PhpExecutableNotFound
3738
*/
3839
public function getPreparedCommand(callable $wrapper = null): string
@@ -44,18 +45,14 @@ public function getPreparedCommand(callable $wrapper = null): string
4445
throw new PhpExecutableNotFound('Unable to find php executable.');
4546
}
4647

47-
$commandLine = join(" ", [$php, $this->scriptName, $this->scriptArgs]);
48+
$commandLine = implode(" ", [$php, $this->scriptName, $this->scriptArgs]);
4849

4950
return $this->decorate($commandLine);
5051
}
5152

5253

5354
/**
5455
* Wrapper
55-
*
56-
* @param string $commandLine
57-
*
58-
* @return string
5956
*/
6057
protected function decorate(string $commandLine): string
6158
{
@@ -64,12 +61,12 @@ protected function decorate(string $commandLine): string
6461
$this->trigger(self::EVENT_PREPARE_COMMAND, $event);
6562
$commandLine = $event->commandLine;
6663

67-
if ($event->useDefaultDecoration === false) {
64+
if (!$event->useDefaultDecoration) {
6865
return $commandLine;
6966
}
7067

7168
// default decoration
72-
return "nice $commandLine > /dev/null 2>&1 &";
69+
return "nice -n 15 {$commandLine} > /dev/null 2>&1 &";
7370
}
7471

7572
}

0 commit comments

Comments
 (0)