Completed
Push — master ( 922505...49fe4c )
by Boudry
05:20
created

Method   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
getStats() 0 1 ?
A createResult() 0 10 1
A __construct() 0 8 3
1
<?php
2
/*
3
    Condorcet PHP Class, with Schulze Methods and others !
4
5
    By Julien Boudry - MIT LICENSE (Please read LICENSE.txt)
6
    https://github.com/julien-boudry/Condorcet
7
*/
8
declare(strict_types=1);
9
10
namespace Condorcet\Algo;
11
12
use Condorcet\CondorcetException;
13
use Condorcet\CondorcetVersion;
14
use Condorcet\Election;
15
use Condorcet\Result;
16
17
// Generic for Algorithms
18
abstract class Method
19
{
20
    use CondorcetVersion;
21
22
    public static $_maxCandidates = null;
23
24
    protected $_selfElection;
25
    protected $_Result;
26
27 67
    public function __construct (Election $mother)
28
    {
29 67
        $this->_selfElection = $mother;
30
31 67
        if (!is_null(static::$_maxCandidates) && $this->_selfElection->countCandidates() > static::$_maxCandidates) :
32 2
            throw new CondorcetException(101, static::METHOD_NAME[0].' is configured to accept only '.static::$_maxCandidates.' candidates');
33
        endif;
34 65
    }
35
36
    abstract protected function getStats () : array;
37
38 58
    protected function createResult (array $result) : Result
39
    {
40 58
    	return new Result (
41 58
            static::METHOD_NAME[0],
42 58
            get_class($this),
43 58
    		$this->_selfElection,
44 58
    		$result,
45 58
            $this->getStats()
46
    	);
47
    }
48
}
49