Greedy::getResult()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace drupol\phpartition\Algorithm;
4
5
use drupol\phpartition\BasePartitionAlgorithm;
6
use drupol\phpartition\Partition;
7
use drupol\phpartition\PartitionAlgorithmInterface;
8
9
/**
10
 * Class Greedy.
11
 *
12
 * @package drupol\phpartition\Algorithm
13
 */
14
class Greedy extends BasePartitionAlgorithm implements PartitionAlgorithmInterface
15
{
16
17
  /**
18
   * {@inheritdoc}
19
   */
20 3
    public function getResult()
21
    {
22
        // The greedy algorithm needs the input data to be sorted (desc).
23 3
        $this->getDataPartition()->sortByValue('DESC');
24 3
        return parent::getResult();
25
    }
26
27
  /**
28
   * {@inheritdoc}
29
   */
30 3
    public function getPartitionWeight(Partition $partition)
31
    {
32 3
        return $partition->getWeight();
33
    }
34
}
35