Test Failed
Pull Request — master (#10)
by
unknown
05:38
created

Search::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace PeeHaa\AsyncTwitter\Api\Request\Search;
4
5
use PeeHaa\AsyncTwitter\Api\Request\BaseRequest;
6
7
/**
8
 * @link https://dev.twitter.com/rest/reference/get/search/tweets
9
 */
10
class Search extends BaseRequest
11
{
12
    const METHOD = 'GET';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
13
    const ENDPOINT = '/search/tweets.json';
14
15
    private $resultTypes = ['mixed', 'recent', 'popular'];
16
17
    public function __construct(string $searchString)
18
    {
19
        parent::__construct(self::METHOD, self::ENDPOINT);
20
21
        $this->parameters['q'] = $searchString;
22
    }
23
24
    //use string instead of float
25
    public function setGeocode(string $latitude, string $longitude, string $radius): Search
26
    {
27
        $this->parameters['geocode'] = sprintf("%s %s %s", $latitude, $longitude, $radius);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal %s %s %s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
28
29
        return $this;
30
    }
31
32
    public function setLanguage(string $language = 'en'): Search
33
    {
34
        $this->parameters['lang'] = $language;
35
36
        return $this;
37
    }
38
39
    public function setlocale(): Search
40
    {
41
        $this->parameters['locale'] = 'ja';
42
43
        return $this;
44
    }
45
46
    public function setResultType(string $resultType): Search
47
    {
48
        if (in_array($resultType, $this->resultTypes)) {
49
            $this->parameters['result_type'] = $resultType;
50
        }
51
52
        return $this;
53
    }
54
55
    public function amount(int $amount): Search
56
    {
57
        $this->parameters['count'] = (string) $amount;
58
59
        return $this;
60
    }
61
62
    public function until(\DateTime $until): Search
63
    {
64
        $this->parameters['until'] = $until->format('Y-m-d');
65
66
        return $this;
67
    }
68
69
    public function minimumId(int $id): Search
70
    {
71
        $this->parameters['since_id'] = (string) $id;
72
73
        return $this;
74
    }
75
76
    public function maximumId(int $id): Search
77
    {
78
        $this->parameters['max_id'] = (string) $id;
79
80
        return $this;
81
    }
82
83
    public function excludeEntities(): Search
84
    {
85
        $this->parameters['include_entities'] = 'false';
86
87
        return $this;
88
    }
89
}