GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

findScheduledJobToReschedule()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 44
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 20
nc 4
nop 1
1
<?php
2
/**
3
 * This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * (c) fduch <[email protected]>
9
 * @date 01.08.16
10
 */
11
12
namespace Gtt\Bundle\WorkflowExtensionsBundle\Entity\Repository;
13
14
use Doctrine\ORM\EntityRepository;
15
use Gtt\Bundle\WorkflowExtensionsBundle\Entity\ScheduledJob;
16
use Gtt\Bundle\WorkflowExtensionsBundle\Exception\NonUniqueReschedulabeJobFoundException;
17
use Gtt\Bundle\WorkflowExtensionsBundle\Schedule\Action\ScheduledAction;
18
use JMS\JobQueueBundle\Entity\Job;
19
20
/**
21
 * ScheduledJobRepository
22
 */
23
class ScheduledJobRepository extends EntityRepository
24
{
25
    /**
26
     * Finds ScheduledJob by original Job can be scheduled earlier
27
     *
28
     * @param $originalJob $originalJob original job
0 ignored issues
show
Documentation introduced by
The doc-type $originalJob could not be parsed: Unknown type name "$originalJob" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
29
     *
30
     * @return ScheduledJob|null
31
     */
32
    public function findScheduledJobToReschedule(Job $originalJob)
33
    {
34
        // fetching scheduled job that was not started before - it can be rescheduled
35
        $queryString = <<<'QUERY'
36
            SELECT sj FROM WorkflowExtensionsBundle:ScheduledJob sj
37
            JOIN sj.job j
38
            WHERE
39
                j.state in (:stateNew, :statePending) AND
40
                j.command = :command AND
41
                j.args = :args AND
42
                sj.reschedulable = 1
43
QUERY;
44
45
        /** @var ScheduledJob[] $scheduledJobsToReschedule */
46
        $scheduledJobsToReschedule = $this->_em
47
            ->createQuery($queryString)
48
            ->setParameters([
49
                'stateNew'     => Job::STATE_NEW,
50
                'statePending' => Job::STATE_PENDING,
51
                'command'      => $originalJob->getCommand(),
52
                'args'         => json_encode($originalJob->getArgs())
53
            ])
54
            ->getResult()
55
        ;
56
57
        if (!$scheduledJobsToReschedule) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $scheduledJobsToReschedule of type Gtt\Bundle\WorkflowExten...e\Entity\ScheduledJob[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
58
            return null;
59
        }
60
61
        if (count($scheduledJobsToReschedule) > 1) {
62
            // since there is normally only one scheduled pending/new job here
63
            // (because an attempt to schedule duplicate job raises rescheduling of the first one)
64
            // we throwing exception in case of several results here
65
            // TODO probably we need support several jobs for the same transition, workflow and subject scheduled for different times?
66
            $duplicateReschedulableJobsIds = [];
67
            foreach ($scheduledJobsToReschedule as $scheduledJobToReschedule) {
68
                $duplicateReschedulableJobsIds[] = $scheduledJobToReschedule->getJob()->getId();
69
            }
70
71
            throw new NonUniqueReschedulabeJobFoundException($originalJob, $duplicateReschedulableJobsIds);
72
        }
73
74
        return reset($scheduledJobsToReschedule);
75
    }
76
}