Total Complexity | 9 |
Total Lines | 126 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
26 | trait ComplexAlgorithmicCostTrait |
||
27 | { |
||
28 | /** |
||
29 | * Setter for the memory cost property. |
||
30 | * |
||
31 | * @param int $cost The algorithmic memory cost. |
||
32 | * |
||
33 | * @return $this The hash algorithm object. |
||
34 | * @throws \Exception Validation errors. |
||
35 | */ |
||
36 | public function setMemoryCost($cost) |
||
37 | { |
||
38 | $cost = filter_var( |
||
39 | $cost, |
||
40 | FILTER_VALIDATE_INT, |
||
41 | [ |
||
42 | "options" => [ |
||
43 | "min_range" => static::MINIMUM_MEMORY_COST, |
||
1 ignored issue
–
show
|
|||
44 | "max_range" => static::MAXIMUM_MEMORY_COST, |
||
1 ignored issue
–
show
|
|||
45 | ], |
||
46 | ] |
||
47 | ); |
||
48 | |||
49 | if ($cost === false) { |
||
50 | throw new \InvalidArgumentException( |
||
51 | 'The number of internal iterations must be a valid integer bigger than 0.' |
||
52 | ); |
||
53 | } |
||
54 | |||
55 | $this->memoryCost = $cost; |
||
56 | |||
57 | return $this; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Getter for the memory cost property. |
||
62 | * |
||
63 | * @return int The algorithmic memory cost. |
||
64 | */ |
||
65 | public function getMemoryCost() |
||
66 | { |
||
67 | return $this->memoryCost; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Setter for the time cost property. |
||
72 | * |
||
73 | * @param int $cost The algorithmic time cost. |
||
74 | * |
||
75 | * @return $this The hash algorithm object. |
||
76 | * @throws \Exception Validation errors. |
||
77 | */ |
||
78 | public function setTimeCost($cost) |
||
79 | { |
||
80 | $cost = filter_var( |
||
81 | $cost, |
||
82 | FILTER_VALIDATE_INT, |
||
83 | [ |
||
84 | "options" => [ |
||
85 | "min_range" => static::MINIMUM_TIME_COST, |
||
1 ignored issue
–
show
|
|||
86 | "max_range" => static::MAXIMUM_TIME_COST, |
||
1 ignored issue
–
show
|
|||
87 | ], |
||
88 | ] |
||
89 | ); |
||
90 | |||
91 | if ($cost === false) { |
||
92 | throw new \InvalidArgumentException( |
||
93 | 'The number of internal iterations must be a valid integer bigger than 0.' |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | $this->timeCost = $cost; |
||
98 | |||
99 | return $this; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Getter for the time cost property. |
||
104 | * |
||
105 | * @return int The algorithmic time cost. |
||
106 | */ |
||
107 | public function getTimeCost() |
||
108 | { |
||
109 | return $this->timeCost; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Setter for the threads cost property. |
||
114 | * |
||
115 | * @param int $cost The algorithmic threads cost. |
||
116 | * |
||
117 | * @return $this The hash algorithm object. |
||
118 | * @throws \Exception Validation errors. |
||
119 | */ |
||
120 | public function setThreadsCost($cost) |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Getter for the threads cost property. |
||
146 | * |
||
147 | * @return int The algorithmic threads cost. |
||
148 | */ |
||
149 | public function getThreadsCost() |
||
152 | } |
||
153 | } |
||
154 |