google-api-php-client-services
google-api-php-client-services copied to clipboard
Return $this in setters to allow chaining
Pretty much all the setters in the AnalyticsData lib return void, it would be much nicer to return $this in all setters to be able to chain them
Example: https://github.com/googleapis/google-api-php-client-services/blob/main/src/AnalyticsData/RunReportRequest.php
I wanted to write my requests like this
(new AnalyticsData\BatchRunReportsRequest())->setRequests([
(new AnalyticsData\RunReportRequest())
->setDimensions([
new AnalyticsData\Dimension(['name' => 'year']),
new AnalyticsData\Dimension(['name' => 'month']),
new AnalyticsData\Dimension(['name' => 'medium']),
])
->setDimensionFilter(...)
])
But without chaining, it becomes
$request1 = new AnalyticsData\RunReportRequest();
$request1->setDimensions([
new AnalyticsData\Dimension(['name' => 'year']),
new AnalyticsData\Dimension(['name' => 'month']),
new AnalyticsData\Dimension(['name' => 'medium']),
]);
$request1->setDimensionFilter(...);
$batch = new AnalyticsData\BatchRunReportsRequest();
$batch->setRequests([$request1]);
Please use this analytics data client, as the one you are using is no longer supported.
composer require google/analytics-data