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.
Completed
Push — master ( ccb5b0...806400 )
by Alex
02:59
created

Entity/Repository/ScheduledJobRepository.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 JMS\JobQueueBundle\Entity\Job;
18
19
/**
20
 * ScheduledJobRepository
21
 */
22
class ScheduledJobRepository extends EntityRepository
23
{
24
    /**
25
     * Finds ScheduledJob by original Job can be scheduled earlier
26
     *
27
     * @param $originalJob $originalJob original job
0 ignored issues
show
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...
28
     *
29
     * @return ScheduledJob|null
30
     */
31
    public function findScheduledJobToReschedule(Job $originalJob)
32
    {
33
        // fetching scheduled job that was not started before - it can be rescheduled
34
        $queryString = <<<'QUERY'
35
            SELECT sj FROM WorkflowExtensionsBundle:ScheduledJob sj
36
            JOIN sj.job j
37
            WHERE
38
                j.state in (:stateNew, :statePending) AND
39
                j.command = :command AND
40
                j.args = :args AND
41
                sj.reschedulable = 1
42
QUERY;
43
44
        /** @var ScheduledJob[] $scheduledJobsToReschedule */
45
        $scheduledJobsToReschedule = $this->_em
46
            ->createQuery($queryString)
47
            ->setParameters([
48
                'stateNew'     => Job::STATE_NEW,
49
                'statePending' => Job::STATE_PENDING,
50
                'command'      => $originalJob->getCommand(),
51
                'args'         => json_encode($originalJob->getArgs())
52
            ])
53
            ->getResult()
54
        ;
55
56
        if (!$scheduledJobsToReschedule) {
57
            return null;
58
        }
59
60
        if (count($scheduledJobsToReschedule) > 1) {
61
            // since there is normally only one scheduled pending/new job here
62
            // (because an attempt to schedule duplicate job raises rescheduling of the first one)
63
            // we throwing exception in case of several results here
64
            // TODO probably we need support several jobs for the same transition, workflow and subject scheduled for different times?
65
            $duplicateReschedulableJobsIds = [];
66
            foreach ($scheduledJobsToReschedule as $scheduledJobToReschedule) {
67
                $duplicateReschedulableJobsIds[] = $scheduledJobToReschedule->getJob()->getId();
68
            }
69
70
            throw new NonUniqueReschedulabeJobFoundException($originalJob, $duplicateReschedulableJobsIds);
71
        }
72
73
        return reset($scheduledJobsToReschedule);
74
    }
75
}