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

gen_stub: various simplifications and clean up (4) #18109

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

DanielEScherzer
Copy link
Contributor

Each commit can be reviewed independently, and should have no functional changes

Otherwise GitHub's syntax highlighting treats it as the end of the code and
stops highlighting
Deduplicates the setting up of the `zend_string_init_interned()` call, removes
the need for `ExposedDocComment::getLength()` and so that method is removed.
* Return a string rather than an array, all callers just immediately used
`implode()` to join the elements in the array with nothing between them
* In the callers, inline some single-use variables with the template for the
version-dependent code
* Remove the callback to `array_filter` specifying that only items that are not
`empty()` be removed - this is the default behavior
There is no need to add special handling for the default value of `null`, since
it is not loosely-equals to any of the strings 'UNKNOWN', 'false', 'true', or
'null' it will just be returned directly anyway.
Move the logic out of `funcInfoToCode()` and update it. In the process, make
`ArgInfo::getDefaultValueAsArginfoString()` private.
The vast majority of the decisions about the use of `ZEND_BEGIN_ARG_INFO_EX` or
one of its variations are based on the return information of the function - is
the type builtin, is the return information tentative, does it include an
object mask, etc. Accordingly, move the logic into the `ReturnInfo` class.

The logic is actually moved into two methods, `ReturnInfo::beginArgInfo()`,
which needs to handle the case of tentative returns being used when PHP < 8.1
is supported, and `::beginArgInfoCompatible()`, which can assume that PHP 8.1+
is supported and thus make use of early returns and guard clauses. Further
improvements to the logic will be made in a subsequent commit.

In the process, make `ReturnInfo::$byRef` private.
Reduce the number of global functions by moving it to instance method
`FuncInfo::toArgInfoCode()`.

In the process, make `FuncInfo::$numRequiredArgs` private.
The following parameters were either unused before this commit or became unused
as part of updating callers to stop passing unused parameters to other
functions updated in this commit:
* `FuncInfo::getMethodSynopsisDocument()` - `$funcMap`, `$aliasMap`
* `FuncInfo::getMethodSynopsisElement()` - `$funcMap`, `$aliasMap`
* `ConstInfo::getGlobalConstDeclaration()` - `$allConstInfos`
* `generateMethodSynopses()` - `$aliasMap`
* `replaceMethodSynopses()` - `$aliasMap`
* Use `@param` instead of `@var` for parameters
* Fix type of `$attributeGroups` in `AttributeInfo::createFromGroups()`
* Remove extra documentation of `$allConstInfo` for
`ClassInfo::getClassSynopsisDocument()`, it is already documented under the
correct name `$allConstInfos`
* Remove unneeded `@throws`
Reduce the number of global functions by moving it to instance method
`FileInfo::handleStatements()`.
Reduce the number of global functions by moving it to static method
`FileInfo::handlePreprocessorConditions()`. Since it is only used by
`FileInfo::handleStatements()`, also make it private.
Reduce the number of global functions by moving it to static method
`DocCommentTag::parseDocComments()`.
For a lot of the structures, the parsing of doc comment tags is based on if a
specific tag is present, or the value that it has if it is. Add a new helper
method, `DocCommentTag::makeTagMap()`, that turns an array of tag instances
into a map from tag name to value (the last value, if there are multiple uses
of the same tag name). Then, for the simple cases where just a tag's presence
is all that is checked, or just the (last) value is used, check the map instead
of using a loop through all of the tags present.
Separate out the creation of a legacy version of a FileInfo object, which has
information for old versions of PHP discarded, from its subsequent use in
`processStubFile()`.

In the process, make `FileInfo::$legacyArginfoGeneration` private, and inline
the single use of `FileInfo::getAllClassInfos()`, removing that method.
The following properties are made private:
* `ArgInfo::$phpDocType`
* `ClassInfo::$flags`, `::$attributes`, `::$extends`, `::$implements`
* `FileInfo::$isUndocumentable`

The following are made protected:
* `VariableLike::$flags`
Reduce the number of global functions by moving it to static method
`FileInfo::parseStubFile()`. Additionally, make `FileInfo::handleStatements()`
private now that the only caller is part of the class.
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.

1 participant