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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
328 commits
Select commit Hold shift + click to select a range
59351ce
Add license to FilePositionMapTest.php
roblourens Feb 14, 2018
0360257
Fixes #188: Fix parsing empty variables
TysonAndre Feb 16, 2018
8ed14c2
Fix bugs and docs of FilePositionMap
TysonAndre Feb 16, 2018
1bfbd22
Merge pull request #233 from TysonAndre/fix-empty-var
roblourens Feb 19, 2018
dab357f
Fixes #224: Use DIRECTORY_SEPARATOR instead
TysonAndre Feb 19, 2018
ca23cef
Rename unused method to getEndLineCharacterPosition
TysonAndre Feb 19, 2018
3040143
Merge pull request #234 from TysonAndre/fix-FilePositionMap
roblourens Feb 19, 2018
faca5af
Merge pull request #235 from TysonAndre/fix-backslashes-unix
roblourens Feb 19, 2018
816ec34
Fixes #189 : Fix parsing edge cases in yield statements
TysonAndre Feb 16, 2018
4bdd48c
Remove unused use statements
TysonAndre Mar 3, 2018
2034b5d
Merge pull request #238 from TysonAndre/remove-unused-use-statement
roblourens Mar 6, 2018
c8e0671
Remove unused TemplateExpression
roblourens Mar 6, 2018
90dc39f
Merge pull request #232 from TysonAndre/fix-empty-yield
roblourens Mar 18, 2018
694b153
Merge pull request #228 from TysonAndre/fix-unary-lhs-binary
roblourens Mar 18, 2018
eca2848
Typo on #162 & 283
kant Mar 18, 2018
967243e
Merge pull request #239 from kant/patch-1
roblourens Mar 18, 2018
6d0ebb1
Update Mac OS PHP installation instructions
MarTango Apr 14, 2018
3811d27
Merge pull request #241 from MarTango/martango/update-mac-installatio…
roblourens Apr 15, 2018
7d369c2
Fixed docblock
dantleech Apr 22, 2018
31cffdb
Merge pull request #242 from dantleech/at_position_not_return_null
roblourens Apr 22, 2018
f297043
Fixes #190: `insteadof` should be able to accept a name list
TysonAndre May 12, 2018
797f795
Make remainingTargetNames consistent, avoid php notice
TysonAndre May 12, 2018
7647b60
Merge pull request #243 from TysonAndre/fix-trait-list
roblourens May 12, 2018
59b37a8
Fixes #103: Support parsing multiple exception types
TysonAndre May 12, 2018
60d3fc5
Add a missing file
TysonAndre May 12, 2018
01479d7
Merge pull request #244 from TysonAndre/multi-class-catch
roblourens May 26, 2018
80071b4
Work on properly parsing the expression lists passed to `<?=`
TysonAndre May 12, 2018
bce97ae
Merge pull request #245 from TysonAndre/fix-short-echo
roblourens Jun 11, 2018
f3fcb1f
Fix notices seen in PHP 7.3.0alpha4
TysonAndre Jul 20, 2018
5123f9c
Merge pull request #250 from TysonAndre/fix-php7.3.0alpha4
roblourens Jul 23, 2018
fc3373c
Added missing string return type for QualfiedName#getResolvedName
dantleech Jul 27, 2018
58814f1
Merge pull request #251 from dantleech/qualified_name_string_return
roblourens Jul 27, 2018
1bf3dbb
Added PHPStan dep
dantleech Jul 28, 2018
531d8bd
Added missing CHILD_NAMES constant from abstract class
dantleech Jul 28, 2018
c28b34b
Removed reference to potentially undefined variable
dantleech Jul 28, 2018
7e57c19
Ignore false-positives from PHPStan
dantleech Jul 28, 2018
602fb52
Set parent property type on namespace definition
dantleech Jul 28, 2018
1362730
Added param type hint
dantleech Jul 28, 2018
2932721
Added doc-block type hints
dantleech Jul 28, 2018
0ab36a5
Only set byRegToken on AssignmentExpression
dantleech Jul 28, 2018
77043f0
Removed docblock type hints and added real type hints
dantleech Jul 28, 2018
7f0d68b
Fixed type hint and added PHPStan to travis
dantleech Jul 28, 2018
91452da
Made phpstan a dev dep
dantleech Jul 28, 2018
9144a77
Conditionally execute PHPStan
dantleech Jul 28, 2018
6b5e32d
Removed hard dependency on phpstan
dantleech Jul 28, 2018
d3e28a7
Fix parsing of edge case involving inline HTML
TysonAndre Jul 28, 2018
e88881b
Merge pull request #252 from dantleech/phpstan
roblourens Aug 2, 2018
89ade27
Merge pull request #253 from TysonAndre/fix-inline-html-edge-case
roblourens Aug 7, 2018
4155326
Fix a notice in Parser->parseTernaryExpression()
TysonAndre Sep 2, 2018
ed2aaa1
Merge pull request #258 from TysonAndre/fix-ternary-notice
roblourens Sep 3, 2018
40d1b6e
Fix typos
TysonAndre Sep 9, 2018
7ea7734
Merge pull request #259 from TysonAndre/fix-typo
roblourens Sep 10, 2018
9463cfc
Fix a PHP notice generating a scoped property access expression
TysonAndre Sep 23, 2018
c9a8793
Only allow parsing unset() as a top-level statement
TysonAndre Sep 24, 2018
4580d0e
Merge pull request #261 from TysonAndre/unset-not-subexpression
roblourens Sep 26, 2018
54a84f1
Merge pull request #260 from TysonAndre/fix-trait-use-notice
roblourens Sep 26, 2018
88c0fd8
Test against (upcoming) PHP 7.3 on Travis
WyriHaximus Oct 30, 2018
3b098b3
Ignore phpenv error when xdebug.ini doesn't exists
WyriHaximus Oct 30, 2018
0818b70
Merge pull request #263 from WyriHaximus/patch-1
roblourens Oct 30, 2018
57e84c0
Move PHPStan configuration to its file
carusogabriel Oct 31, 2018
b20df05
Use in_array instead of array_search + comparison
carusogabriel Oct 31, 2018
9f13272
Merge pull request #264 from carusogabriel/phpstan-file
roblourens Oct 31, 2018
a266248
Merge pull request #265 from carusogabriel/in_array
roblourens Oct 31, 2018
c64dbb2
Bug fixes for parsing associativity
TysonAndre Dec 5, 2018
b662587
Merge pull request #268 from TysonAndre/parsing-precedence-fixes
roblourens Dec 29, 2018
4058fa7
Fix typo, remove unused 'use' statement
TysonAndre Feb 8, 2019
9d7f8ae
Implement support for parsing php 7.4 typed properties
TysonAndre Feb 8, 2019
aeaf4f8
Use fully qualified substr in Token.php
TysonAndre Feb 10, 2019
db476e9
Merge pull request #278 from TysonAndre/parse-property-declaration
roblourens Feb 17, 2019
c2d332e
Merge pull request #280 from TysonAndre/patch-1
roblourens Feb 17, 2019
2676462
Merge pull request #279 from TysonAndre/misc-nits
roblourens Feb 17, 2019
f74cd0c
Support parsing `??=` (only supports php 7.4)
TysonAndre Feb 18, 2019
2c62c5c
Add micro-optimizations
TysonAndre Feb 23, 2019
d3e6a0e
Merge pull request #283 from TysonAndre/micro-optimize
roblourens Feb 24, 2019
27aec73
Merge pull request #281 from TysonAndre/questionquestionequals
roblourens Feb 24, 2019
9917efe
Annotate the types on Token
TysonAndre Mar 8, 2019
97bc57e
Merge pull request #284 from TysonAndre/annotate-token-type
roblourens Mar 9, 2019
0a96f2e
Properly parse @$x += $y as @($x += $y)
TysonAndre Feb 23, 2019
89386de
Merge pull request #282 from TysonAndre/force-assignment-expression
roblourens Mar 9, 2019
b1377e2
Minor optimizations to Parser
TysonAndre Mar 10, 2019
51b16ef
Merge pull request #286 from TysonAndre/parse-optimize
roblourens Mar 11, 2019
23cdc01
Optimizations to PhpTokenizer
TysonAndre Mar 10, 2019
ffeaf03
Fix #288
roblourens Mar 14, 2019
77cc4df
Fix a typo in a variable name
TysonAndre Mar 25, 2019
8e6d4a3
Merge pull request #287 from TysonAndre/optimize-tokenizing
roblourens Mar 25, 2019
c74eb57
Merge pull request #289 from TysonAndre/fix-typo-var
roblourens Mar 25, 2019
2836a80
Support parsing PHP 7.4's arrow functions
TysonAndre May 12, 2019
3f4f381
Support the array spread operator
TysonAndre May 20, 2019
d0786c4
Fix namespace expression usage in arg list
TysonAndre Jun 11, 2019
5457e82
Merge pull request #293 from TysonAndre/parse-arrow-function
roblourens Jul 1, 2019
0cf8b84
Merge pull request #294 from TysonAndre/arrow-spread-operator
roblourens Jul 1, 2019
e255aa9
Merge pull request #295 from TysonAndre/fix-namespace-expr-in-arglist
roblourens Jul 1, 2019
75189fd
Fix associativity of ternary operation parsing
TysonAndre Jul 28, 2019
ff5dda4
Merge pull request #298 from TysonAndre/fix-ternary-precedence
roblourens Aug 2, 2019
0b8d1b7
Support php 8.0 union types for param/property/return
TysonAndre-tmg Nov 9, 2019
c4a9d19
Fix bug, add tests for php 7.4 short arrow functions
TysonAndre-tmg Nov 17, 2019
6c701e3
Merge pull request #303 from TysonAndre/parse-union-type
roblourens Nov 19, 2019
1a9118b
Add more modifier checks to MethodDeclaration node
inxilpro Dec 28, 2019
e88ad9b
Merge pull request #306 from inxilpro/MethodDeclarationModifierGetters
roblourens Jan 2, 2020
63314e3
Simplify change from #306 to avoid confusion
roblourens Jan 2, 2020
635d0ba
Fix statement order when there are multiple Inline HTML
ngyuki Jan 30, 2020
b407b9d
Merge pull request #308 from ngyuki/fixes-307
roblourens Jan 30, 2020
a2f014b
Fix validation errors
roblourens Jan 30, 2020
e8c3d19
Fix validation error
roblourens Jan 30, 2020
83d8b91
Fix InlineHtml in control structures
ngyuki Jan 30, 2020
29c7430
Merge pull request #310 from ngyuki/fix-inline-html-in-control-struct…
roblourens Jan 31, 2020
46204f1
Properly handle failure to parse right side of binary operations
TysonAndre-tmg Feb 6, 2020
2bcc533
Merge pull request #311 from TysonAndre/fix-fuzz-static
roblourens Feb 7, 2020
fda7e17
Remove extra parens
roblourens Feb 7, 2020
a1cbc19
Fix parsing of static return types
TysonAndre-tmg Feb 15, 2020
8eebdbe
Merge pull request #313 from TysonAndre/fix-static-return
roblourens Feb 17, 2020
c9fb699
Support parsing `new (call_function())()`
TysonAndre Feb 15, 2020
c5e2bf5
Merge pull request #314 from TysonAndre/object-creation-parens
roblourens Feb 18, 2020
6f9d25b
Add a way to override the lexer in a Parser instance
TysonAndre Mar 3, 2020
824775d
Test in Travis with php 7.4
TysonAndre-tmg Sep 11, 2019
90b1fed
Support using `throw` as an expression
TysonAndre Apr 11, 2020
f65ad0c
Remove TODO for trailing comma in parameter list
TysonAndre Apr 18, 2020
8786bf0
Merge pull request #319 from TysonAndre/trailing_comma
roblourens Apr 18, 2020
0decf16
GettingStarted: Update composer instructions
yanmii-is May 4, 2020
daa2368
GettingStarted: Update instructions to PHP 7.2
yanmii-is May 4, 2020
e5c91d8
Merge pull request #321 from yanmii-is/master
roblourens May 5, 2020
f03a55c
Support parsing php 8.0's non-capturing catch statement
TysonAndre May 26, 2020
14f0fbc
Merge pull request #322 from TysonAndre/noncapturing-catch
roblourens May 27, 2020
69358e2
Merge pull request #318 from TysonAndre/fix-throw
roblourens May 27, 2020
0c858c9
Merge pull request #299 from TysonAndre/fix-php74-parse
roblourens May 27, 2020
45d447e
Support php 8.0 constructor property promotion
TysonAndre Jun 14, 2020
22f7813
Add missing file
TysonAndre Jun 14, 2020
2096712
Merge pull request #324 from TysonAndre/parameter-promotion
roblourens Jun 15, 2020
2e5f566
Warn about missing use variable
TysonAndre Jul 2, 2020
f0b68cd
Merge pull request #325 from TysonAndre/missing-variable
roblourens Jul 2, 2020
67f09de
Support match expression v2 RFC
TysonAndre Jul 4, 2020
e813b45
Merge pull request #326 from TysonAndre/match-expression
roblourens Jul 12, 2020
b4f5f2c
Merge pull request #317 from TysonAndre/token_get_all-override
roblourens Jul 12, 2020
9bb043e
Support php 8.0's "Treat namespaced names as single token"
TysonAndre Aug 2, 2020
2c63e8a
Support php 8.0's nullsafe operator
TysonAndre Aug 2, 2020
be9cfce
Merge pull request #331 from TysonAndre/relative-token
roblourens Aug 7, 2020
98fbbd2
Adding declare directive list support
Aug 7, 2020
ceb5125
Adding test case for simple list
Aug 7, 2020
63cf35a
Updating existing test structures
Aug 7, 2020
b1e2ec0
:lipstick:
Aug 7, 2020
a562154
Fixing start tag length by including whitespace tokens
Aug 7, 2020
869dc7f
Support parsing php 8.0 named arguments
TysonAndre Aug 8, 2020
3fdca6b
Merge pull request #335 from TysonAndre/named-arguments-
roblourens Aug 8, 2020
ec691a0
Making changes backwards compatible
Aug 10, 2020
6b07add
Refactoring modified type behaviors
Aug 10, 2020
8bb0959
Merge pull request #333 from PythooonUser/issue-178
roblourens Aug 23, 2020
52e792a
Merge pull request #337 from PythooonUser/helper-function-on-modified…
roblourens Aug 23, 2020
3a174a9
Add support for php 8.0 `#[` attribute groups
TysonAndre Aug 19, 2020
673bacf
Improve the lookahead check for attributes on expressions
TysonAndre Sep 6, 2020
917e065
Merge pull request #341 from TysonAndre/attributes-group
roblourens Sep 10, 2020
4e9127c
Also handle `new #[MyAttr] class {...}`
TysonAndre Sep 11, 2020
6d546ce
Support attributes on traits and interfaces
TysonAndre Sep 11, 2020
ba3805b
Fix infinite loop parsing `trait #[`
TysonAndre Sep 12, 2020
494acd8
Start running tests in travis with nightly
TysonAndre Sep 12, 2020
c91c8a1
Merge pull request #342 from TysonAndre/anonymous-class-attributes
roblourens Sep 12, 2020
85b40c3
Merge pull request #344 from TysonAndre/travis-nightly
roblourens Sep 12, 2020
42ddd21
Fix handling of named label for goto.
TysonAndre Sep 13, 2020
0c991bc
Warn about #[] attribute groups of 0 length
TysonAndre Sep 13, 2020
b5c7cd4
Merge pull request #346 from TysonAndre/attribute-group-missing-error
roblourens Sep 13, 2020
1d76657
Merge pull request #345 from TysonAndre/goto-empty
roblourens Sep 13, 2020
8430e6d
iterable is now a token instead of a Name
camilledejoye Nov 7, 2020
f2ec9ea
Merge pull request #348 from camilledejoye/fix/#191-iterable-as-token
roblourens Nov 28, 2020
acdfa57
Add support for PHP 8.0 mixed type
dantleech Dec 23, 2020
b08e0d5
PHPStan no longer reports this error
dantleech Dec 23, 2020
55436ce
Deprecate IterableKeyword in favor of IterableReservedWord
dantleech Dec 23, 2020
0034e81
Update src/TokenKind.php
dantleech Dec 23, 2020
e5ebee7
Use 340 for mixed reserved word
dantleech Dec 23, 2020
a38e03b
Merge pull request #350 from dantleech/mixed-reserved-word
roblourens Dec 30, 2020
b476ac7
Support testing with phpunit 7 as well
TysonAndre Jul 26, 2020
5bfe9fd
Support parsing PHP 8.1 enums
TysonAndre Mar 27, 2021
dccc6f2
Merge pull request #328 from TysonAndre/update-composer
roblourens Mar 30, 2021
35646d5
Merge pull request #352 from TysonAndre/enum-support
roblourens Mar 30, 2021
2a48939
[WIP] v1.0.0 proposal
TysonAndre Jul 26, 2020
465d02f
v0.1.0: Raise minimum php version, change some AST representations
TysonAndre Dec 15, 2020
0b40640
Refactor to use getStartPosition
TysonAndre Apr 29, 2021
5df29ef
Convert array()/list() to short array `[]` with phpcbf
TysonAndre Apr 29, 2021
56f2603
Support php 8.1
TysonAndre Jun 4, 2021
769b9d9
Merge pull request #349 from TysonAndre/v1-refactor
roblourens Jun 11, 2021
8fd46ab
Adding source file node check
Jun 22, 2021
9067f71
Support parsing PHP 8.1 intersection types
TysonAndre Jun 4, 2021
69f23ca
Merge pull request #355 from PythooonUser/feature/issue-225
roblourens Jul 12, 2021
03f8cab
Merge pull request #356 from TysonAndre/intersection-type-support
roblourens Jul 16, 2021
e0814a0
Support readonly property modifier
TysonAndre Jul 9, 2021
0faf367
Support proposed first-class callable syntax
TysonAndre Jul 10, 2021
190ebc0
Clarify why multiple modifiers can be parsed. Fix conflicts.
TysonAndre Jul 16, 2021
78a7744
Remove comment indicating unsupported modifiers
TysonAndre Jul 16, 2021
6a96561
Merge pull request #357 from TysonAndre/readonly-properties
roblourens Jul 16, 2021
e0d0880
Fix regression after supporting intersection types
TysonAndre Jul 20, 2021
4f5a6ea
Merge pull request #358 from TysonAndre/fix-delimiter-edge-case
roblourens Jul 21, 2021
5f5c958
fix: Download the VSIX URL
ishan-deepsource Sep 16, 2021
2e3999f
Merge pull request #359 from ishan-deepsource/patch-1
roblourens Sep 16, 2021
cbbaba1
Fix parsing of `a ? a ? a : b : b`
TysonAndre Oct 8, 2021
af2ff38
Merge pull request #361 from TysonAndre/fix-delimiter-edge-case
roblourens Oct 12, 2021
c11175a
Fix PHP 8.2 deprecation notices in tolerant-php-parser
TysonAndre Nov 27, 2021
12db2d7
Merge pull request #363 from TysonAndre/fix-deprecation
roblourens Nov 29, 2021
adf34be
callableExpression can also be a QualifiedName...
dantleech Jan 1, 2022
f4f5e93
Merge pull request #364 from dantleech/callable_function
roblourens Jan 4, 2022
477b358
fix: add match to keywords
zobo Jun 24, 2022
ecc2be1
Merge pull request #366 from zobo/fix-match-keyword
roblourens Jun 24, 2022
2ba725b
Support PHP 8.2 features
TysonAndre Aug 9, 2022
db0840e
Update test expectations, test readonly class
TysonAndre Aug 9, 2022
17a63a0
Add tests of php 8.2 constants in traits
TysonAndre Aug 9, 2022
7ff8145
Support php 8.2 true type
TysonAndre Aug 9, 2022
af944a3
Remove a TODO that no longer applies in php 8.0
TysonAndre Aug 10, 2022
f08d133
Start testing in php 8.1 in travis
TysonAndre Aug 11, 2022
a2f34af
Merge pull request #369 from TysonAndre/remove-todo-230
roblourens Aug 18, 2022
e42180c
Merge pull request #371 from TysonAndre/test-8.1-travis
roblourens Aug 18, 2022
9bf6637
Merge pull request #368 from TysonAndre/php8.2-features
roblourens Aug 18, 2022
6a89b5c
Set up github workflows for multiple php versions
TysonAndre Aug 10, 2022
dd25257
Add .sh extension to run_tests files
TysonAndre Aug 18, 2022
1261275
Merge pull request #370 from TysonAndre/test-8.1
roblourens Aug 23, 2022
18d7801
Support php 8.2 `A|(B&C)` dnf types
TysonAndre Aug 19, 2022
81790cd
Stricten error checking in parsing union types/intersection types
TysonAndre Aug 20, 2022
3b81f38
Fix parent node set when parsing union types
TysonAndre Aug 20, 2022
ca256f1
Remove inapplicable TODOs
TysonAndre Aug 20, 2022
c940402
Support php 'never' type, change parsing of 'void'
TysonAndre Aug 18, 2022
0d46605
Add test cases of void/never in parameter types
TysonAndre Aug 23, 2022
15362b1
Remove impossible check for empty list
TysonAndre Aug 23, 2022
49058c4
Merge pull request #374 from TysonAndre/support-never
roblourens Aug 25, 2022
a60544e
Merge pull request #375 from TysonAndre/8.2-union-of-intersection
roblourens Aug 25, 2022
ca842b4
Update example syntax-visualizer output to latest version
TysonAndre Aug 26, 2022
7e6cb20
Add MissingToken for missing QualifiedName
TysonAndre Aug 26, 2022
da1f15e
Speed up running the framework validation test suite
TysonAndre Aug 26, 2022
a036846
Support `__halt_compiler` statement
TysonAndre Aug 27, 2022
8e63602
Remove unused use statement
TysonAndre Sep 22, 2022
8ed21ce
Change getUri return type to nullable string
TysonAndre Sep 22, 2022
107ac4a
Use PHPDoc `@param string ...$classNames`
TysonAndre Sep 22, 2022
735ce08
Merge pull request #378 from TysonAndre/update-syntax-visualizer
roblourens Sep 25, 2022
9d9b602
Merge pull request #380 from TysonAndre/speed-up-validation-suite
roblourens Sep 25, 2022
6f49c64
Merge pull request #379 from TysonAndre/fix-base-clause
roblourens Sep 25, 2022
ba1f1e8
Merge pull request #382 from TysonAndre/halt-compiler-support
roblourens Sep 25, 2022
1016890
Merge pull request #383 from TysonAndre/source-file-node-nit
roblourens Sep 25, 2022
a35ec03
Merge pull request #384 from TysonAndre/classNames-nit
roblourens Sep 25, 2022
0145399
Update code to PHPStan Level 3
dantleech Sep 22, 2022
f0ed566
Ignore "should not happen" statement
dantleech Sep 28, 2022
5862e67
Bump to level 4
dantleech Sep 28, 2022
3401048
Remove !is_null conditional branch - it always returns Node
dantleech Sep 28, 2022
625b80b
NamespaceUseDeclaration#useClauses is technically nullable
dantleech Sep 28, 2022
5d2ebdb
NamespaceUseGroupCluase#functionOrConst can be NULL
dantleech Sep 28, 2022
f537ec2
Add TODO
dantleech Sep 28, 2022
ce28948
Removed redundant condition (check)
dantleech Sep 28, 2022
c9a1beb
Add return type
dantleech Sep 28, 2022
2bc6203
Add retutn type, remove inaccurate docblock
dantleech Sep 28, 2022
b040d5f
Fix bug with get string literal text, as it returned the quotes
dantleech Sep 28, 2022
f1baea2
Ignore assumed false-positive from PHPStan
dantleech Sep 28, 2022
c04ab69
If allowEmptyElements if `false`...
dantleech Sep 28, 2022
6700ef1
backslash can be NULL
dantleech Sep 28, 2022
e2904ed
BinaryExpresionOrHigher can return MIssingToken
dantleech Sep 28, 2022
7a6d982
Ignoring error to be safe (as commented) and more type hints
dantleech Sep 28, 2022
90da216
Set level to 4
dantleech Sep 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.git/
.github/
validation/
vendor/
docs/
tools/
**/.DS_Store
**/.idea
**/composer.lock
tests/output
.phpunit.result.cache
**/*.ast
**/.*.swp
**/.*.swo
**/Dockerfile
.dockerignore
23 changes: 17 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
/tests/*.php text eol=lf
/tests/cases/**/*.php text eol=lf

syntax-visualizer/ export-ignore
tests/ export-ignore
validation/ export-ignore
php-langspec/ export-ignore
experiments/ export-ignore
tools/ export-ignore
/.vscode export-ignore
/ci export-ignore
/docs export-ignore
/experiments export-ignore
/php-langspec export-ignore
/syntax-visualizer export-ignore
/tests export-ignore
/tools export-ignore
/validation export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.gitmodules export-ignore
/.travis.yml export-ignore
/Contributing.md export-ignore
/README.md export-ignore
/phpunit.xml export-ignore
/.dockerignore export-ignore
43 changes: 43 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Runs tolerant-php-parser's tests
name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-environment-variables-in-a-matrix
strategy:
fail-fast: false
matrix:
include:
# NOTE: If this is not quoted, the yaml parser will convert numbers such as 8.0 to the number 8,
# and the docker image `php:8` is the latest minor version of php 8.x (8.1).
- PHP_VERSION: '7.2'
- PHP_VERSION: '7.3'
- PHP_VERSION: '7.4'
- PHP_VERSION: '8.0'
- PHP_VERSION: '8.1'
- PHP_VERSION: '8.2.0beta2'

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Build and test in docker
run: bash ci/run_tests_dockerized.sh ${{ matrix.PHP_VERSION }}
Empty file added .github/workflows/phpstan.yml
Empty file.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
vendor/
composer.lock
tests/output
*.ast
*.ast
.*.swp
.*.swo
.phpunit.result.cache
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
language: php

