/** * @param mixed $data * @return Consent * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ private static function createConsent($data) { Assert::keyExists($data, 'service_provider', 'Consent JSON structure must contain key "service_provider"'); Assert::keyExists($data, 'consent_given_on', 'Consent JSON structure must contain key "consent_given_on"'); Assert::keyExists($data, 'last_used_on', 'Consent JSON structure must contain key "last_used_on"'); Assert::keyExists($data, 'consent_type', 'Consent JSON structure must contain key "consent_type"'); Assert::choice($data['consent_type'], [ConsentType::TYPE_EXPLICIT, ConsentType::TYPE_IMPLICIT], '"%s" is not one of the valid ConsentTypes: %s'); $consentGivenOn = DateTimeImmutable::createFromFormat(DateTime::ATOM, $data['consent_given_on']); $lastUsedOn = DateTimeImmutable::createFromFormat(DateTime::ATOM, $data['last_used_on']); Assert::isInstanceOf($consentGivenOn, '\\DateTimeImmutable', sprintf('Consent given on date must be formatted according to the ISO8601 standard, got "%s"', $data['consent_given_on'])); Assert::isInstanceOf($lastUsedOn, '\\DateTimeImmutable', sprintf('Last used on date must be formatted according to the ISO8601 standard, got "%s"', $data['last_used_on'])); if ($data['consent_type'] === ConsentType::TYPE_EXPLICIT) { $consentType = ConsentType::explicit(); } else { $consentType = ConsentType::implicit(); } return new Consent(self::createServiceProvider($data['service_provider']), $consentGivenOn, $lastUsedOn, $consentType); }