Completed
Pull Request — master (#104)
by
unknown
03:28
created

Factory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 55
ccs 16
cts 20
cp 0.8
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getJobRunner() 0 4 1
A createCurlJob() 0 11 1
A startJob() 0 4 1
A onPreLoop() 0 4 1
A onPostLoop() 0 4 1
A onEverySecond() 0 4 1
1
<?php
2
3
namespace eXpansion\Framework\Core\Helpers\JobRunner;
4
5
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpApplication;
6
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpTimer;
7
use eXpansion\Framework\Core\Helpers\Structures\HttpRequest;
8
use eXpansion\Framework\Core\Helpers\Structures\HttpResult;
9
use oliverde8\AsynchronousJobs\Job;
10
use oliverde8\AsynchronousJobs\Job\CallbackCurl;
11
use oliverde8\AsynchronousJobs\JobRunner;
12
13
14
/**
15
 * Class Factory
16
 *
17
 * @author    de Cramer Oliver<[email protected]>
18
 * @copyright 2017 Smile
19
 * @package Tests\eXpansion\Framework\Core\Helpers\JobRunner
20
 */
21
class Factory implements ListenerInterfaceExpTimer
22
{
23
    /**
24
     * @return JobRunner
25
     */
26 2
    public function getJobRunner()
27
    {
28 2
        return JobRunner::getInstance('expansion', PHP_BINARY, 'var/tmp/asynchronous');
29
    }
30
31
    /**
32
     * @param $url
33
     * @param $callback
34
     * @param null|mixed $additionalData
35
     * @param array $options
36
     *
37
     * @param array|\stdClass $parameters one dimensional array or \stdClass with post key-value pairs
38
     * @return CallbackCurl
39
     */
40 1
    public function createCurlJob($url, $callback, $additionalData = null, $options = [], $parameters = [])
41
    {
42 1
        $curlJob = new HttpRequest();
43 1
        $curlJob->setCallback($callback);
44 1
        $curlJob->setUrl($url);
45 1
        $curlJob->setOptions($options);
46 1
        $curlJob->setParameters($parameters);
0 ignored issues
show
Bug introduced by
It seems like $parameters defined by parameter $parameters on line 40 can also be of type object<stdClass>; however, oliverde8\AsynchronousJo...b\Curl::setParameters() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
47 1
        $curlJob->setAdditionalData($additionalData);
48
49 1
        return $curlJob;
50
    }
51
52
    /**
53
     * @param Job $job
54
     */
55 1
    public function startJob(Job $job)
56
    {
57 1
        $job->start();
58 1
    }
59
60
61
    public function onPreLoop()
62
    {
63
64
    }
65
66 1
    public function onPostLoop()
67
    {
68 1
        $this->getJobRunner()->proccess();
69 1
    }
70
71
    public function onEverySecond()
72
    {
73
74
    }
75
}
76