-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix the type related issues, replace the doc types with PHP type wherever safe * feat: run on symfony 7 * fix: $scriptName must not be acces sed before initialization * feat: replace annotations with attributes * fix: add strict types * chore: use only needed libraries --------- Co-authored-by: Musa Haidari <[email protected]>
- Loading branch information
1 parent
a59afb8
commit 2c0341f
Showing
28 changed files
with
363 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
/** | ||
* This file is part of the SymfonyCronBundle package. | ||
* | ||
|
@@ -11,12 +11,13 @@ | |
|
||
use Cron\CronBundle\Cron\CronCommand; | ||
use Cron\CronBundle\Entity\CronJob; | ||
use Symfony\Component\Console\Question\Question; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use InvalidArgumentException; | ||
use Symfony\Component\Console\Helper\HelperInterface; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
use Symfony\Component\Console\Question\Question; | ||
|
||
/** | ||
* @author Dries De Peuter <[email protected]> | ||
|
@@ -26,7 +27,7 @@ class CronCreateCommand extends CronCommand | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
protected function configure(): void | ||
{ | ||
$this->setName('cron:create') | ||
->setDescription('Create a cron job') | ||
|
@@ -37,14 +38,7 @@ protected function configure() | |
->addOption('enabled', null, InputOption::VALUE_REQUIRED, 'Is the job enabled'); | ||
} | ||
|
||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$job = new CronJob(); | ||
|
||
|
@@ -108,18 +102,16 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
/** | ||
* Validate the job name. | ||
* | ||
* @param string $name | ||
* @return string | ||
* @throws \InvalidArgumentException | ||
* @throws InvalidArgumentException | ||
*/ | ||
protected function validateJobName($name) | ||
protected function validateJobName(?string $name): string | ||
{ | ||
if (!$name || strlen($name) == 0) { | ||
throw new \InvalidArgumentException('Please set a name.'); | ||
throw new InvalidArgumentException('Please set a name.'); | ||
} | ||
|
||
if ($this->queryJob($name)) { | ||
throw new \InvalidArgumentException('Name already in use.'); | ||
throw new InvalidArgumentException('Name already in use.'); | ||
} | ||
|
||
return $name; | ||
|
@@ -128,47 +120,36 @@ protected function validateJobName($name) | |
/** | ||
* Validate the command. | ||
* | ||
* @param string $command | ||
* @return string | ||
* @throws \InvalidArgumentException | ||
* @throws InvalidArgumentException | ||
*/ | ||
protected function validateCommand($command) | ||
protected function validateCommand(string $command): string | ||
{ | ||
$parts = explode(' ', $command); | ||
$this->getApplication()->get((string) $parts[0]); | ||
$this->getApplication()->get($parts[0]); | ||
|
||
return $command; | ||
} | ||
|
||
/** | ||
* Validate the schedule. | ||
* | ||
* @param string $schedule | ||
* @return string | ||
* @throws \InvalidArgumentException | ||
* @throws InvalidArgumentException | ||
*/ | ||
protected function validateSchedule($schedule) | ||
protected function validateSchedule(string $schedule): string | ||
{ | ||
$this->getContainer()->get('cron.validator') | ||
->validate($schedule); | ||
|
||
return $schedule; | ||
} | ||
|
||
/** | ||
* @param string $jobName | ||
* @return CronJob | ||
*/ | ||
protected function queryJob($jobName) | ||
protected function queryJob(string $jobName): ?CronJob | ||
{ | ||
return $this->getContainer()->get('cron.manager') | ||
->getJobByName($jobName); | ||
} | ||
|
||
/** | ||
* @return QuestionHelper | ||
*/ | ||
private function getQuestionHelper() | ||
private function getQuestionHelper(): HelperInterface | ||
{ | ||
return $this->getHelperSet()->get('question'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
/** | ||
* This file is part of the SymfonyCronBundle package. | ||
* | ||
|
@@ -11,10 +11,12 @@ | |
|
||
use Cron\CronBundle\Cron\CronCommand; | ||
use Cron\CronBundle\Entity\CronJob; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
use InvalidArgumentException; | ||
use Symfony\Component\Console\Helper\HelperInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
|
||
/** | ||
* @author Dries De Peuter <[email protected]> | ||
|
@@ -24,30 +26,23 @@ class CronDeleteCommand extends CronCommand | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
protected function configure(): void | ||
{ | ||
$this->setName('cron:delete') | ||
->setDescription('Delete a cron job') | ||
->addArgument('job', InputArgument::REQUIRED, 'The job to delete'); | ||
} | ||
|
||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$job = $this->queryJob($input->getArgument('job')); | ||
|
||
if (!$job) { | ||
throw new \InvalidArgumentException('Unknown job.'); | ||
throw new InvalidArgumentException('Unknown job.'); | ||
} | ||
|
||
if ($job->getEnabled()) { | ||
throw new \InvalidArgumentException('The job should be disabled first.'); | ||
throw new InvalidArgumentException('The job should be disabled first.'); | ||
} | ||
|
||
$output->writeln(sprintf('<info>You are about to delete "%s".</info>', $job->getName())); | ||
|
@@ -61,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
); | ||
|
||
if (!$this->getQuestionHelper()->ask($input, $output, $question)) { | ||
return; | ||
return 0; | ||
} | ||
|
||
$this->getContainer()->get('cron.manager') | ||
|
@@ -72,20 +67,13 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
return 0; | ||
} | ||
|
||
/** | ||
* @param string $jobName | ||
* @return CronJob | ||
*/ | ||
protected function queryJob($jobName) | ||
protected function queryJob(string $jobName): ?CronJob | ||
{ | ||
return $this->getContainer()->get('cron.manager') | ||
->getJobByName($jobName); | ||
} | ||
|
||
/** | ||
* @return QuestionHelper | ||
*/ | ||
private function getQuestionHelper() | ||
private function getQuestionHelper(): HelperInterface | ||
{ | ||
return $this->getHelperSet()->get('question'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
/** | ||
* This file is part of the SymfonyCronBundle package. | ||
* | ||
|
@@ -11,10 +11,8 @@ | |
|
||
use Cron\CronBundle\Cron\CronCommand; | ||
use Cron\CronBundle\Entity\CronJob; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* @author Dries De Peuter <[email protected]> | ||
|
@@ -24,20 +22,13 @@ class CronListCommand extends CronCommand | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
protected function configure(): void | ||
{ | ||
$this->setName('cron:list') | ||
->setDescription('List all available crons'); | ||
} | ||
|
||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$jobs = $this->queryJobs(); | ||
|
||
|
@@ -52,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
/** | ||
* @return CronJob[] | ||
*/ | ||
protected function queryJobs() | ||
protected function queryJobs(): array | ||
{ | ||
return $this->getContainer()->get('cron.manager')->listJobs(); | ||
} | ||
|
Oops, something went wrong.