Skip to content

Phpstan Level 4 (depends PHPStan Level 3) #1

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

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

Conversation

dantleech
Copy link
Owner

Depends on microsoft#385

roblourens and others added 30 commits February 14, 2018 10:39
Previously, the fallback case when something beginning
with the token `$` wasn't a simple variable
would be to assume it would be a complex variable
such as `$$x`

Check that the first token would be valid before recursing.
I wasn't using some of those APIs for Node/Token,
and didn't notice the incorrect phpdoc/code.
Update tests diagnostics and expected generated ASTs

For backwards compatibility, continue to make `yield from expr`
have an ArrayElement as a child node.

To maintain the invariant that all Nodes must have at least one child,
make $yieldExpression->arrayElement be null when parsing `yield;`

Aside: `yield &$a;` is (and should be)
parsed as the binary operator `(yield) & ($a)`.
This is surprising, but makes sense, being the only sane parse tree.

- Add a unit test that `yield & &$a;` is invalid.
  There is no way to parse that.

Verified with the PHP module nikic/php-ast

```php
var_export(ast_dump(
    ast\parse_code('<?php function test() { yield & $x; }', 50)
));
```
Fixes microsoft#189 : Fix parsing edge cases in yield statements
For microsoft#19: Fix an edge case parsing `=` and `instanceof`
The homebrew/php repository has been deprecated, and php formulae have been moved to [homebrew-core](https://github.com/Homebrew/homebrew-core)
…stallation-instructions

Update Mac OS PHP installation instructions
Said it could return null, when that was not possible.
Do this in a way that makes it less likely that applications already
using targetName will throw an exception or error.
This should be revisited in a future backwards incompatible release.
Add remainingTargetNames as a new property.

NOTE: traits16.php is invalid php 7 code,
so traits16.php.diag should be non-empty.
However, tolerant-php-parser emits a slightly different error
message than `php -l` would.
Add a test of parsing an empty `insteadof` clause

Make remainingTargetNames consistently be an empty array instead of null
Fixes microsoft#190: `insteadof` should be able to accept a name list
Add a new array `otherQualifiedNameList` alongside qualifiedName
to `CatchClause`. (Contains remaining `Token`s and `QualifiedName`s)
(This design breaks backwards compatibility as little as possible)

- A future backwards incompatible release should merge the two
  properties into `qualifiedNameList`,
  or something along those lines.

Add a new helper method to parse the catch list.

- The new helper is required because
  `tests/cases/php-langspec/exception_handling/odds_and_ends.php`
  should not fail because `catch (int $e)` is **syntactically** valid php
  (in 7.x), i.e. `php --syntax-check` doesn't reject it.
Fixes microsoft#103: Support parsing multiple exception types
Before, tolerant-php-parser parsed the tokens after `<?=` and `<?php`
the same way.

Fixes microsoft#220 (This commit and subsequent commits in this PR)

This adds `TokenKind::ScriptSectionStartWithEchoTag` and handles the
subsequent tokens differently if that token kind is seen instead of
`ScriptSectionStartTag`.

This reuses `ExpressionStatement` with an `EchoExpression` for simplicity.
The resulting expression will have no `echoKeyword` because
`<?=` was part of the preceding `InlineHTML` Node.

- In all cases that I'm aware of,
  the ExpressionStatement with the EchoExpression will be moved
  into the outer statement list.

NOTE: echo is a statement, not an expression.
It must be followed by `?>` or `;`

- `echo exprList` can't be used as an expression.

- Contrast with `print expr`, (`PrintIntrinsicExpression`),
  which is correctly treated as an expression.

Update documentation

Add a test that the Parser will warn about `<?= 'expr'<EOF>`.

- Fixing that bug got rid of an incorrect EmptyExpression in another test
  (programStructure5.php.tree)
Fixes microsoft#220 : Properly parse expression lists passed to `<?=`
    vendor/microsoft/tolerant-php-parser/src/Parser.php:1037 [2]
    "continue" targeting switch is equivalent to "break".
    Did you mean to use "continue 2"
Fix notices seen in PHP 7.3.0alpha4 (but not alpha3)
TysonAndre and others added 27 commits August 27, 2022 08:41
https://www.php.net/manual/en/function.halt-compiler.php can be used to
embed data in php scripts from the outermost scope.
In inner scope, it is parsed in php-src only for the sake of error
messages about it needing to be in the outermost scope, so treat it as
an unexpected token in other contexts.

(In an inner `{...}` scope, the call to `token_get_all()` will still
stop after `__halt_compiler();`, returning T_INLINE_HTML,
so the remaining statements can't be parsed, anyway)

Additionally, `__halt_compiler` can't be used as a name, a member name
(e.g. method name), etc, so calling it `TokenKind::Name` seems
incorrect. (`__COMPILER_HALT_OFFSET__` is already properly a Name)

Closes microsoft#381
`Parser::parseSourceFile()` accepts a nullable string $uri.
Avoid a potential type error
The `string` is the type of each argument.
The `...` indicates that it is an array of that type, like
`function (string ...$classNames)` also would indicate.
…izer

Update example ast output to latest version's output
…suite

Speed up running the framework validation test suite
Add MissingToken for missing QualifiedName
Change getUri return type to nullable string
Use PHPDoc `@param string ...$classNames`
Added ReturnTypeWillChange

Fix return type for Expression

Add type hints for returned variables

Add generic parameter for delimted list

Fixing type hints

Ignore co-variance error

Remove TODO - it already must always be a Node

Ignore error

Add missing types

Update phpstan to level 3

Add phpstan to dev reqs

No need to install phpstan independently

Do not override unary expression operand

It seems to me that the operand can be any expression

Added token to operand types -- should this be MissingToken?

Include tokens in return types

ExpressionStatement => EchoStatement

It seems this is always an EchoStatement not an ExpressionStatement

unaryExpressionOrHigher can return a ThrowExpression

Remove overridden property

Add Token to union

Remove QualifiedName and rename local variable

Remove unused import

Add return types

Remove trailing whitespace

Add MissingToken type
... then it MUST be true in the right hand side of ||
@dantleech dantleech changed the base branch from phpstan-level-3 to master January 5, 2023 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.