Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return $this in setters to allow chaining #2319

Open
Tofandel opened this issue Feb 23, 2023 · 1 comment
Open

Return $this in setters to allow chaining #2319

Tofandel opened this issue Feb 23, 2023 · 1 comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@Tofandel
Copy link

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]);
@bshaffer
Copy link
Contributor

bshaffer commented Mar 17, 2023

Please use this analytics data client, as the one you are using is no longer supported.

composer require google/analytics-data

@bshaffer bshaffer added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants