Passed
Branch dev-1.5.x (fb93e4)
by Boudry
04:14
created

Method::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 1
crap 3.1406
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 4
    public function __construct (Election $mother)
28
    {
29 4
        $this->_selfElection = $mother;
30
31 4
        if (!is_null(static::$_maxCandidates) && $this->_selfElection->countCandidates() > static::$_maxCandidates) :
32
            throw new CondorcetException(101, static::METHOD_NAME[0].' is configured to accept only '.static::$_maxCandidates.' candidates');
1 ignored issue
show
Bug introduced by
The constant Condorcet\Algo\Method::METHOD_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
33
        endif;
34 4
    }
35
36
    abstract protected function getStats () : array;
37
38 4
    protected function createResult (array $result) : Result
39
    {
40 4
    	return new Result (
41 4
            static::METHOD_NAME[0],
1 ignored issue
show
Bug introduced by
The constant Condorcet\Algo\Method::METHOD_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
42 4
            get_class($this),
43 4
    		$this->_selfElection,
44 4
    		$result,
45 4
            $this->getStats()
46
    	);
47
    }
48
}
49