Skip to content

Commit 43a740f

Browse files
Douglas Greenshieldsgsdevme
authored andcommitted
refactor: add phpstan level 2 coverage
1 parent 5bc2af0 commit 43a740f

11 files changed

+42
-71
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ install:
2424
- if [ "$deps" = "low" ]; then composer --prefer-lowest -n --prefer-stable --prefer-dist update; fi;
2525

2626

27-
script: bin/phpunit && bin/phpstan analyse -l 1 ./
27+
script: bin/phpunit && bin/phpstan analyse -l 2 ./
2828

2929
notifications:
3030

Command/ReadRecurringConsoleJobConfigurationCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7070

7171
/**
7272
* Uses the process component to determine if a command is valid, by looking at the output of cmd:xyz --help
73-
* @param $command
74-
* @return boolean
73+
* @param string $command
74+
* @return bool
7575
*/
7676
private function isCommandValid($command)
7777
{

Model/Queue.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ class Queue
4646
*/
4747
private $idleSince;
4848

49-
/**
50-
* Queue constructor.
51-
*
52-
* @param $name
53-
* @param $vhost
54-
* @param $state
55-
* @param $consumerCount
56-
* @param $messages
57-
* @param $messagesReady
58-
* @param $messagesUnacknowledged
59-
* @param \DateTime $idleSince
60-
*/
6149
public function __construct(
6250
$name,
6351
$vhost,
@@ -81,12 +69,11 @@ public function __construct(
8169
/**
8270
* Takes the response from the RabbitMq Api for queues and uses it to build an instance of this class
8371
*
84-
* @param $response string
72+
* @param array $response
8573
* @return Queue
8674
*/
8775
public static function constructFromApiResponse(array $response)
8876
{
89-
9077
return new self(
9178
isset($response['name']) ? $response['name'] : 'undefined',
9279
isset($response['vhost']) ? $response['vhost'] : 'undefined',

Model/ScheduledJobRepositoryInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
interface ScheduledJobRepositoryInterface
88
{
9-
109
/**
1110
* @return mixed
1211
*/

Service/CliConsumerConfigFileWriter.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ class CliConsumerConfigFileWriter
5252
*/
5353
private $topics;
5454

55-
/**
56-
* @param $logPath
57-
* @param $configFilePath
58-
* @param $host
59-
* @param $username
60-
* @param $password
61-
* @param $vhost
62-
* @param $port
63-
*/
6455
public function __construct(
6556
$logPath,
6657
$configFilePath,
@@ -117,9 +108,9 @@ public function writeConfig($uniqueEnvironment)
117108
}
118109

119110
/**
120-
* @param $uniqueEnvironment
121-
* @param $topic
122-
* @param $topicConfig
111+
* @param string $uniqueEnvironment
112+
* @param string $topic
113+
* @param array $topicConfig
123114
* @return string
124115
*/
125116
public function getConfigString($uniqueEnvironment, $topic, $topicConfig)

Service/JobManager.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
use Markup\JobQueueBundle\Job\ConsoleCommandJob;
66
use Markup\JobQueueBundle\Model\Job;
77
use Markup\JobQueueBundle\Publisher\JobPublisher;
8-
use Symfony\Bundle\FrameworkBundle\Console\Application;
98

109
/**
1110
* Controller for adding jobs to a queue
1211
* or scheduling them to be added at a later date
1312
*/
1413
class JobManager
1514
{
16-
1715
/**
1816
* @var JobPublisher
1917
*/
@@ -40,7 +38,7 @@ public function addJob(Job $job, $dateTime = null)
4038
{
4139
if ($dateTime === null) {
4240
$this->publisher->publish($job);
43-
} else {
41+
} elseif ($job instanceof ConsoleCommandJob) {
4442
$this->scheduledJob->addScheduledJob($job, $dateTime);
4543
}
4644
}
@@ -64,11 +62,11 @@ public function addCommandJob($command, $topic = 'default', $timeout = 60, $idle
6462

6563
/**
6664
* Adds a named command to the job queue at a specific datetime
67-
* @param string $command A valid command for this application.
68-
* @param string $dateTime The DateTime to execute the command.
69-
* @param string $topic The name of a valid topic.
70-
* @param integer $timeout The amount of time to allow the command to run.
71-
* @param integer $idleTimeout The amount of idle time to allow the command to run. Default to the same as timeout.
65+
* @param string $command A valid command for this application.
66+
* @param \DateTime $dateTime The DateTime to execute the command.
67+
* @param string $topic The name of a valid topic.
68+
* @param int $timeout The amount of time to allow the command to run.
69+
* @param int $idleTimeout The amount of idle time to allow the command to run. Default to the same as timeout.
7270
*/
7371
public function addScheduledCommandJob(
7472
$command,

Service/RecurringConsoleCommandReader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class RecurringConsoleCommandReader
3434
private $configurations;
3535

3636
/**
37-
* @param $kernelPath string
37+
* @param string $kernelPath
3838
*/
3939
public function __construct(
4040
$kernelPath
@@ -69,7 +69,7 @@ public function getConfigurations()
6969
}
7070

7171
/**
72-
* @param $uuid
72+
* @param string $id
7373
*/
7474
public function getConfigurationById($id)
7575
{
@@ -115,7 +115,7 @@ public function getConfigurationCommands()
115115
* Parses the configuration and returns an array of of configuration objects
116116
* Configuration is cached after running this function so it should only be run once
117117
*
118-
* @param ArrayCollection<RecurringConsoleCommandConfiguration>
118+
* @return ArrayCollection<RecurringConsoleCommandConfiguration>
119119
*/
120120
private function parseConfiguration(array $config)
121121
{

Service/ScheduledJobService.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Markup\JobQueueBundle\Service;
44

55
use Doctrine\Common\Persistence\ManagerRegistry;
6-
use Doctrine\Common\Persistence\ObjectRepository;
7-
use Markup\JobQueueBundle\Entity\Repository\ScheduledJobRepository;
86
use Markup\JobQueueBundle\Entity\ScheduledJob;
9-
use Markup\JobQueueBundle\Model\Job;
7+
use Markup\JobQueueBundle\Job\ConsoleCommandJob;
8+
use Markup\JobQueueBundle\Model\ScheduledJobRepositoryInterface;
109

1110
class ScheduledJobService
1211
{
@@ -25,11 +24,11 @@ public function __construct(
2524
}
2625

2726
/**
28-
* @param Job $job
29-
* @param \DateTime $scheduledTime
27+
* @param ConsoleCommandJob $job
28+
* @param \DateTime|string $scheduledTime
3029
* @return ScheduledJob
3130
*/
32-
public function addScheduledJob(Job $job, $scheduledTime)
31+
public function addScheduledJob(ConsoleCommandJob $job, $scheduledTime)
3332
{
3433
$scheduledJob = new ScheduledJob($job->getCommand(), $scheduledTime, $job->getTopic());
3534
$this->save($scheduledJob, true);
@@ -57,11 +56,11 @@ public function getUnqueuedJobs()
5756
return $this->getScheduledJobRepository()->fetchUnqueuedJobs();
5857
}
5958

60-
/**
61-
* @return ObjectRepository|ScheduledJobRepository
62-
*/
63-
private function getScheduledJobRepository()
59+
private function getScheduledJobRepository(): ScheduledJobRepositoryInterface
6460
{
65-
return $this->managerRegistry->getRepository(ScheduledJob::class);
61+
/** @var ScheduledJobRepositoryInterface $repository */
62+
$repository = $this->managerRegistry->getRepository(ScheduledJob::class);
63+
64+
return $repository;
6665
}
6766
}

Service/SupervisordConfigFileWriter.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ class SupervisordConfigFileWriter
4747
*/
4848
private $mode;
4949

50-
/**
51-
* SupervisordConfigFileWriter constructor.
52-
*
53-
* @param $kernelPath
54-
* @param $logsDir
55-
* @param $kernelEnv
56-
* @param $supervisordConfigPath
57-
* @param $consumerPath
58-
* @param $configFilePath
59-
*/
6050
public function __construct(
6151
$kernelPath,
6252
$logsDir,
@@ -118,7 +108,7 @@ public function writeConfig($uniqueEnvironment)
118108
}
119109

120110
/**
121-
* @param $uniqueEnvironment string environment disambiguator
111+
* @param string $uniqueEnvironment environment disambiguator
122112
* @param bool $skipExistsChecks If set skips FS checks for binary and config file
123113
* @return string
124114
*/
@@ -179,7 +169,7 @@ public function getConfigForCliConsumer($uniqueEnvironment, $skipExistsChecks =
179169
}
180170

181171
/**
182-
* @param $uniqueEnvironment
172+
* @param string $uniqueEnvironment
183173
* @return string
184174
*/
185175
public function getConfigForPhpConsumer($uniqueEnvironment, $skipExistsChecks = false)

Tests/Service/JobManagerTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Markup\Bundle\JobQueueBundle\Tests\Service;
44

55
use Doctrine\Common\Persistence\ManagerRegistry;
6+
use Markup\JobQueueBundle\Entity\ScheduledJob;
7+
use Markup\JobQueueBundle\Job\ConsoleCommandJob;
68
use Markup\JobQueueBundle\Job\SleepJob;
79
use Markup\JobQueueBundle\Model\Job;
810
use Markup\JobQueueBundle\Publisher\JobPublisher;
@@ -40,23 +42,28 @@ protected function setUp()
4042
);
4143
}
4244

43-
public function testCanAddJob()
45+
public function testCanAddJobWithoutDateTime(): void
4446
{
4547
$job = new SleepJob();
46-
$scheduledTime = new \DateTime();
4748
$this->jobManager->addJob($job);
48-
$this->jobManager->addJob($job, $scheduledTime);
4949
$this->assertSame([$job], $this->jobPublisher->getJobs());
50+
}
51+
52+
public function testCanAddConsoleCommandJobWithDateTime(): void
53+
{
54+
$job = new ConsoleCommandJob();
55+
$scheduledTime = new \DateTime();
56+
$this->jobManager->addJob($job, $scheduledTime);
5057
$this->assertSame([$job], $this->scheduledJobService->getJobs());
5158
}
5259

53-
public function testCanAddCommandJob()
60+
public function testCanAddCommandJob(): void
5461
{
5562
$this->jobManager->addCommandJob('console:herp:derp', 'system', 60, 60);
5663
$this->assertCount(1, $this->jobPublisher->getJobs());
5764
}
5865

59-
public function testIdleTimeoutDefaultsToTimeout()
66+
public function testIdleTimeoutDefaultsToTimeout(): void
6067
{
6168
$timeout = 720;
6269
$this->jobManager->addCommandJob('command', 'topic', $timeout);
@@ -94,7 +101,7 @@ public function __construct()
94101
$this->initializeJobs();
95102
}
96103

97-
public function addScheduledJob(Job $job, $scheduledTime)
104+
public function addScheduledJob(ConsoleCommandJob $job, $scheduledTime)
98105
{
99106
$this->addJob($job);
100107
}

0 commit comments

Comments
 (0)