Code Duplication    Length = 42-51 lines in 2 locations

src/Surfnet/StepupMiddlewareClientBundle/Identity/Service/AuditLogService.php 1 location

@@ 30-80 (lines=51) @@
27
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\AuditLog;
28
use Symfony\Component\Validator\Validator\ValidatorInterface;
29
30
class AuditLogService
31
{
32
    /**
33
     * @var LibraryAuditLogService
34
     */
35
    private $service;
36
37
    /**
38
     * @var ValidatorInterface
39
     */
40
    private $validator;
41
42
    /**
43
     * @param LibraryAuditLogService $service
44
     * @param ValidatorInterface $validator
45
     */
46
    public function __construct(LibraryAuditLogService $service, ValidatorInterface $validator)
47
    {
48
        $this->service = $service;
49
        $this->validator = $validator;
50
    }
51
52
    /**
53
     * @param SecondFactorAuditLogSearchQuery $query
54
     * @return AuditLog
55
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
56
     * @throws InvalidResponseException When the API responded with invalid data.
57
     * @throws ResourceReadException When the API doesn't respond with the resource.
58
     * @throws MalformedResponseException When the API doesn't respond with a proper response.
59
     */
60
    public function searchSecondFactorAuditLog(SecondFactorAuditLogSearchQuery $query)
61
    {
62
        $data = $this->service->searchSecondFactorAuditLog($query);
63
64
        if ($data === null) {
65
            return null;
66
        }
67
68
        $auditLog = AuditLog::fromData($data);
69
        $violations = $this->validator->validate($auditLog);
70
71
        if (count($violations) > 0) {
72
            throw InvalidResponseException::withViolations(
73
                "One or more audit log entries retrieved from the Middleware were invalid",
74
                $violations
75
            );
76
        }
77
78
        return $auditLog;
79
    }
80
}
81

src/Surfnet/StepupMiddlewareClientBundle/Configuration/Service/InstitutionConfigurationOptionsService.php 1 location

@@ 27-68 (lines=42) @@
24
use Surfnet\StepupMiddlewareClientBundle\Exception\InvalidResponseException;
25
use Symfony\Component\Validator\Validator\ValidatorInterface;
26
27
final class InstitutionConfigurationOptionsService
28
{
29
    /**
30
     * @var LibraryInstitutionConfigurationOptionsService
31
     */
32
    private $service;
33
    /**
34
     * @var ValidatorInterface
35
     */
36
    private $validator;
37
38
    public function __construct(LibraryInstitutionConfigurationOptionsService $service, ValidatorInterface $validator)
39
    {
40
        $this->service   = $service;
41
        $this->validator = $validator;
42
    }
43
44
    /**
45
     * @param $institution
46
     * @return null|InstitutionConfigurationOptions
47
     */
48
    public function getInstitutionConfigurationOptionsFor($institution)
49
    {
50
        $data = $this->service->getInstitutionConfigurationOptionsFor($institution);
51
52
        if ($data === null) {
53
            return null;
54
        }
55
56
        $institutionConfigurationOptions = InstitutionConfigurationOptions::fromData($data);
57
58
        $violations = $this->validator->validate($institutionConfigurationOptions);
59
        if (count($violations) > 0) {
60
            throw InvalidResponseException::withViolations(
61
                sprintf('Could not get institution configuration options for "%s": invalid response', $institution),
62
                $violations
63
            );
64
        }
65
66
        return $institutionConfigurationOptions;
67
    }
68
}
69