Analyze::setMode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Swader\Diffbot\Api;
4
5
use Swader\Diffbot\Abstracts\Api;
6
use Swader\Diffbot\Traits\StandardApi;
7
8
class Analyze extends Api
9
{
10
    use StandardApi;
11
12
    /** @var string API URL to which to send the request */
13
    protected $apiUrl = 'https://api.diffbot.com/v3/analyze';
14
15
    /**
16
     * If set to false, will not extract article comments in a Discussion
17
     * entity embedded in the Article / Product entity. By default, it will.
18
     * @param bool $bool
19
     * @return $this
20
     */
21 2
    public function setDiscussion($bool = true)
22
    {
23 2
        $this->otherOptions['discussion'] = ($bool) ? 'true' : 'false';
24
25 2
        return $this;
26
    }
27
28
    /**
29
     * By default the Analyze API will fully extract all pages that match an
30
     * existing Automatic API -- articles, products or image pages. Set mode
31
     * to a specific page-type (e.g., mode=article) to extract content only
32
     * from that specific page-type. All other pages will simply return the
33
     * default Analyze fields.
34
     *
35
     * @param string $mode article, product or image
36
     * @return $this
37
     */
38 52
    public function setMode($mode)
39
    {
40 52
        if (!in_array($mode, ['article', 'product', 'image', 'auto'])) {
41 4
            $error = 'Only "article", "product" and "image" modes supported.';
42 4
            throw new \InvalidArgumentException($error);
43
        }
44 48
        $this->otherOptions['mode'] = $mode;
45
46 48
        return $this;
47
    }
48
49
}
50