Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CaptchaRequirementTrait
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
8
100.00% covered (success)
100.00%
1 / 1
 isCaptchaRequiredForOfficeIds
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
5
 isCaptchaRequiredForOfficeId
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace BO\Zmscitizenapi\Services\Captcha;
6
7/**
8 * Requires the using class to define: private ZmsApiFacadeService $zmsApiFacadeService
9 */
10trait CaptchaRequirementTrait
11{
12    private function isCaptchaRequiredForOfficeIds(array $officeIds): bool
13    {
14        foreach ($officeIds as $officeIdRaw) {
15            $officeId = (int) $officeIdRaw;
16            if ($officeId <= 0) {
17                continue;
18            }
19
20            try {
21                $scope = $this->zmsApiFacadeService->getScopeByOfficeId($officeId);
22                if (($scope->captchaActivatedRequired ?? false) === true) {
23                    return true;
24                }
25            } catch (\Throwable $e) {
26                continue;
27            }
28        }
29
30        return false;
31    }
32
33    private function isCaptchaRequiredForOfficeId(?int $officeId): bool
34    {
35        if ($officeId === null || $officeId <= 0) {
36            return false;
37        }
38
39        return $this->isCaptchaRequiredForOfficeIds([(string) $officeId]);
40    }
41}