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
Pull Request — master (#158)
by Bernardo Vieira da
12:24
created

AbstractGearmanService::getWorkers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * Gearman Bundle for Symfony2
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * Feel free to edit as you please, and have fun.
10
 *
11
 * @author Marc Morera <[email protected]>
12
 */
13
14
namespace Mmoreram\GearmanBundle\Service\Abstracts;
15
16
use Mmoreram\GearmanBundle\Exceptions\JobDoesNotExistException;
17
use Mmoreram\GearmanBundle\Exceptions\WorkerDoesNotExistException;
18
use Mmoreram\GearmanBundle\Service\GearmanCacheWrapper;
19
20
/**
21
 * Gearman execute methods. All Worker methods
22
 *
23
 * @author Marc Morera <[email protected]>
24
 */
25
abstract class AbstractGearmanService
26
{
27
    /**
28
     * All workers
29
     *
30
     * @var array
31
     */
32
    protected $workers;
33
34
    /**
35
     * The prefix for all job names
36
     *
37
     * @var string $jobPrefix
38
     */
39
    protected $jobPrefix = null;
40
41
    /**
42
     * Construct method
43
     *
44
     * @param GearmanCacheWrapper $gearmanCacheWrapper GearmanCacheWrapper
45
     * @param array               $defaultSettings     The default settings for the bundle
46
     */
47 3
    public function __construct(GearmanCacheWrapper $gearmanCacheWrapper, array $defaultSettings)
48
    {
49 3
        $this->workers = $gearmanCacheWrapper->getWorkers();
50
51 3
        if (isset($defaultSettings['job_prefix'])) {
52
53
            $this->jobPrefix = $defaultSettings['job_prefix'];
54
        }
55 3
    }
56
57
    /**
58
     * Return worker containing a job with $jobName as name
59
     * If is not found, throws JobDoesNotExistException Exception
60
     *
61
     * @param string $jobName Name of job
62
     *
63
     * @return array
64
     *
65
     * @throws JobDoesNotExistException
66
     */
67 1
    public function getJob($jobName)
68
    {
69 1
        $jobName = $this->jobPrefix . $jobName;
70
71 1
        foreach ($this->workers as $worker) {
72
73 1
            if (is_array($worker['jobs'])) {
74
75 1
                foreach ($worker['jobs'] as $job) {
76
77 1
                    if ($jobName === $job['realCallableName']) {
78
79 1
                        $worker['job'] = $job;
80
81 1
                        return $worker;
82
                    }
83
                }
84
            }
85
        }
86
87
        throw new JobDoesNotExistException();
88
    }
89
90
    /**
91
     * Return worker with $workerName as name and all its jobs
92
     * If is not found, throws WorkerDoesNotExistException Exception
93
     *
94
     * @param string $workerName Name of worker
95
     *
96
     * @return array
97
     *
98
     * @throws WorkerDoesNotExistException
99
     */
100
    public function getWorker($workerName)
101
    {
102
        foreach ($this->workers as $worker) {
103
104
            if ($workerName === $worker['callableName']) {
105
                return $worker;
106
            }
107
        }
108
109
        throw new WorkerDoesNotExistException();
110
    }
111
112
    /**
113
     * Return array of workers
114
     *
115
     * @return array all available workers
116
     */
117
    public function getWorkers()
118
    {
119
        return $this->workers;
120
    }
121
}
122