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

Method   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 28
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createResult() 0 8 1
A __construct() 0 6 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 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