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

docs: use modern named arguments syntax #10933

Merged
merged 1 commit into from
Sep 8, 2023
Merged

Conversation

kaznovac
Copy link
Contributor

@kaznovac kaznovac commented Sep 5, 2023

use official named arguments syntax in example instead of pre php 8 codestyle for 'named' arguments

@greg0ire
Copy link
Member

greg0ire commented Sep 5, 2023

Good idea. I can find more occurrences of this:

$ rg 'new \w+\(.*\$.*=' docs
docs/en/tutorials/pagination.rst
18:    $paginator = new Paginator($query, $fetchJoinCollection = true);

docs/en/cookbook/aggregate-fields.rst
214:            $account = new Account("123456", $maxCredit = 200);
226:            $account = new Account("123456", $maxCredit = 200);
$ rg '>\w+\([^\)]*\$[^\)]*=' docs
docs/en/reference/dql-doctrine-query-language.rst
1384:          ->setResultCacheLifeTime($seconds = 3600);
1395:    $query->useResultCache(true, $seconds = 3600, 'my_query_result');

Can you please fix those as well?

@kaznovac
Copy link
Contributor Author

kaznovac commented Sep 5, 2023

Of course, I'll look into it later

@kaznovac
Copy link
Contributor Author

kaznovac commented Sep 7, 2023

@greg0ire done

searched through the rest of documentation, no further instances


however:

there is this one, looks a bit like definition of default value:

- ``Query::setQueryCacheLifeTime($seconds = 3600)`` - Set lifetime
of the query caching.

but method definition does not specify the default value:

public function setQueryCacheLifetime($timeToLive): self

how would you like to proceed?
i'd guess this one should also be rewritten as named argument

@kaznovac kaznovac changed the title tutorials[pagination]: use modern named arguments syntax docs: use modern named arguments syntax Sep 7, 2023
@greg0ire
Copy link
Member

greg0ire commented Sep 7, 2023

i'd guess this one should also be rewritten as named argument

Yeah but would you then change the Query part to $query? Maybe what's best would be to drop the = 3600 part instead 🤔

@greg0ire
Copy link
Member

greg0ire commented Sep 7, 2023

Please squash your commits together, you shouldn't do one commit per file.

Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this change in the docs. Introducing this would need us to check the docs everytime when we change an internal variable name of an argument when it's a method with just one argument.

The variable $seconds was just there for context. Should the seconds value be used directly?

docs/en/reference/dql-doctrine-query-language.rst Outdated Show resolved Hide resolved
@@ -1392,7 +1392,7 @@ Result Cache API:
$result = $query->getResult(); // saved in given result cache id.

// or call useResultCache() with all parameters:
$query->useResultCache(true, $seconds = 3600, 'my_query_result');
$query->useResultCache(true, seconds: 3600, 'my_query_result');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be lifetime too.

Suggested change
$query->useResultCache(true, seconds: 3600, 'my_query_result');
$query->useResultCache(true, lifetime: 3600, 'my_query_result');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is deprecated since 2.7

should the documentation still promote its use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've asked as I'd like to remove this reference, or should we fix it now and remove it in the future?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should document the non-deprecated method here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've asked because method userResultCache is deprecated, and this section is written in a language that kind of 'promotes' it's use. I'd suggest to replace these lines with suggested replacement enableResultCache, but that's for another PR

/**
* Set whether or not to cache the results of this query and if so, for
* how long and which ID to use for the cache entry.
*
* @deprecated 2.7 Use {@see enableResultCache} and {@see disableResultCache} instead.
*
* @param bool $useCache Whether or not to cache the results of this query.
* @param int $lifetime How long the cache entry is valid, in seconds.
* @param string $resultCacheId ID to use for the cache entry.
*
* @return $this
*/
public function useResultCache($useCache, $lifetime = null, $resultCacheId = null)
{
return $useCache
? $this->enableResultCache($lifetime, $resultCacheId)
: $this->disableResultCache();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please send a PR. 🙂

@greg0ire
Copy link
Member

greg0ire commented Sep 7, 2023

everytime when we change an internal variable name of an argument when it's a method with just one argument.

How often are we going to do that? Because of named arguments, this is arguably a breaking change now.

use official named arguments syntax in example instead of pre php 8 codestyle for 'named' arguments
@SenseException
Copy link
Member

How often are we going to do that? Because of named arguments, this is arguably a breaking change now.

I suppose not that often, but it's still a bad practice to use this when we only have one argument or when all arguments are already covered. Question is if we keep named arguments for context or just use a variable again.

@greg0ire
Copy link
Member

greg0ire commented Sep 8, 2023

Why is it a bad practice to use named arguments when there is only one argument? I mean in some situations, it might make things clearer. It's not always obvious what an argument is. For instance, if you pass 60, it can be handy to know we are talking seconds and not minutes.

@SenseException
Copy link
Member

SenseException commented Sep 8, 2023

That's why I ask if this should be kept for context. My change request still included the named arguments.

@greg0ire greg0ire merged commit 9f555ea into doctrine:2.16.x Sep 8, 2023
@greg0ire greg0ire added this to the 2.16.3 milestone Sep 8, 2023
@greg0ire
Copy link
Member

greg0ire commented Sep 8, 2023

Thanks @kaznovac !

@kaznovac kaznovac deleted the patch-2 branch September 9, 2023 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants