Commit Graph

476 Commits

Author SHA1 Message Date
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