Completed
Push — master ( 0b9fa7...ac04d3 )
by Ryosuke
03:05
created

AutoScheduler::isEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
nc 1
cc 1
eloc 2
nop 0
1
<?php
2
3
namespace mpyw\Co\Internal;
4
use mpyw\Co\CURLException;
5
use mpyw\RuntimePromise\Deferred;
6
7
/**
8
 * Currently this class is not used
9
 * @codeCoverageIgnore
10
 */
11
class AutoScheduler extends AbstractScheduler
12
{
13
    /**
14
     * Constructor.
15
     * Initialize cURL multi handle.
16
     * @param CoOption $options
17
     * @param resource $mh      curl_multi
18
     */
19
    public function __construct(CoOption $options, $mh)
20
    {
21
        curl_multi_setopt($mh, CURLMOPT_MAX_TOTAL_CONNECTIONS, $options['concurrency']);
22
        $this->mh = $mh;
23
        $this->options = $options;
24
    }
25
26
    /**
27
     * Call curl_multi_add_handle().
28
     * @param resource $ch
29
     * @param Deferred $deferred
30
     */
31 View Code Duplication
    public function add($ch, Deferred $deferred = null)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $errno = curl_multi_add_handle($this->mh, $ch);
34
        if ($errno !== CURLM_OK) {
35
            // @codeCoverageIgnoreStart
36
            $msg = curl_multi_strerror($errno) . ": $ch";
37
            $deferred && $deferred->reject(new \RuntimeException($msg));
38
            return;
39
            // @codeCoverageIgnoreEnd
40
        }
41
        $this->added[(string)$ch] = $ch;
42
        $deferred && $this->deferreds[(string)$ch] = $deferred;
43
    }
44
45
    /**
46
     * Are there no cURL handles?
47
     * @return bool
48
     */
49
    public function isEmpty()
50
    {
51
        return !$this->added;
52
    }
53
54
    /**
55
     * Do nothing.
56
     * @param array $entry
57
     */
58
    protected function interruptConsume(array $entry) {}
59
}
60