Code Duplication    Length = 38-51 lines in 3 locations

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

@@ 33-83 (lines=51) @@
30
/**
31
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
32
 */
33
class RaSecondFactorService
34
{
35
    /**
36
     * @var LibraryRaSecondFactorService
37
     */
38
    private $service;
39
40
    /**
41
     * @var ValidatorInterface
42
     */
43
    private $validator;
44
45
    /**
46
     * @param LibraryRaSecondFactorService $service
47
     * @param ValidatorInterface $validator
48
     */
49
    public function __construct(LibraryRaSecondFactorService $service, ValidatorInterface $validator)
50
    {
51
        $this->service = $service;
52
        $this->validator = $validator;
53
    }
54
55
    /**
56
     * @param RaSecondFactorSearchQuery $query
57
     * @return RaSecondFactorCollection
58
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
59
     * @throws InvalidResponseException When the API responded with invalid data.
60
     * @throws ResourceReadException When the API doesn't respond with the resource.
61
     * @throws MalformedResponseException When the API doesn't respond with a proper response.
62
     */
63
    public function search(RaSecondFactorSearchQuery $query)
64
    {
65
        $data = $this->service->search($query);
66
67
        if ($data === null) {
68
            return null;
69
        }
70
71
        $secondFactors = RaSecondFactorCollection::fromData($data);
72
        $violations = $this->validator->validate($secondFactors);
73
74
        if (count($violations) > 0) {
75
            throw InvalidResponseException::withViolations(
76
                "One or more second factors retrieved from the Middleware were invalid",
77
                $violations
78
            );
79
        }
80
81
        return $secondFactors;
82
    }
83
}
84

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

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