| Total Complexity | 3 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | trait AlgorithmicCostTrait |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Setter for the computational cost property. |
||
| 26 | * |
||
| 27 | * @param int $cost The algorithmic cost. |
||
| 28 | * |
||
| 29 | * @return $this The hash algorithm object. |
||
| 30 | * @throws \Exception Validation errors. |
||
| 31 | */ |
||
| 32 | 17 | public function setAlgorithmicCost($cost) |
|
| 33 | { |
||
| 34 | 17 | $cost = filter_var( |
|
| 35 | 17 | $cost, |
|
| 36 | 17 | FILTER_VALIDATE_INT, |
|
| 37 | 17 | [ |
|
| 38 | 17 | "options" => [ |
|
| 39 | 17 | "min_range" => static::MINIMUM_ALGORITHMIC_COST, |
|
| 40 | 17 | "max_range" => static::MAXIMUM_ALGORITHMIC_COST, |
|
| 41 | 17 | ], |
|
| 42 | 17 | ] |
|
| 43 | 17 | ); |
|
| 44 | |||
| 45 | 17 | if ($cost === false) { |
|
| 46 | 1 | throw new \InvalidArgumentException( |
|
| 47 | 1 | 'The number of internal iterations must be a valid integer bigger than 0.' |
|
| 48 | 1 | ); |
|
| 49 | } |
||
| 50 | |||
| 51 | 17 | $this->computationalCost = $cost; |
|
| 52 | |||
| 53 | 17 | return $this; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Getter for the computational cost property. |
||
| 58 | * |
||
| 59 | * @return int The algorithmic cost. |
||
| 60 | */ |
||
| 61 | 1 | public function getAlgorithmicCost() |
|
| 64 | } |
||
| 65 | } |
||
| 66 |