Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ActionRequestType
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
3 / 3
12
100.00% covered (success)
100.00%
1 / 1
 revocableAfterAcceptance
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 payloadProperty
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
 notificationFor
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\Api;
6
7use LambdaTwelve\OneRecord\Vocabulary\Generated\Api;
8
9enum ActionRequestType: string
10{
11    case Change = Api::ChangeRequest;
12    case Subscription = Api::SubscriptionRequest;
13    case AccessDelegation = Api::AccessDelegationRequest;
14    case Verification = Api::VerificationRequest;
15
16    /**
17     * Subscriptions and delegations are standing arrangements, so they can be
18     * ended after acceptance; an applied change or an acknowledged
19     * verification cannot be undone that way.
20     */
21    public function revocableAfterAcceptance(): bool
22    {
23        return $this === self::Subscription || $this === self::AccessDelegation;
24    }
25
26    /** The property that carries the request's payload (api:hasChange, ...). */
27    public function payloadProperty(): string
28    {
29        return match ($this) {
30            self::Change => Api::hasChange,
31            self::Subscription => Api::hasSubscription,
32            self::AccessDelegation => Api::hasAccessDelegation,
33            self::Verification => Api::hasVerification,
34        };
35    }
36
37    /**
38     * The notification event type announcing a status (CHANGE_REQUEST_ACCEPTED, ...).
39     */
40    public function notificationFor(RequestStatus $status): NotificationEventType
41    {
42        $prefix = match ($this) {
43            self::Change => 'CHANGE_REQUEST_',
44            self::Subscription => 'SUBSCRIPTION_REQUEST_',
45            self::AccessDelegation => 'ACCESS_DELEGATION_REQUEST_',
46            self::Verification => 'VERIFICATION_REQUEST_',
47        };
48
49        return NotificationEventType::from(Api::NAMESPACE . $prefix . substr($status->shortName(), \strlen('REQUEST_')));
50    }
51}