Completed
Pull Request — feat/html-splitter (#182)
by Nuno
14:37 queued 10:11
created

Node::getTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Scout Extended.
7
 *
8
 * (c) Algolia Team <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Algolia\ScoutExtended\Splitters\HtmlSplitter;
15
16
/**
17
 * @internal
18
 */
19
final class Node
20
{
21
    /**
22
     * Contains node name.
23
     *
24
     * @var string tag
25
     */
26
    private $tag;
27
28
    /**
29
     * Contains content of node.
30
     *
31
     * @var string
32
     */
33
    private $content;
34
35
    /**
36
     * Create a new instance of Node.
37
     *
38
     * @param string $tag
39
     * @param string $content
40
     */
41 5
    public function __construct(string $tag, string $content)
42
    {
43 5
        $this->tag = $tag;
44 5
        $this->content = $this->cleanContent($content);
45 5
    }
46
47
    /**
48
     * @return string
49
     */
50 5
    public function getTag(): string
51
    {
52 5
        return $this->tag;
53
    }
54
55
    /**
56
     * @return string
57
     */
58 5
    public function getContent(): string
59
    {
60 5
        return $this->content;
61
    }
62
63
    /**
64
     * Cleans the given content removing spaces.
65
     *
66
     * @param string $content
67
     *
68
     * @return string
69
     */
70 5
    private function cleanContent(string $content): string
71
    {
72 5
        return trim(preg_replace('/\s+/', ' ', str_replace('\n', '', $content)));
73
    }
74
}
75