aawnu/php-ga4

rationale for Analytics::new()

8ctopus opened this issue · 2 comments

Hi again Alex,

What is the rationale for Analytics::new('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true) instead of new Analytics('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true)?

aawnu commented

Hi again Alex,

What is the rationale for Analytics::new('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true) instead of new Analytics('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true)?

Thats mainly a readability thing for quick nested methods

$analytics = new Analytics('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true);
$analytics->method()
    ->method()
    ->method();

compared to

$analytics = (new Analytics('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true))
    ->method()
    ->method()
    ->method();

compared to

$analytics = Analytics::new('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true)
    ->method()
    ->method()
    ->method();

Oh I see, thank you for the explanation, I mainly use the second option, now I know one more.