Completed
Pull Request — master (#102)
by De Cramer
03:26
created

Factory::createCurlJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 4
crap 1
1
<?php
2
3
namespace eXpansion\Framework\Core\Helpers\JobRunner;
4
5
use oliverde8\AsynchronousJobs\Job;
6
use oliverde8\AsynchronousJobs\Job\CallbackCurl;
7
use oliverde8\AsynchronousJobs\JobRunner;
8
9
10
/**
11
 * Class Factory
12
 *
13
 * @author    de Cramer Oliver<[email protected]>
14
 * @copyright 2017 Smile
15
 * @package Tests\eXpansion\Framework\Core\Helpers\JobRunner
16
 */
17
class Factory
18
{
19
    /**
20
     * @return JobRunner
21
     */
22 2
    public function getJobRunner()
23
    {
24 2
        return JobRunner::getInstance('expansion', 'php', 'var/tmp/asnychronous');
25
    }
26
27
    /**
28
     * @param $url
29
     * @param $callback
30
     * @param null $additionalData
31
     * @param array $options
32
     *
33
     * @return CallbackCurl
34
     */
35 1
    public function createCurlJob($url, $callback, $additionalData = null, $options = [])
36
    {
37 1
        $curlJob = new CallbackCurl();
38 1
        $curlJob->setCallback($callback);
39 1
        $curlJob->setUrl($url);
40 1
        $curlJob->setOptions($options);
41 1
        $curlJob->__additionalData = $additionalData;
0 ignored issues
show
Bug introduced by
The property __additionalData does not seem to exist in oliverde8\AsynchronousJobs\Job\CallbackCurl.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
42
43 1
        return $curlJob;
44
    }
45
46
    /**
47
     * @param Job $job
48
     */
49 1
    public function startJob(Job $job)
50
    {
51 1
        $job->start();
52 1
    }
53
54
55
    /**
56
     * On each loop check for finished jobs.
57
     */
58 1
    public function onExpansionPostLoop()
59
    {
60 1
        $this->getJobRunner()->proccess();
61 1
    }
62
}
63