Code Duplication    Length = 51-51 lines in 2 locations

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

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

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