php:
- 7.0
- 7.1
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'

env:
- VALIDATION=false
Expand All @@ -12,9 +15,10 @@ os:
- linux

matrix:
include:
- php: 7.2
env: STATIC_ANALYSIS=true
fast_finish: true
allow_failures:
- env: VALIDATION=true

cache:
directories:
Expand All @@ -23,12 +27,13 @@ cache:
before_script:
- composer install
- set -e # Stop on first error.
- phpenv config-rm xdebug.ini
- phpenv config-rm xdebug.ini || true
- if find . -name "*.php" -path "./src/*" -path "./experiments/*" -path "./tools/*" -path "./syntax-visualizer/server/src/*" -exec php -l {} 2>&1 \; | grep "syntax error, unexpected"; then exit 1; fi
- if find . -name "*.php" -path "./tests/*" -path "./validation/*" -maxdepth 0 --exec php -l {} 2>&1 \; | grep "syntax error, unexpected"; then exit 1; fi

script:
- composer validate
- if [[ $STATIC_ANALYSIS = true ]]; then ./vendor/bin/phpstan analyse; fi
- |
if [[ $VALIDATION = true ]]; then
./vendor/bin/phpunit --testsuite validation
Expand Down
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
[![Build Status](https://travis-ci.org/Microsoft/tolerant-php-parser.svg?branch=master)](https://travis-ci.org/Microsoft/tolerant-php-parser)

This is an early-stage PHP parser designed, from the beginning, for IDE usage scenarios (see [Design Goals](#design-goals) for more details). There is
still a ton of work to be done, so at this point, this repo mostly serves as
still a ton of work to be done, so at this point, this repo mostly serves as
an experiment and the start of a conversation.

![image](https://cloud.githubusercontent.com/assets/762848/19023070/4ab01c92-889a-11e6-9bb5-ec1a6816aba2.png)

This is the v0.1 branch, which changes data structures to support syntax added after the initial 0.0.x release line.

## Get Started
After you've [configured your machine](docs/GettingStarted.md), you can use the parser to generate and work
After you've [configured your machine](docs/GettingStarted.md), you can use the parser to generate and work
with the Abstract Syntax Tree (AST) via a friendly API.
```php
<?php
// Autoload required classes
require "vendor/autoload.php";
require __DIR__ . "/vendor/autoload.php";

use Microsoft\PhpParser\{DiagnosticsProvider, Node, Parser, PositionUtilities};

Expand All @@ -27,7 +29,7 @@ var_dump($astNode);
// Gets and prints errors from AST Node. The parser handles errors gracefully,
// so it can be used in IDE usage scenarios (where code is often incomplete).
$errors = DiagnosticsProvider::getDiagnostics($astNode);
var_dump(iterator_to_array($errors));
var_dump($errors);

// Traverse all Node descendants of $astNode
foreach ($astNode->getDescendantNodes() as $descendant) {
Expand All @@ -38,17 +40,17 @@ foreach ($astNode->getDescendantNodes() as $descendant) {
// All Nodes link back to their parents, so it's easy to navigate the tree.
$grandParent = $descendant->getParent()->getParent();
var_dump($grandParent->getNodeKindName());

// The AST is fully-representative, and round-trippable to the original source.
// This enables consumers to build reliable formatting and refactoring tools.
var_dump($grandParent->getLeadingCommentAndWhitespaceText());
}

// In addition to retrieving all children or descendants of a Node,
// Nodes expose properties specific to the Node type.
if ($descendant instanceof Node\Expression\EchoExpression) {
$echoKeywordStartPosition = $descendant->echoKeyword->getStartPosition();
// To cut down on memory consumption, positions are represented as a single integer
// To cut down on memory consumption, positions are represented as a single integer
// index into the document, but their line and character positions are easily retrieved.
$lineCharacterPosition = PositionUtilities::getLineCharacterPositionFromPosition(
$echoKeywordStartPosition,
Expand All @@ -59,15 +61,15 @@ foreach ($astNode->getDescendantNodes() as $descendant) {
}
```

> Note: [the API](docs/ApiDocumentation.md) is not yet finalized, so please file issues let us know what functionality you want exposed,
> Note: [the API](docs/ApiDocumentation.md) is not yet finalized, so please file issues let us know what functionality you want exposed,
and we'll see what we can do! Also please file any bugs with unexpected behavior in the parse tree. We're still
in our early stages, and any feedback you have is much appreciated :smiley:.

## Design Goals
* Error tolerant design - in IDE scenarios, code is, by definition, incomplete. In the case that invalid code is entered, the
parser should still be able to recover and produce a valid + complete tree, as well as relevant diagnostics.
parser should still be able to recover and produce a valid + complete tree, as well as relevant diagnostics.
* Fast and lightweight (should be able to parse several MB of source code per second,
to leave room for other features).
to leave room for other features).
* Memory-efficient data structures
* Allow for incremental parsing in the future
* Adheres to [PHP language spec](https://github.com/php/php-langspec),
Expand All @@ -83,34 +85,34 @@ so each language server operation should be < 50 ms to leave room for all the
confusing, really fast, so readability and debug-ability is high priority.
* Testable - the parser should produce provably valid parse trees. We achieve this by defining and continuously testing
a set of invariants about the tree.
* Friendly and descriptive API to make it easy for others to build on.
* Friendly and descriptive API to make it easy for others to build on.
* Written in PHP - make it as easy as possible for the PHP community to consume and contribute.

## Current Status and Approach
To ensure a sufficient level of correctness at every step of the way, the
parser is being developed using the following incremental approach:

* [x] **Phase 1:** Write lexer that does not support PHP grammar, but supports EOF
* [x] **Phase 1:** Write lexer that does not support PHP grammar, but supports EOF
and Unknown tokens. Write tests for all invariants.
* [x] **Phase 2:** Support PHP lexical grammar, lots of tests
* [x] **Phase 3:** Write a parser that does not support PHP grammar, but produces tree of
* [x] **Phase 3:** Write a parser that does not support PHP grammar, but produces tree of
Error Nodes. Write tests for all invariants.
* [x] **Phase 4:** Support PHP syntactic grammar, lots of tests
* [ ] **Phase 5 (in progress :running:):** Real-world validation and optimization
* [ ] _**Correctness:**_ validate that there are no errors produced on sample codebases, benchmark against other parsers (investigate any instance of disagreement), fuzz-testing
* [ ] _**Performance:**_ profile, benchmark against large PHP applications
* [ ] **Phase 6:** Finalize API to make it as easy as possible for people to consume.
* [ ] **Phase 6:** Finalize API to make it as easy as possible for people to consume.

### Additional notes
A few of the PHP grammatical constructs (namely yield-expression, and template strings)
are not yet supported and there are also other miscellaneous bugs. However, because the parser is error-tolerant,
these errors are handled gracefully, and the resulting tree is otherwise complete. To get a more holistic sense for
where we are, you can run the "validation" test suite (see [Contributing Guidelines](Contributing.md) for more info
where we are, you can run the "validation" test suite (see [Contributing Guidelines](Contributing.md) for more info
on running tests). Or simply, take a look at the current [validation test results](https://travis-ci.org/Microsoft/tolerant-php-parser).

Even though we haven't yet begun the performance optimization stage, we have seen promising results so far,
and have plenty more room for improvement. See [How It Works](docs/HowItWorks.md) for details on our current
approach, and run the [Performance Tests](Contributing.md#running-performance-tests) on your
Even though we haven't yet begun the performance optimization stage, we have seen promising results so far,
and have plenty more room for improvement. See [How It Works](docs/HowItWorks.md) for details on our current
approach, and run the [Performance Tests](Contributing.md#running-performance-tests) on your
own machine to see for yourself.

## Learn more
Expand All @@ -119,7 +121,7 @@ own machine to see for yourself.
**:book: [Documentation](docs/GettingStarted.md#getting-started)** - learn how to reference the parser from your project, and how to perform
operations on the AST to answer questions about your code.

**:eyes: [Syntax Visualizer Tool](syntax-visualizer/client#php-parser-syntax-visualizer-tool)** - get a more tangible feel for the AST. Get creative - see if you can break it!
**:eyes: [Syntax Visualizer Tool](syntax-visualizer/client#php-parser-syntax-visualizer-tool)** - get a more tangible feel for the AST. Get creative - see if you can break it!

**:chart_with_upwards_trend: [Current Status and Approach](#current-status-and-approach)** - how much of the grammar is supported? Performance? Memory? API stability?

Expand All @@ -131,10 +133,10 @@ operations on the AST to answer questions about your code.
* [Validation Strategy](docs/HowItWorks.md#validation-strategy)

**:sparkling_heart: [Contribute!](Contributing.md)** - learn how to get involved, check out some pointers to educational commits that'll
help you ramp up on the codebase (even if you've never worked on a parser before),
help you ramp up on the codebase (even if you've never worked on a parser before),
and recommended workflows that make it easier to iterate.

---
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact
[[email protected]](mailto:[email protected]) with any additional questions or comments.
12 changes: 12 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG PHP_VERSION
FROM php:$PHP_VERSION
RUN curl https://getcomposer.org/download/latest-2.x/composer.phar -o /usr/bin/composer.phar && chmod a+x /usr/bin/composer.phar
WORKDIR /tolerant-php-parser
RUN apt-get update && apt-get install -y unzip && apt-get clean
ARG COMPOSER_OPTIONS
ENV COMPOSER_OPTIONS=$COMPOSER_OPTIONS

ADD composer.json ./
RUN composer.phar install $COMPOSER_OPTIONS && composer.phar clear-cache

ADD . .
9 changes: 9 additions & 0 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# This runs the tests that have been set up in GitHub Workflows so far

# -x Exit immediately if any command fails
# -e Echo all commands being executed.
set -xe
php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite invariants
php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite grammar
php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite api
22 changes: 22 additions & 0 deletions ci/run_tests_dockerized.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
if [ $# != 1 ]; then
echo "Usage: $0 PHP_VERSION" 1>&2
echo "e.g. $0 8.0" 1>&2
echo "The PHP_VERSION is the version of the php docker image to use" 1>&2
echo "This runs the tests that have been set up in GitHub Workflows so far" 1>&2
exit 1
fi
# -x Exit immediately if any command fails
# -e Echo all commands being executed.
# -u fail for undefined variables
set -xeu
PHP_VERSION=$1
COMPOSER_OPTIONS=""
# lexicographic comparison
if [ "$PHP_VERSION" > "8.1" ]; then
COMPOSER_OPTIONS="--ignore-platform-reqs"
fi

DOCKER_IMAGE="tolerant-php-parser-test-runner:$PHP_VERSION"
docker build --build-arg="PHP_VERSION=$PHP_VERSION" --build-arg="COMPOSER_OPTIONS=$COMPOSER_OPTIONS" --tag="$DOCKER_IMAGE" -f ci/Dockerfile .
docker run --rm $DOCKER_IMAGE ci/run_tests.sh
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"description": "Tolerant PHP-to-AST parser designed for IDE usage scenarios",
"type": "library",
"require": {
"php": ">=7.0"
"php": ">=7.2"
},
"require-dev": {
"phpunit/phpunit": "^5.5"
"phpunit/phpunit": "^8.5.15",
"phpstan/phpstan": "^1.8"
},
"license": "MIT",
"authors": [
Expand All @@ -17,5 +18,8 @@
],
"autoload": {
"psr-4": { "Microsoft\\PhpParser\\": ["src/"] }
},
"autoload-dev": {
"psr-4": { "Microsoft\\PhpParser\\Tests\\Unit\\": ["tests/unit/"] }
}
}
14 changes: 7 additions & 7 deletions docs/ApiDocumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
```php
public function getNodeKindName ( ) : string
```
### Node::getStart
### Node::getStartPosition
Gets start position of Node, not including leading comments and whitespace.
```php
public function getStart ( ) : int
public function getStartPosition ( ) : int
```
### Node::getFullStart
### Node::getFullStartPosition
Gets start position of Node, including leading comments and whitespace
```php
public function getFullStart ( ) : int
public function getFullStartPosition ( ) : int
```
### Node::getParent
Gets parent of current node (returns null if has no parent)
Expand Down Expand Up @@ -198,11 +198,11 @@ public function getFullText ( string & $document ) : string
```php
public function getStartPosition ( )
```
### Token::getFullStart
### Token::getFullStartPosition
> TODO: add doc comment

```php
public function getFullStart ( )
public function getFullStartPosition ( )
```
### Token::getWidth
> TODO: add doc comment
Expand All @@ -226,7 +226,7 @@ public function getEndPosition ( )
> TODO: add doc comment

```php
public static function getTokenKindNameFromValue ( $kindName )
public static function getTokenKindNameFromValue ( $kind )
```
### Token::jsonSerialize
> TODO: add doc comment
Expand Down
Loading