SearchTerm::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace CViniciusSDias\GoogleCrawler;
3
4
/**
5
 * Class that represents a search term and makes sure that no spaces are used
6
 *
7
 * @package CViniciusSDias\GoogleCrawler
8
 * @author Vinicius Dias
9
 */
10
class SearchTerm implements SearchTermInterface
11
{
12
    /** @var string $searchTerm */
13
    protected $searchTerm;
14
15
    /**
16
     * Initializes the search term
17
     *
18
     * @param string $searchTerm
19
     */
20 8
    public function __construct(string $searchTerm)
21
    {
22 8
        $searchTerm = $this->normalize($searchTerm);
23 8
        $this->searchTerm = $searchTerm;
24 8
    }
25
26
    /**
27
     * Returns the normalized search term
28
     *
29
     * @return string
30
     */
31 6
    public function __toString(): string
32
    {
33 6
        return $this->searchTerm;
34
    }
35
36
    /**
37
     * Normalizes the search term removing its spaces
38
     *
39
     * @param string $searchTerm
40
     * @return string
41
     */
42 8
    protected function normalize(string $searchTerm): string
43
    {
44 8
        return rawurlencode($searchTerm);
45
    }
46
}
47