Skip to content

Commit

Permalink
add phpdocs and misc
Browse files Browse the repository at this point in the history
  • Loading branch information
arrilot committed Nov 19, 2021
1 parent b569eae commit 1f43290
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
28 changes: 25 additions & 3 deletions src/InitialEventDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,32 @@
class InitialEventDTO
{
public function __construct(
/** Unique identifier of event, e.g "a95e90a3-82a3-4c77-82b2-4080a333456d" */
public string $correlationId,

/** UTC-based ISO-8601 datetime of initial event, e.g "2021-11-17T16:08:26.385954Z" */
public string $timestamp,

/** Slug name of the application where initial event took place, e.g "api-gateway" */
public string $app,

/** Name of API endpoint or console command name, e.g "/api/v1/users/{id}" */
public string $entrypoint,

/** Guid or autoincrement user id of initiator, e.g "1" */
public string $userId = '',

/** User type of initiator if there are different types of users in your system, e.g "admin" */
public string $userType = '',

/** If there is a "login as another user" functionality in your system you can use this field as a place to store a real user id, e.g "1" */
public string $realUserId = '',

/** if there is a "login as another user" functionality in your system you can use this field as a place to store a real user type, e.g "admin" */
public string $realUserType = '',

/** Not used by package by default. This field can be used if there is a need to pass some additional data with InitialEventData, e.g "foo:bar;foo2:baz" */
public string $misc = '',
) {
}

Expand All @@ -27,8 +45,9 @@ public static function fromScratch(
string $userType = '',
string $realUserId = '',
string $realUserType = '',
string $misc = '',
string $correlationId = '',
string $timestamp = ''
string $timestamp = '',
): static {
return new static(
correlationId: $correlationId ?: Uuid::uuid4()->toString(),
Expand All @@ -38,7 +57,8 @@ public static function fromScratch(
userId: $userId,
userType: $userType,
realUserId: $realUserId,
realUserType: $realUserType
realUserType: $realUserType,
misc: $misc,
);
}

Expand All @@ -61,7 +81,8 @@ public static function fromSerializedString(string $serializedData): static
userId: $params['userId'] ?? '',
userType: $params['userType'] ?? '',
realUserId: $params['realUserId'] ?? '',
realUserType: $params['realUserType'] ?? ''
realUserType: $params['realUserType'] ?? '',
misc: $params['misc'] ?? ''
);
}

Expand All @@ -88,6 +109,7 @@ public function toArray(): array
'userType' => $this->userType,
'realUserId' => $this->realUserId,
'realUserType' => $this->realUserType,
'misc' => $this->misc,
];
}
}
10 changes: 7 additions & 3 deletions tests/InitiatorDTOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
userId: "1",
userType: "admin",
app: "mobile,api",
entrypoint: "/api/v1/users/{id}"
entrypoint: "/api/v1/users/{id}",
misc: ""
);

$expected = 'correlationId=a95e90a3-82a3-4c77-82b2-4080a333456d,timestamp=2021-11-17T16:08:26.385954Z,app=mobile__COMMA__api,entrypoint=/api/v1/users/{id},userId=1,userType=admin';
Expand All @@ -25,7 +26,8 @@
userId: "1",
userType: "admin",
app: "mobile,api",
entrypoint: "/api/v1/users/{id}"
entrypoint: "/api/v1/users/{id}",
misc: ""
);

expect(InitialEventDTO::fromSerializedString($serializedString))->toEqual($expected);
Expand All @@ -36,7 +38,8 @@
userId: "1",
userType: "admin",
app: "mobile-api",
entrypoint: "/api/v1/users/{id}"
entrypoint: "/api/v1/users/{id}",
misc: "",
);

expect($dto->correlationId)->not->toBeEmpty();
Expand All @@ -46,5 +49,6 @@
'userType' => "admin",
'app' => "mobile-api",
'entrypoint' => "/api/v1/users/{id}",
'misc' => "",
]);
});

0 comments on commit 1f43290

Please sign in to comment.