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

Node   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 54
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A cleanContent() 0 3 1
A getTag() 0 3 1
A getContent() 0 3 1
A __construct() 0 4 1
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