From c170c3e52c424e49f35dcde4d2c5a5b31a8b2375 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Tue, 3 Jan 2023 16:02:40 +0100 Subject: [PATCH 1/7] feat: drop support of symfony < 4.4 --- .github/workflows/test.yml | 2 +- composer.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 68c4992..4c96834 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: matrix: include: - php-versions: 7.3 - symfony-versions: 3.4.* + symfony-versions: 4.4.* - php-versions: 7.4 symfony-versions: 4.4.* - php-versions: 7.4 diff --git a/composer.json b/composer.json index 08b9b9f..53bd04c 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,14 @@ ], "require": { "php": ">=7.3", - "symfony/process": "^3.4|^4.4|^5.4|^6.0" + "symfony/process": "^4.4|^5.4|^6.0" }, "suggest": { "symfony/filesystem": "Allows using Symfony Filesystem" }, "require-dev": { "roave/security-advisories": "dev-master", - "symfony/filesystem": "^3.4|^4.4|^5.4|^6.0", + "symfony/filesystem": "^4.4|^5.4|^6.0", "phpunit/phpunit": "^9.5" }, "autoload": { From 2d9bf9014333b08dfe82803e01beb3e1ded129d4 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Tue, 3 Jan 2023 16:25:04 +0100 Subject: [PATCH 2/7] feat: drop support of symfony < 4.4, drop support of php 7 --- .github/workflows/test.yml | 6 +-- composer.json | 3 +- phpunit.xml.dist | 52 +++++++++++++------------- src/Formatter/Comment.php | 9 +---- src/Formatter/Cron.php | 5 +-- src/Formatter/Header.php | 38 +++++-------------- src/Formatter/Job.php | 17 ++------- src/Formatter/Output.php | 20 +++------- src/Formatter/Time.php | 21 +++-------- src/Updater/CommandCronManipulator.php | 19 ++-------- src/Updater/CronUpdater.php | 9 +---- src/Updater/SymfonyFileSystem.php | 3 +- tests/Formatter/CronTest.php | 4 +- tests/Updater/CronUpdaterTest.php | 9 ++--- 14 files changed, 68 insertions(+), 147 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c96834..4674b54 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,12 +8,8 @@ jobs: strategy: matrix: include: - - php-versions: 7.3 - symfony-versions: 4.4.* - - php-versions: 7.4 + - php-versions: 8.0 symfony-versions: 4.4.* - - php-versions: 7.4 - symfony-versions: 5.4.* - php-versions: 8.0 symfony-versions: 5.4.* - php-versions: 8.0 diff --git a/composer.json b/composer.json index 53bd04c..6ec94e0 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,13 @@ } ], "require": { - "php": ">=7.3", + "php": ">=8.0.2", "symfony/process": "^4.4|^5.4|^6.0" }, "suggest": { "symfony/filesystem": "Allows using Symfony Filesystem" }, "require-dev": { - "roave/security-advisories": "dev-master", "symfony/filesystem": "^4.4|^5.4|^6.0", "phpunit/phpunit": "^9.5" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7a71ad9..01dd99f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,28 @@ - - - - - - tests - - - - - - ./src - - ./tests - ./vendor - - - + + + + ./src + + + ./tests + ./vendor + + + + + tests + + diff --git a/src/Formatter/Comment.php b/src/Formatter/Comment.php index 2d1d789..6da799f 100644 --- a/src/Formatter/Comment.php +++ b/src/Formatter/Comment.php @@ -4,13 +4,8 @@ class Comment { - /** @var string */ - private $comment; - - public function __construct(string $comment) - { - $this->comment = $comment; - } + public function __construct(private string $comment) + {} public function format(): string { diff --git a/src/Formatter/Cron.php b/src/Formatter/Cron.php index 27667d8..682bf51 100644 --- a/src/Formatter/Cron.php +++ b/src/Formatter/Cron.php @@ -4,11 +4,10 @@ class Cron { - /** @var Header */ - private $header; + private ?Header $header = null; /** @var mixed[] */ - private $lines = []; + private array $lines = []; public function header(): Header { diff --git a/src/Formatter/Header.php b/src/Formatter/Header.php index 7055867..d81ce0e 100644 --- a/src/Formatter/Header.php +++ b/src/Formatter/Header.php @@ -4,34 +4,16 @@ class Header { - /** @var Cron */ - private $cron; - - /** @var string */ - private $path; - - /** @var string */ - private $mailTo; - - /** @var string */ - private $home; - - /** @var string */ - private $shell; - - /** @var string */ - private $contentType; - - /** @var string */ - private $encoding; - - /** @var string */ - private $timezone; - - public function __construct(Cron $cron) - { - $this->cron = $cron; - } + private string $path; + private ?string $mailTo = null; + private ?string $home = null; + private ?string $shell = null; + private ?string $contentType = null; + private ?string $encoding = null; + private ?string $timezone = null; + + public function __construct(private Cron $cron) + {} /** * Works just like the shell PATH, but it does not inherit from your environment. diff --git a/src/Formatter/Job.php b/src/Formatter/Job.php index ad68935..f513c7d 100644 --- a/src/Formatter/Job.php +++ b/src/Formatter/Job.php @@ -4,23 +4,12 @@ class Job { - /** @var Cron */ - private $cron; + private Time $time; + private Output $output; - /** @var Time */ - private $time; - - /** @var string */ - private $command; - - /** @var Output */ - private $output; - - public function __construct(string $command, Cron $cron) + public function __construct(private string $command, private Cron $cron) { - $this->cron = $cron; $this->time = new Time; - $this->command = $command; $this->output = new Output; } diff --git a/src/Formatter/Output.php b/src/Formatter/Output.php index f63f204..37a5032 100644 --- a/src/Formatter/Output.php +++ b/src/Formatter/Output.php @@ -5,21 +5,11 @@ class Output { public const NO_FILE = '/dev/null'; - - /** @var bool */ - private $noOutput = false; - - /** @var string */ - private $stdOutFile; - - /** @var bool */ - private $stdOutAppend; - - /** @var string */ - private $stdErrFile; - - /** @var bool */ - private $stdErrAppend; + private bool $noOutput = false; + private string $stdOutFile; + private bool $stdOutAppend = false; + private string $stdErrFile; + private bool $stdErrAppend = false; public function suppressOutput(): self { diff --git a/src/Formatter/Time.php b/src/Formatter/Time.php index 7202a46..6cf29a8 100644 --- a/src/Formatter/Time.php +++ b/src/Formatter/Time.php @@ -26,20 +26,11 @@ class Time public const FORMAT = '%-4s %-4s %-4s %-4s %-4s '; public const WILDCARD_TIME = '*'; - /** @var string */ - private $minute = self::WILDCARD_TIME; - - /** @var string */ - private $hour = self::WILDCARD_TIME; - - /** @var string */ - private $dayOfMonth = self::WILDCARD_TIME; - - /** @var string */ - private $month = self::WILDCARD_TIME; - - /** @var string */ - private $dayOfWeek = self::WILDCARD_TIME; + private string $minute = self::WILDCARD_TIME; + private string $hour = self::WILDCARD_TIME; + private string $dayOfMonth = self::WILDCARD_TIME; + private string $month = self::WILDCARD_TIME; + private string $dayOfWeek = self::WILDCARD_TIME; /** * @param string $value 0-59 or a list or range @@ -98,7 +89,7 @@ public function format(): string private function parse(string $value): string { - if (0 === \strpos($value, '/')) { + if (\str_starts_with($value, '/')) { return self::WILDCARD_TIME . $value; } diff --git a/src/Updater/CommandCronManipulator.php b/src/Updater/CommandCronManipulator.php index eba4206..f525836 100644 --- a/src/Updater/CommandCronManipulator.php +++ b/src/Updater/CommandCronManipulator.php @@ -4,21 +4,10 @@ class CommandCronManipulator implements CronManipulator { - /** @var ProcessRunner */ - private $processRunner; - - /** @var FileSystem */ - private $fileSystem; - - /** @var string */ - private $cronCommand; - - public function __construct(ProcessRunner $processRunner, FileSystem $fileSystem, string $cronCommand = 'crontab') - { - $this->processRunner = $processRunner; - $this->fileSystem = $fileSystem; - $this->cronCommand = $cronCommand; - } + public function __construct(private ProcessRunner $processRunner, + private FileSystem $fileSystem, + private string $cronCommand = 'crontab') + {} public function replace(string $contents): void { diff --git a/src/Updater/CronUpdater.php b/src/Updater/CronUpdater.php index 8638b0a..29cf4bd 100644 --- a/src/Updater/CronUpdater.php +++ b/src/Updater/CronUpdater.php @@ -9,13 +9,8 @@ class CronUpdater public const KEY_BEGIN = '# KEY %key%'; public const KEY_END = '# END'; - /** @var CronManipulator */ - private $cronManipulator; - - public function __construct(CronManipulator $cronManipulator) - { - $this->cronManipulator = $cronManipulator; - } + public function __construct(private CronManipulator $cronManipulator) + {} public static function createDefault(): self { diff --git a/src/Updater/SymfonyFileSystem.php b/src/Updater/SymfonyFileSystem.php index 7fd135e..cb587f7 100644 --- a/src/Updater/SymfonyFileSystem.php +++ b/src/Updater/SymfonyFileSystem.php @@ -6,8 +6,7 @@ class SymfonyFileSystem implements FileSystem { - /** @var FileSystemHelper; */ - private $filesystem; + private FileSystemHelper $filesystem; public function __construct() { diff --git a/tests/Formatter/CronTest.php b/tests/Formatter/CronTest.php index b01c018..5b1e465 100644 --- a/tests/Formatter/CronTest.php +++ b/tests/Formatter/CronTest.php @@ -1,13 +1,13 @@ Date: Tue, 3 Jan 2023 17:29:01 +0100 Subject: [PATCH 3/7] Update src/Formatter/Header.php Co-authored-by: Max Baldanza --- src/Formatter/Header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Formatter/Header.php b/src/Formatter/Header.php index d81ce0e..87ee4dd 100644 --- a/src/Formatter/Header.php +++ b/src/Formatter/Header.php @@ -4,7 +4,7 @@ class Header { - private string $path; + private ?string $path = null; private ?string $mailTo = null; private ?string $home = null; private ?string $shell = null; From 5b78729fddff89396f497ffae64b3aaf4da89d12 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 3 Jan 2023 17:29:06 +0100 Subject: [PATCH 4/7] Update src/Formatter/Output.php Co-authored-by: Max Baldanza --- src/Formatter/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Formatter/Output.php b/src/Formatter/Output.php index 37a5032..d9b11b9 100644 --- a/src/Formatter/Output.php +++ b/src/Formatter/Output.php @@ -6,7 +6,7 @@ class Output { public const NO_FILE = '/dev/null'; private bool $noOutput = false; - private string $stdOutFile; + private ?string $stdOutFile = null; private bool $stdOutAppend = false; private string $stdErrFile; private bool $stdErrAppend = false; From 747a422781e271b8f08134fdefb20566deee4550 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 3 Jan 2023 17:29:14 +0100 Subject: [PATCH 5/7] Update src/Formatter/Output.php Co-authored-by: Max Baldanza --- src/Formatter/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Formatter/Output.php b/src/Formatter/Output.php index d9b11b9..0143ac6 100644 --- a/src/Formatter/Output.php +++ b/src/Formatter/Output.php @@ -8,7 +8,7 @@ class Output private bool $noOutput = false; private ?string $stdOutFile = null; private bool $stdOutAppend = false; - private string $stdErrFile; + private ?string $stdErrFile = null; private bool $stdErrAppend = false; public function suppressOutput(): self From aaf2c78f6352b269567d0e21728ac74d77a85c72 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Tue, 3 Jan 2023 17:36:11 +0100 Subject: [PATCH 6/7] feat: drop support of symfony < 4.4, drop support of php 7 --- README.md | 2 +- composer.json | 3 +++ tests/Formatter/CronTest.php | 2 +- tests/Updater/CronUpdaterTest.php | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5f26cd4..b1134c2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Easily configure cron through PHP. -If you use Symfony 3/4/5/6, you could use our [cool bundle](https://github.com/mybuilder/cronos-bundle) in order to configure your app jobs through fancy annotations! +If you use Symfony 4/5/6, you could use our [cool bundle](https://github.com/mybuilder/cronos-bundle) in order to configure your app jobs through fancy annotations! ## Setup and Configuration diff --git a/composer.json b/composer.json index 6ec94e0..80553ef 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,9 @@ "autoload": { "psr-4": { "MyBuilder\\Cronos\\": "src" } }, + "autoload-dev": { + "psr-4": { "MyBuilder\\Cronos\\Tests\\": "tests/" } + }, "config": { "bin-dir": "bin" }, diff --git a/tests/Formatter/CronTest.php b/tests/Formatter/CronTest.php index 5b1e465..2997a66 100644 --- a/tests/Formatter/CronTest.php +++ b/tests/Formatter/CronTest.php @@ -1,6 +1,6 @@ Date: Tue, 3 Jan 2023 16:41:13 +0000 Subject: [PATCH 7/7] Run further Symfony versions in PHP8.1 --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4674b54..bc51ed9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,10 @@ jobs: symfony-versions: 5.4.* - php-versions: 8.0 symfony-versions: 6.0.* + - php-versions: 8.1 + symfony-versions: 4.4.* + - php-versions: 8.1 + symfony-versions: 5.4.* - php-versions: 8.1 symfony-versions: 6.2.* - php-versions: 8.2