NodeGravityTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
eloc 6
c 4
b 0
f 1
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getScore() 0 2 1
A updateNodeCount() 0 4 1
A updateScore() 0 4 1
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