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 NodeCollection |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Collection of \Algolia\ScoutExtended\Splitters\HtmlSplitter\Node. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private $nodes = []; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \Algolia\ScoutExtended\Splitters\HtmlSplitter\NodesCollection. |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
private $nodesCollection; |
32
|
|
|
/** |
33
|
|
|
* The list of html tags. |
34
|
|
|
* |
35
|
|
|
* @var string[] |
36
|
|
|
*/ |
37
|
|
|
private $tags = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* String. |
41
|
|
|
*/ |
42
|
|
|
private const PARAGRAPH = 'p'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* NodeCollection constructor. |
46
|
|
|
* |
47
|
|
|
* @param array|null $tags |
48
|
|
|
* @param \Algolia\ScoutExtended\Splitters\HtmlSplitter\NodesCollection $nodesCollection |
49
|
|
|
*/ |
50
|
8 |
|
public function __construct(array $tags = null, NodesCollection $nodesCollection) |
51
|
|
|
{ |
52
|
8 |
|
if ($tags !== null) { |
53
|
8 |
|
$this->tags = $tags; |
54
|
|
|
} |
55
|
8 |
|
$this->nodesCollection = $nodesCollection; |
|
|
|
|
56
|
8 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
8 |
|
public function getNodes(): array |
62
|
|
|
{ |
63
|
8 |
|
return $this->nodes; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Add object to collection. |
68
|
|
|
* |
69
|
|
|
* @param \Algolia\ScoutExtended\Splitters\HtmlSplitter\Node $node |
70
|
|
|
*/ |
71
|
8 |
|
public function push(Node $node): void |
72
|
|
|
{ |
73
|
8 |
|
if ($this->lengthNodes() === 0 || $this->findWeight($node) > $this->findWeight($this->last(0))) { |
74
|
8 |
|
$this->nodes[] = $node; |
75
|
8 |
|
$this->nodesCollection->push($this); |
76
|
|
|
} else { |
77
|
4 |
|
array_pop($this->nodes); |
78
|
4 |
|
$this->push($node); |
79
|
|
|
} |
80
|
8 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Return the last element of the collection |
84
|
|
|
* Give integer as pointer from the end. |
85
|
|
|
* |
86
|
|
|
* @param int $position |
87
|
|
|
* |
88
|
|
|
* @return \Algolia\ScoutExtended\Splitters\HtmlSplitter\Node |
89
|
|
|
*/ |
90
|
8 |
|
public function last(int $position): Node |
91
|
|
|
{ |
92
|
8 |
|
return $this->nodes[$this->lengthNodes() - $position - 1]; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Importance formula. |
97
|
|
|
* Give integer from tags ranking. |
98
|
|
|
* |
99
|
|
|
* @param \Algolia\ScoutExtended\Splitters\HtmlSplitter\Node $node |
100
|
|
|
* |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
8 |
|
public function importanceWeight(Node $node): int |
104
|
|
|
{ |
105
|
8 |
|
if ($node->getTag() === self::PARAGRAPH) { |
106
|
4 |
|
if ($this->last(0) === null || $this->lengthNodes() === 1) { |
107
|
1 |
|
return 0; |
108
|
|
|
} |
109
|
3 |
|
$object = $this->last(1); |
110
|
|
|
|
111
|
3 |
|
return (count($this->tags) - 1) + $this->findWeight($object); |
112
|
|
|
} |
113
|
|
|
|
114
|
7 |
|
return $this->findWeight($node); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Find weight of current nodes. |
119
|
|
|
* |
120
|
|
|
* @param \Algolia\ScoutExtended\Splitters\HtmlSplitter\Node $node |
121
|
|
|
* |
122
|
|
|
* @return int |
123
|
|
|
*/ |
124
|
7 |
|
private function findWeight(Node $node): int |
125
|
|
|
{ |
126
|
7 |
|
return (int) array_search($node->getTag(), $this->tags, true); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Give the length of the collection. |
131
|
|
|
* |
132
|
|
|
* @return int |
133
|
|
|
*/ |
134
|
8 |
|
private function lengthNodes(): int |
135
|
|
|
{ |
136
|
8 |
|
return count($this->nodes); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths