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

Method::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 1
crap 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