@@ -16,44 +16,44 @@ class Transaction
1616 public const TYPE_REQUEST = 'request ' ;
1717 public const TYPE_JOB = 'job ' ;
1818
19- /** @var string Unique ID for transaction */
20- protected $ id ;
19+ /** Unique ID for transaction */
20+ protected string $ id ;
2121
22- /** @var string Type of transaction */
23- protected $ type ;
22+ /** Type of transaction */
23+ protected string $ type ;
2424
25- /** @var string|null Name to identify transaction */
26- protected $ name ;
25+ /** Name to identify transaction */
26+ protected ? string $ name = null ;
2727
28- /** @var int Start time as milliseconds since epoch */
29- protected $ startTime ;
28+ /** Start time as milliseconds since epoch */
29+ protected int $ startTime ;
3030
31- /** @var int End time as milliseconds since epoch */
32- protected $ endTime ;
31+ /** End time as milliseconds since epoch */
32+ protected ? int $ endTime = null ;
3333
34- /** @var int Duration as milliseconds */
35- protected $ duration ;
34+ /** Duration as milliseconds */
35+ protected ? int $ duration = null ;
3636
37- /** @var Agent Meta information for transaction agent */
38- protected $ agent ;
37+ /** Meta information for transaction agent */
38+ protected Agent $ agent ;
3939
40- /** @var Http Meta information for request transaction */
41- protected $ http ;
40+ /** Meta information for request transaction */
41+ protected ? Http $ http = null ;
4242
43- /** @var Service Meta information for transaction service */
44- protected $ service ;
43+ /** Meta information for transaction service */
44+ protected ? Service $ service = null ;
4545
46- /** @var System Meta information for transaction system */
47- protected $ system ;
46+ /** Meta information for transaction system */
47+ protected System $ system ;
4848
49- /** @var Tags Custom meta tags */
50- protected $ tags ;
49+ /** Custom meta tags */
50+ protected ? Tags $ tags = null ;
5151
52- /** @var User Meta information for transaction user */
53- protected $ user ;
52+ /** Meta information for transaction user */
53+ protected ? User $ user = null ;
5454
5555 /** @var Span[] Spans that occur during transaction */
56- protected $ spans ;
56+ protected array $ spans ;
5757
5858 /**
5959 * Deserialize formatted properties array into Transaction object
@@ -66,13 +66,13 @@ public static function createFromArray(array $properties): Transaction
6666 $ type = $ trace ['type ' ];
6767 $ name = $ trace ['name ' ];
6868 $ startTime = $ trace ['start_time ' ];
69- $ endTime = isset ( $ trace ['end_time ' ]) ? $ trace [ ' end_time ' ] : null ;
70- $ duration = isset ( $ trace ['duration ' ]) ? $ trace [ ' duration ' ] : null ;
69+ $ endTime = $ trace ['end_time ' ] ?? null ;
70+ $ duration = $ trace ['duration ' ] ?? null ;
7171
7272 # service properties
7373 $ service = $ properties ['service ' ];
74- $ serviceName = isset ( $ service ['name ' ]) ? $ service [ ' name ' ] : null ;
75- $ environment = isset ( $ service ['environment ' ]) ? $ service [ ' environment ' ] : null ;
74+ $ serviceName = $ service ['name ' ] ?? null ;
75+ $ environment = $ service ['environment ' ] ?? null ;
7676
7777 # create transaction
7878 $ transaction = new Transaction ($ id , $ type , $ name );
@@ -83,37 +83,37 @@ public static function createFromArray(array $properties): Transaction
8383 $ transaction ->service ()->setEnvironment ($ environment );
8484
8585 # agent properties
86- $ agent = isset ( $ properties ['agent ' ]) ? $ properties [ ' agent ' ] : [];
86+ $ agent = $ properties ['agent ' ] ?? [];
8787 if ($ agent !== []) {
8888 $ transaction ->agent ()->fillFromArray ($ agent );
8989 }
9090
9191 # http properties
92- $ http = isset ( $ properties ['http ' ]) ? $ properties [ ' http ' ] : [];
92+ $ http = $ properties ['http ' ] ?? [];
9393 if ($ http !== []) {
9494 $ transaction ->http ()->fillFromArray ($ http );
9595 }
9696
9797 # system properties
98- $ system = isset ( $ properties ['system ' ]) ? $ properties [ ' system ' ] : [];
98+ $ system = $ properties ['system ' ] ?? [];
9999 if ($ system !== []) {
100100 $ transaction ->system ()->fillFromArray ($ system );
101101 }
102102
103103 # tags
104- $ tags = isset ( $ properties ['tags ' ]) ? $ properties [ ' tags ' ] : [];
104+ $ tags = $ properties ['tags ' ] ?? [];
105105 if ($ tags !== []) {
106106 $ transaction ->tags ()->replaceAll ($ tags );
107107 }
108108
109109 # user properties
110- $ user = isset ( $ properties ['user ' ]) ? $ properties [ ' user ' ] : [];
110+ $ user = $ properties ['user ' ] ?? [];
111111 if ($ user !== []) {
112112 $ transaction ->user ()->fillFromArray ($ user );
113113 }
114114
115115 # spans
116- $ spans = isset ( $ properties ['spans ' ]) ? $ properties [ ' spans ' ] : [];
116+ $ spans = $ properties ['spans ' ] ?? [];
117117 foreach ($ spans as $ spanProperties ) {
118118 $ span = Span::createFromArray ($ transaction , $ spanProperties );
119119 $ transaction ->pushSpan ($ span );
@@ -255,21 +255,9 @@ public function finish(?int $at = null): Transaction
255255 */
256256 public function agent (): Agent
257257 {
258- if ($ this ->agent === null ) {
259- $ this ->agent = new Agent ();
260- }
261-
262258 return $ this ->agent ;
263259 }
264260
265- /**
266- * Determine if agent information is present
267- */
268- public function hasAgent (): bool
269- {
270- return $ this ->agent !== null ;
271- }
272-
273261 /**
274262 * Service meta information
275263 */
@@ -315,21 +303,9 @@ public function hasHttp(): bool
315303 */
316304 public function system (): System
317305 {
318- if ($ this ->system === null ) {
319- $ this ->system = new System ();
320- }
321-
322306 return $ this ->system ;
323307 }
324308
325- /**
326- * Determine if system information is present
327- */
328- public function hasSystem (): bool
329- {
330- return $ this ->system !== null ;
331- }
332-
333309 /**
334310 * Custom meta information
335311 */
@@ -423,7 +399,7 @@ public function newFilesystemSpan(string $name, ?string $parentSpanId = null): S
423399 return $ this ->newSpan ($ name , Span::TYPE_FILESYSTEM , $ parentSpanId );
424400 }
425401
426- public function serialize ()
402+ public function serialize (): array
427403 {
428404 $ spanData = [];
429405 foreach ($ this ->spans () as $ span ) {
@@ -442,18 +418,14 @@ public function serialize()
442418 'spans ' => $ spanData ,
443419 ];
444420
445- if ($ this ->hasAgent ()) {
446- $ data ['agent ' ] = $ this ->agent ()->serialize ();
447- }
421+ $ data ['agent ' ] = $ this ->agent ()->serialize ();
422+ $ data ['system ' ] = $ this ->system ()->serialize ();
448423 if ($ this ->hasHttp ()) {
449424 $ data ['http ' ] = $ this ->http ()->serialize ();
450425 }
451426 if ($ this ->hasService ()) {
452427 $ data ['service ' ] = $ this ->service ()->serialize ();
453428 }
454- if ($ this ->hasSystem ()) {
455- $ data ['system ' ] = $ this ->system ()->serialize ();
456- }
457429 if ($ this ->hasTags ()) {
458430 $ data ['tags ' ] = $ this ->tags ()->serialize ();
459431 }
0 commit comments