| Total Complexity | 6 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Coverage | 52.63% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | class Numerical extends AGraphical |
||
| 16 | { |
||
| 17 | 2 | public function set(string $alias, ArrayAccess &$session, string $errorMessage, string $font = '/usr/share/fonts/truetype/freefont/FreeMono.ttf'): AGraphical |
|
| 18 | { |
||
| 19 | 2 | $this->font = $font; |
|
| 20 | |||
| 21 | 2 | $num1 = mt_rand(0, 9); |
|
| 22 | 2 | $num2 = mt_rand(0, 9); |
|
| 23 | 2 | $text = ' ' . $num1 . ' + ' . $num2 . ' ='; |
|
| 24 | |||
| 25 | 2 | $this->setEntry($alias, null, $text); |
|
| 26 | 2 | $this->fillSession($alias, $session, strval($num1 + $num2)); |
|
| 27 | 2 | $this->setAttribute('id', $this->getKey()); |
|
| 28 | 2 | parent::addRule(IRules::SATISFIES_CALLBACK, $errorMessage, [$this, 'checkFillCaptcha']); |
|
| 29 | 2 | return $this; |
|
| 30 | } |
||
| 31 | |||
| 32 | public function addRule(/** @scrutinizer ignore-unused */ string $ruleName, /** @scrutinizer ignore-unused */ string $errorText, /** @scrutinizer ignore-unused */ ...$args): void |
||
| 33 | { |
||
| 34 | // no additional rules applicable |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param mixed $value |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | public function checkFillCaptcha($value): bool |
||
| 42 | { |
||
| 43 | $formName = $this->getKey() . '_last'; |
||
| 44 | return $this->getSession()->offsetExists($formName) && (intval($this->getSession()->offsetGet($formName)) == intval($value)); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function renderLabel($attributes = null): string |
||
| 48 | { |
||
| 49 | return ''; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function renderInput($attributes = null): string |
||
| 55 | } |
||
| 56 | } |
||
| 57 |