NodeGravityTrait::updateScore()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 2
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Goose\Traits;
4
5
use DOMWrap\Element;
6
7
/**
8
 * Node Gravity Trait
9
 *
10
 * @package Goose\Traits
11
 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
12
 */
13
trait NodeGravityTrait {
14
    /**
15
     * Returns the gravityScore from this node
16
     *
17
     * @param Element $node
18
     *
19
     * @return float
20
     */
21
    private function getScore(Element $node): float {
22
        return (float)$node->attr('gravityScore');
23
    }
24
25
    /**
26
     * Adds a score to the gravityScore Attribute we put on divs
27
     * we'll get the current score then add the score we're passing in to the current
28
     *
29
     * @param Element $node
30
     * @param float $addToScore
31
     */
32
    private function updateScore(Element $node, float $addToScore): void {
33
        $currentScore = (float)$node->attr('gravityScore');
34
35
        $node->attr('gravityScore', (string)($currentScore + $addToScore));
36
    }
37
38
    /**
39
     * Stores how many decent nodes are under a parent node
40
     *
41
     * @param Element $node
42
     * @param int $addToCount
43
     */
44
    private function updateNodeCount(Element $node, int $addToCount): void {
45
        $currentScore = (int)$node->attr('gravityNodes');
46
47
        $node->attr('gravityNodes', (string)($currentScore + $addToCount));
48
    }
49
}
50