Skip to content

Commit 8a89fb9

Browse files
authored
Merge pull request #171 from j-guyon/code-styling-harmonization
Add and apply php_cs ruleset
2 parents 6a7934b + 36bb16d commit 8a89fb9

32 files changed

+373
-366
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor/
22
composer.lock
33
build/
4+
.php_cs.cache

.php_cs.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
->exclude('build');
6+
7+
return PhpCsFixer\Config::create()
8+
->setRules(
9+
[
10+
'@Symfony' => true,
11+
'no_superfluous_phpdoc_tags' => false,
12+
'array_syntax' => ['syntax' => 'short'],
13+
]
14+
)
15+
->setFinder($finder);

Command/ExecuteCommand.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@
33
namespace JMose\CommandSchedulerBundle\Command;
44

55
use Cron\CronExpression;
6+
use JMose\CommandSchedulerBundle\Entity\ScheduledCommand;
67
use Symfony\Bridge\Doctrine\ManagerRegistry;
78
use Symfony\Component\Console\Command\Command;
8-
use Symfony\Component\Console\Input\StringInput;
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Input\InputOption;
11+
use Symfony\Component\Console\Input\StringInput;
1112
use Symfony\Component\Console\Output\NullOutput;
1213
use Symfony\Component\Console\Output\OutputInterface;
1314
use Symfony\Component\Console\Output\StreamOutput;
14-
use JMose\CommandSchedulerBundle\Entity\ScheduledCommand;
1515

1616
/**
17-
* Class ExecuteCommand : This class is the entry point to execute all scheduled command
17+
* Class ExecuteCommand : This class is the entry point to execute all scheduled command.
1818
*
1919
* @author Julien Guyon <julienguyon@hotmail.com>
20-
* @package JMose\CommandSchedulerBundle\Command
2120
*/
2221
class ExecuteCommand extends Command
2322
{
24-
2523
/**
2624
* @var \Doctrine\ORM\EntityManager
2725
*/
@@ -33,17 +31,18 @@ class ExecuteCommand extends Command
3331
private $logPath;
3432

3533
/**
36-
* @var boolean
34+
* @var bool
3735
*/
3836
private $dumpMode;
3937

4038
/**
41-
* @var integer
39+
* @var int
4240
*/
4341
private $commandsVerbosity;
4442

4543
/**
4644
* ExecuteCommand constructor.
45+
*
4746
* @param ManagerRegistry $managerRegistry
4847
* @param $managerName
4948
* @param $logPath
@@ -62,7 +61,7 @@ public function __construct(ManagerRegistry $managerRegistry, $managerName, $log
6261
}
6362

6463
/**
65-
* @inheritdoc
64+
* {@inheritdoc}
6665
*/
6766
protected function configure()
6867
{
@@ -75,9 +74,9 @@ protected function configure()
7574
}
7675

7776
/**
78-
* Initialize parameters and services used in execute function
77+
* Initialize parameters and services used in execute function.
7978
*
80-
* @param InputInterface $input
79+
* @param InputInterface $input
8180
* @param OutputInterface $output
8281
*/
8382
protected function initialize(InputInterface $input, OutputInterface $output)
@@ -93,16 +92,17 @@ protected function initialize(InputInterface $input, OutputInterface $output)
9392
}
9493

9594
/**
96-
* @param InputInterface $input
95+
* @param InputInterface $input
9796
* @param OutputInterface $output
97+
*
9898
* @return int
9999
*/
100100
protected function execute(InputInterface $input, OutputInterface $output)
101101
{
102102
$output->writeln('<info>Start : '.($this->dumpMode ? 'Dump' : 'Execute').' all scheduled command</info>');
103103

104104
// Before continue, we check that the output file is valid and writable (except for gaufrette)
105-
if (false !== $this->logPath && strpos($this->logPath, 'gaufrette:') !== 0 && false === is_writable(
105+
if (false !== $this->logPath && 0 !== strpos($this->logPath, 'gaufrette:') && false === is_writable(
106106
$this->logPath
107107
)
108108
) {
@@ -118,7 +118,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
118118

119119
$noneExecution = true;
120120
foreach ($commands as $command) {
121-
122121
$this->em->refresh($this->em->find(ScheduledCommand::class, $command));
123122
if ($command->isDisabled() || $command->isLocked()) {
124123
continue;
@@ -161,8 +160,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
161160

162161
/**
163162
* @param ScheduledCommand $scheduledCommand
164-
* @param OutputInterface $output
165-
* @param InputInterface $input
163+
* @param OutputInterface $output
164+
* @param InputInterface $input
166165
*/
167166
private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterface $output, InputInterface $input)
168167
{
@@ -174,7 +173,7 @@ private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterf
174173
->getRepository(ScheduledCommand::class)
175174
->getNotLockedCommand($scheduledCommand);
176175
//$notLockedCommand will be locked for avoiding parallel calls: http://dev.mysql.com/doc/refman/5.7/en/innodb-locking-reads.html
177-
if ($notLockedCommand === null) {
176+
if (null === $notLockedCommand) {
178177
throw new \Exception();
179178
}
180179

Command/MonitorCommand.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010

1111
/**
12-
* Class MonitorCommand : This class is used for monitoring scheduled commands if they run for too long or failed to execute
12+
* Class MonitorCommand : This class is used for monitoring scheduled commands if they run for too long or failed to execute.
1313
*
1414
* @author Daniel Fischer <dfischer000@gmail.com>
15-
* @package JMose\CommandSchedulerBundle\Command
1615
*/
1716
class MonitorCommand extends Command
1817
{
19-
2018
/**
2119
* @var \Doctrine\ORM\EntityManager
2220
*/
2321
private $em;
2422

2523
/**
26-
* @var boolean
24+
* @var bool
2725
*/
2826
private $dumpMode;
2927

3028
/**
31-
* @var integer|boolean Number of seconds after a command is considered as timeout
29+
* @var int|bool Number of seconds after a command is considered as timeout
3230
*/
3331
private $lockTimeout;
3432

@@ -43,12 +41,13 @@ class MonitorCommand extends Command
4341
private $mailSubject;
4442

4543
/**
46-
* @var boolean if true, current command will send mail even if all is ok.
44+
* @var bool if true, current command will send mail even if all is ok.
4745
*/
4846
private $sendMailIfNoError;
4947

5048
/**
5149
* MonitorCommand constructor.
50+
*
5251
* @param ManagerRegistry $managerRegistry
5352
* @param $managerName
5453
* @param $lockTimeout
@@ -74,7 +73,7 @@ public function __construct(
7473
}
7574

7675
/**
77-
* @inheritdoc
76+
* {@inheritdoc}
7877
*/
7978
protected function configure()
8079
{
@@ -86,15 +85,16 @@ protected function configure()
8685
}
8786

8887
/**
89-
* @param InputInterface $input
88+
* @param InputInterface $input
9089
* @param OutputInterface $output
91-
* @return int|null|void
90+
*
91+
* @return int|void|null
9292
*/
9393
protected function execute(InputInterface $input, OutputInterface $output)
9494
{
9595
// If not in dump mode and none receiver is set, exit.
9696
$this->dumpMode = $input->getOption('dump');
97-
if (!$this->dumpMode && count($this->receiver) === 0) {
97+
if (!$this->dumpMode && 0 === count($this->receiver)) {
9898
$output->writeln('Please add receiver in configuration');
9999

100100
return 1;
@@ -106,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
106106

107107
// Commands in error
108108
if (count($failedCommands) > 0) {
109-
$message = "";
109+
$message = '';
110110

111111
foreach ($failedCommands as $command) {
112112
$message .= sprintf(
@@ -124,7 +124,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
124124
} else {
125125
$this->sendMails($message);
126126
}
127-
128127
} else {
129128
if ($this->dumpMode) {
130129
$output->writeln('No errors found.');
@@ -137,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
137136
}
138137

139138
/**
140-
* Send message to email receivers
139+
* Send message to email receivers.
141140
*
142141
* @param string $message message to be sent
143142
*/
@@ -155,7 +154,7 @@ private function sendMails($message)
155154
}
156155

157156
/**
158-
* get the subject for monitor mails
157+
* get the subject for monitor mails.
159158
*
160159
* @return string subject
161160
*/
@@ -165,5 +164,4 @@ private function getMailSubject()
165164

166165
return sprintf($this->mailSubject, $hostname, date('Y-m-d H:i:s'));
167166
}
168-
169167
}

Command/StartSchedulerCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace JMose\CommandSchedulerBundle\Command;
34

45
use Symfony\Component\Console\Command\Command;
@@ -11,10 +12,9 @@
1112
/**
1213
* Code originally taken from https://github.com/Cron/Symfony-Bundle/blob/2.1.0/Command/CronStartCommand.php
1314
* License: MIT (according to https://github.com/Cron/Symfony-Bundle/blob/2.1.0/LICENSE)
14-
* Original author: Alexander Lokhman <alex.lokhman@gmail.com>
15+
* Original author: Alexander Lokhman <alex.lokhman@gmail.com>.
1516
*
1617
* Adaption to CommandSchedulerBundle by Christoph Singer <singer@webagentur72.de>
17-
*
1818
*/
1919
class StartSchedulerCommand extends Command
2020
{
@@ -87,4 +87,4 @@ private function scheduler(OutputInterface $output, $pidFile)
8787
$command->run($input, $output);
8888
}
8989
}
90-
}
90+
}

Command/StopSchedulerCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace JMose\CommandSchedulerBundle\Command;
34

45
use Symfony\Component\Console\Command\Command;
@@ -8,10 +9,9 @@
89
/**
910
* Code originally taken from https://github.com/Cron/Symfony-Bundle/blob/2.1.0/Command/CronStopCommand.php
1011
* License: MIT (according to https://github.com/Cron/Symfony-Bundle/blob/2.1.0/LICENSE)
11-
* Original author: Alexander Lokhman <alex.lokhman@gmail.com>
12+
* Original author: Alexander Lokhman <alex.lokhman@gmail.com>.
1213
*
1314
* Adaption to CommandSchedulerBundle by Christoph Singer <singer@webagentur72.de>
14-
*
1515
*/
1616
class StopSchedulerCommand extends Command
1717
{
@@ -23,6 +23,7 @@ protected function configure()
2323
$this->setName('scheduler:stop')
2424
->setDescription('Stops command scheduler');
2525
}
26+
2627
/**
2728
* {@inheritdoc}
2829
*/
@@ -40,11 +41,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
4041
throw new \RuntimeException('Unable to stop scheduler.');
4142
}
4243
$output->writeln(sprintf('<comment>%s</comment>', 'Unable to kill command scheduler process. Scheduler will be stopped before the next run.'));
44+
4345
return 0;
4446
}
4547
unlink($pidFile);
4648
$output->writeln(sprintf('<info>%s</info>', 'Command scheduler is stopped.'));
4749

4850
return 0;
4951
}
50-
}
52+
}

0 commit comments

Comments
 (0)