Tomas Votruba
9de96821f7
Add support for ??= operator
...
Introduced in PHP 5.4, represented using an AssignOp\Coalesce node.
2019-02-09 11:16:26 +01:00
Lars Moelleken
b7e6361536
updates via "rectorphp/rector" ( #573 )
...
- "global" -> remove unused "use" statements
- "phpunit" -> fix "@covers" comments
- "phpunit" -> replace "->will($this->returnValue()" with "->willReturn()"
- "UseTest.php" -> add missing namespace
- "composer.json" -> use "autoload-dev"
- remove -> "require_once" usage in the tests (use autoload-dev via composer.json)
-> most of the changes are done automatically by "https://github.com/rectorphp/rector "
2019-01-19 11:18:00 +01:00
Nikita Popov
1f95f9215c
Tweak type annotation to include null
2019-01-12 17:31:37 +01:00
Nikita Popov
6b9dd7afe7
Avoid redundant argument
2019-01-12 17:31:37 +01:00
Tomas Votruba
af8c729603
Add PHP 7.4 typed properties support
2019-01-05 21:34:25 +01:00
Tomas Votruba
0ef61b49bb
add float/double/real KIND support to Cast\Double node
2019-01-05 19:23:00 +01:00
Nikita Popov
90ee36a7fc
Actually remove assertion...
2018-12-26 14:19:18 +01:00
Nikita Popov
49d73e829f
Remove anon class null name assertion
...
Fixes #554 .
2018-12-26 12:23:42 +01:00
Nikita Popov
f42bbc2403
Avoid default action for error production
...
error is not necessarily going to have a semantic value, make sure
that the default action $$=$1 is not used.
Fixes #551 .
2018-11-30 11:00:48 +01:00
Tomas Votruba
a74b54ce8b
[cs] remove unused @var name
2018-11-20 20:31:31 +01:00
Nikita Popov
3d0f7843d4
Support error recovery for missing return type
...
The return type is set to "null" in this case.
Fixes #544 .
2018-10-25 16:56:50 +02:00
Maks Rafalko
dc323458b4
Add new constant to be returned from enterNode() to not traverse current and child nodes ( #536 )
...
* Add new constant to be returned from enterNode() to not travers current node for subsequent visitors and skip children traversing
* Allow visitors to replace nodes in leaveNode() when DONT_TRAVERSE_CURRENT_AND_CHILDREN is used
2018-10-08 22:26:00 +02:00
Matthew Brown
674c5610fb
StaticCall::$name cannot be a string
2018-10-04 21:29:57 +02:00
Nikita Popov
eebaa94647
Flexible doc strings: Fix some issues, add more tests
2018-09-22 10:09:00 +02:00
Nikita Popov
0ed9065b4c
Flexible doc: Validate and strip indentation
...
If indentation is invalid, we strip on a best-effort basis.
The error position information is not great, but I don't want to
introduce sub-token error positioning at this point in time.
2018-09-21 21:47:01 +02:00
Nikita Popov
5f73c4de80
Flexible doc: Validate end label indentation
...
Move doc string parsing logic from rebuildParsers.php and
String_::parseDocString() into ParserAbstract. This stuff is
going to get complicated now.
For now only implement the validation of the indentation on the
end label.
2018-09-21 16:31:17 +02:00
Nikita Popov
a5c726bfbf
Make sure heredoc end label not followed by label char
2018-09-21 11:44:39 +02:00
Nikita Popov
83766c8c0e
Partial support for flexible heredoc/nowdoc
...
This only implements the token emulation part, it does not yet
handle the indentation stripping.
Emulating this feature on old PHP versions is really tough and is
not going to work perfectly, but hopefully this implementation is
"good enough".
2018-09-21 11:16:00 +02:00
Nikita Popov
16c5d107ca
Revert "Add check for leading backslash in Name ctor"
...
This reverts commit 2f67429ec9
.
Reverting this to avoid a BC break in a patch release, will
reapply for the next major version.
2018-09-18 09:00:32 +02:00
Tomáš Votruba
d7d581c1d2
Remove NodeTraverser dependency on parent::__construct() ( #528 )
...
A parent::__construct() call is now optional when extending NodeTraverser.
2018-08-28 07:49:42 +09:00
Nikita Popov
41408081d7
Rename setTypeHint() to setType()
...
To align with modern terminology -- we don't like calling these
type hints anymore. Old method name remains, marked as @deprecated.
2018-07-22 21:41:21 +02:00
ProgMiner
8d9ae46597
Add Builder\TraitUse::with receiving adaptation builder ability
2018-07-22 21:23:00 +02:00
ProgMiner
f6fc248ca3
Add TraitUseAdaptation and factory for it
2018-07-22 21:23:00 +02:00
ProgMiner
84dcd179d2
Add TraitUse builder and useTrait builder factory
2018-07-22 21:22:57 +02:00
Nikita Popov
2f67429ec9
Add check for leading backslash in Name ctor
...
Fixes #523 .
2018-07-21 21:58:32 +02:00
Nikita Popov
0cd7207ca6
Add tests for var() and propertyFetch()
2018-07-20 21:59:42 +02:00
Eridan Domoratskiy
6751ac3c9d
Add Variable and PropertyFetch node constructors
2018-07-20 21:49:21 +02:00
Nikita Popov
b855c1ca23
Add some tests for new use builders
2018-07-20 21:44:37 +02:00
Eridan Domoratskiy
53c732a96d
Add useFunction() and useConst() builder methods
2018-07-20 21:38:27 +02:00
Nikita Popov
8b1c9c0409
Store comment at end of class in Nop statement
...
Fixed #509 .
2018-07-07 12:49:49 +02:00
openex27
df64d86cf4
Check for empty $append in safeAppend()
...
Can happen with Nop statements.
2018-07-07 12:34:07 +02:00
Nikita Popov
f967b867d5
Improve error recovery in arrays
...
Similarly to missing semicolons, the error is not indicated in the
AST.
Fixes #512 .
2018-07-07 12:24:06 +02:00
Nikita Popov
6526ea2497
Throw when printin EncapsedStringPart
...
This needs to go through something like Encapsed or ShellExec to
determine quotation type. Explicitly throw an exception to avoid
getting an undefined method error.
2018-06-03 13:31:00 +02:00
David Paz
3ce5e628a7
Fix binary operator doc block comment ( #504 )
...
Remove reference to bitwise and in doc block.
2018-05-19 12:21:45 +02:00
Gabriel Caruso
ee870e3464
Fixes from PHPStan ( #502 )
2018-05-19 11:12:24 +02:00
Nikita Popov
7b201b63d2
Error recovery for functions without body
2018-05-13 16:28:08 +02:00
Nikita Popov
01e85a26c6
Support recovery for param without variable
...
We store an Expr\Error for the variable in this case.
2018-05-12 19:49:39 +02:00
Nikita Popov
fa99c3fbfb
Recover from foreach without as
2018-04-28 22:31:45 +02:00
Nikita Popov
6121001576
Remove unused ParserAbstract::$errors property
...
Leftover from before ErrorHandler was introduced.
2018-03-30 21:45:52 +02:00
Nikita Popov
7208b1c7ac
Improve error recovery in classes ( #492 )
2018-03-30 16:03:03 +02:00
Nikita Popov
7f8ff1b9a4
Add support for list reference assignments
...
RFC: https://wiki.php.net/rfc/list_reference_assignment
2018-03-10 16:48:20 +01:00
Nikita Popov
91a462ce76
PHP 7.3: Add support for trailing commas in calls
...
RFC: https://wiki.php.net/rfc/trailing-comma-function-calls
2018-03-10 16:41:20 +01:00
Nikita Popov
610617fe93
Also add new() builder
2018-03-03 22:25:58 +01:00
Nikita Popov
ff2d85dc6b
Add constFetch() and classConstFetch() builders
2018-03-03 22:14:42 +01:00
Nikita Popov
b998d1e9b5
Add funcCall(), methodCall() and staticCall() builders
2018-03-03 15:40:51 +01:00
Nikita Popov
6aba7624ed
Add replacement sanity check in traverser
2018-03-03 13:22:36 +01:00
Nikita Popov
9cea94000a
Merge branch '3.x'
...
Conflicts:
CHANGELOG.md
lib/PhpParser/NodeAbstract.php
2018-02-28 21:32:04 +01:00
Théo FIDRY
1c3eabb000
Replace string by class call ( #477 )
...
For better PHP-Scoper compatibility
2018-02-23 22:44:40 +01:00
Gabriel Caruso
14454326e9
Fix misspellings
2018-02-06 14:47:39 +01:00
Nikita Popov
ad9c42b66a
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/Parser/Php5.php
lib/PhpParser/Parser/Php7.php
2018-01-30 23:07:11 +01:00
Nikita Popov
08215e7646
Fix duplicate switch comment assignment
...
Fixes #469 .
2018-01-30 23:06:20 +01:00
Nikita Popov
a513ccabb7
Improve constant evaluation and add docs
...
Split into evaluateDirectly() and evaluateSilently(), to be able
to treat errors more gracefully. Add documentation for constant
evaluation.
2018-01-27 17:47:45 +01:00
Nikita Popov
d817818b5d
Move TokenStream into Internal namespace
2018-01-27 13:40:20 +01:00
Nikita Popov
6a273c9fbd
Remove Autoloader class
2018-01-25 23:13:53 +01:00
Nikita Popov
1cdb280a30
Merge branch '3.x'
2018-01-25 22:28:08 +01:00
Nikita Popov
d01fafcb40
Handle +(++$x) and -(--$x) as well
2018-01-25 22:27:37 +01:00
Nikita Popov
b85b6b3519
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/PrettyPrinter/Standard.php
2018-01-25 22:18:32 +01:00
Nikita Popov
94c715d97e
Fix pretty printing of -(-$x) and +(+$x)
...
Fixes #459 .
2018-01-25 22:17:35 +01:00
Nikita Popov
4dacbb8d39
FPPP: Fix indentation on list insertion
...
Use indentation of last list element, instead of indentation
before the insertion point.
Fixes #466 .
2018-01-25 22:08:40 +01:00
Gabriel Caruso
68d07c4662
[CS] New line in the end of file
2018-01-13 16:08:26 +01:00
Gabriel Caruso
f6617e6d25
[CS] Space after ternary operator
2018-01-13 16:04:00 +01:00
Gabriel Caruso
2499534729
[CS] Whitespace before return type
2018-01-13 16:03:59 +01:00
Gabriel Caruso
e0a2043089
[CS] Space before casting
2018-01-13 16:03:57 +01:00
Gabriel Caruso
e6e52abae7
[CS] Trim whitespaces
2018-01-13 16:03:56 +01:00
Gabriel Caruso
7f72c84122
[CS] Open class brackets in new line
2018-01-13 16:03:55 +01:00
Gabriel Caruso
fc8ac71e76
[CS] Trim whitespaces inside arrays
2018-01-13 16:03:54 +01:00
Gabriel Caruso
a8968caa5b
[CS] Remove extra lines
2018-01-13 16:03:53 +01:00
Nikita Popov
5285df8f22
[CS] Use elseif instead of else if
...
Conflicts:
lib/PhpParser/TokenStream.php
2018-01-13 16:03:36 +01:00
Gabriel Caruso
bf7d811cda
Add methods visibility ( #464 )
...
* [PSR-2] Visibility before static
* [PSR-2] Declare method Visibility
2018-01-10 19:07:41 +01:00
Gabriel Caruso
248b29ecf6
Add public visibility to getType method ( #463 )
2018-01-10 18:57:48 +01:00
Gabriel Caruso
3bc31488ce
Combine issets ( #460 )
2018-01-04 13:36:01 +01:00
Nikita Popov
92b39e3d1f
Fix nNextFreeElement for arrays with trailing comma
...
Ugh.
2017-12-26 21:17:36 +01:00
Nikita Popov
1c7fd314d1
FPPP: Add heuristic for multi-line lists
2017-12-26 21:14:36 +01:00
Nikita Popov
fb8175567e
Simplify delayed add code
...
$insertStr always stays the same, so no reason to store it
separately.
2017-12-26 17:53:36 +01:00
Nikita Popov
8d3cb5f57b
FPPP: Fallback if we must insert a block
2017-12-26 15:41:38 +01:00
Nikita Popov
a86151f24f
FPPP: Fix fallback for inline HTML
2017-12-26 15:08:29 +01:00
Gabriel Caruso
e6e8791848
Missing # in method description
2017-12-25 14:28:33 +01:00
Gabriel Caruso
4dbb02c57b
Use Null Coalesce Operator
2017-12-15 21:41:41 +01:00
Nikita Popov
4fcdac40d1
FPPP: Fix insertion of multiple elems at start
2017-12-02 15:10:15 +01:00
Nikita Popov
dc3ace55c3
FPPP: Support insert at start of list node ( #446 )
2017-12-01 22:09:51 +01:00
Nikita Popov
e5453f0d46
Extract pSingleQuotedString as an extension point
...
And add some more string formatting tests.
2017-12-01 18:31:21 +01:00
Nikita Popov
b507fa43da
Ensure names are not empty
2017-12-01 18:13:55 +01:00
Nikita Popov
336a49b428
FPPP: Fix comment indentation ( #443 )
2017-11-13 13:27:27 +01:00
Nikita Popov
fa174b093f
Merge branch '3.x'
2017-11-13 01:15:38 +01:00
Nikita Popov
94ca9a7ab9
Use Tokens::class in lexer
...
Ref #441 .
2017-11-13 01:14:55 +01:00
Nikita Popov
0bb74e03aa
Drop two more getType() usages in builders
2017-11-13 00:24:01 +01:00
Nikita Popov
8d3f48ab75
Switch some auxiliary pretty printer tables away from getType()
...
Instead use class names via ::class.
2017-11-13 00:18:44 +01:00
Nikita Popov
1c11626f0a
Add explicit getType() methods
...
Rather than automatically deriving getType() from the class name.
2017-11-12 21:27:14 +01:00
Nikita Popov
05e2cd287e
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/NodeAbstract.php
2017-11-12 21:12:27 +01:00
Maks Rafalko
bac91b426e
Correctly determine Type of Node when PHP-Parser's namespaces are prefixed
...
Hi there,
I'm working on mutation testing framework ([Infection](https://github.com/infection/infection/ )) that is distributed as a PHAR. One of this goal is to run target project's test suite against mutated code. Since we use reflection and load project's autoloader, we want to avoid potential conflicts between vendor files of Infection itself and the target project.
To avoid this issue, there is a project calld [PHP-Scoper](https://github.com/humbug/php-scoper ). What it does is it prefixes all the namespaces of the library (including vendor folder) with some character(s), for example namespace `Infection\Mutator\PublicVisibility` is transformed to `ScoperAbc123\Infection\Mutant\PublicVisibility`.
But since it also prefixes vendor folder, PHP-Parser's classes are prefixed as well and `NodeAbstract::getType()` after this prefixing works incorrectly.
There is a hardcoded number `15` which means to remove `'PhpParser\Node'` (length=15) substring from the FQCN.
Code:
```php
// PHPParser\Node\Stmt\Declare_ -> Stmt_Declare
return strtr(substr(rtrim(get_class($this), '_'), 15), '\\', '_');
```
What I suggest is a little be more dynamic solution, to correctly extract class name (type) from the ***prefixed*** FQCL:
`ScoperAbc123\PHPParser\Node\Stmt\Declare_` -> `Stmt_Declare`
2017-11-12 21:11:41 +01:00
Nikita Popov
a75164c77e
Rename YYNLSTATES to numNonLeafStates
2017-11-12 16:09:00 +01:00
Nikita Popov
c59e75f873
Clear parser state directly after parsing
...
I don't think this makes any difference in practical scenarios, but
it makes memory usage analysis simpler.
2017-11-11 16:54:52 +01:00
Nikita Popov
4392a7b164
Fix PHP5 static call fixup
...
Variable nodes directly store the variable name as a string, they
don't use VarLikeIdentifier. So remove this wrapper if it exists.
2017-11-11 12:23:14 +01:00
Nikita Popov
68e9b91e9c
Use fully-qualified names for global constant references
2017-11-10 23:33:12 +01:00
Nikita Popov
e2c0c598a3
FPPP: Optimize indentation calculation
...
Precalculate the indentation for every position. The previous
implementation was quadratic for long lines.
2017-11-04 22:43:53 +01:00
Nikita Popov
9b6a2577fa
FPPP: Convert some checks to assertions
...
Don't just silently fall back if we receive illegal input.
2017-11-04 18:14:12 +01:00
Nikita Popov
457fe049a8
Ensure nodes have full complement of location info
2017-11-04 18:13:00 +01:00
Nikita Popov
6a2e1ae440
FPPP: Graceful handling of comment changes
2017-11-04 17:56:11 +01:00
Nikita Popov
47c973b3aa
Store start token position in comments
2017-11-04 17:45:14 +01:00
Nikita Popov
56bc8ebb9b
FPPP: Add support for removal from list nodes
2017-11-04 17:23:17 +01:00