Add optional cpg-language-php module with a minimal PHP frontend#2747
Add optional cpg-language-php module with a minimal PHP frontend#2747Copilot wants to merge 18 commits into
cpg-language-php module with a minimal PHP frontend#2747Conversation
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/25ca3113-0e91-4a1c-80c1-e2efb1fd27bb Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/25ca3113-0e91-4a1c-80c1-e2efb1fd27bb Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/25ca3113-0e91-4a1c-80c1-e2efb1fd27bb Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/25ca3113-0e91-4a1c-80c1-e2efb1fd27bb Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/e7cddaf1-8462-427a-9702-a9a965e38e05 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/c3f99ec1-26fe-495c-b7f5-a81c21f3add2 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/96191110-fddd-4a87-b33f-abced158bc57 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/96191110-fddd-4a87-b33f-abced158bc57 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/4b3a7d33-ed55-4bd7-904a-d52336a6b640 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
|
@copilot please check why tests are failing |
I checked the failing CI run and reproduced it: the failure is dependency resolution in Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/414d7511-de09-430c-a667-085e2370ab59 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
|
@copilot can we try to add some more test for the patch coverage? please keep it "themed", e.g. functions, classes, etc. don't add "patch coverage tests" |
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/e531dcac-585e-4dfd-bfc0-484cd6907243 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Added themed test coverage for functions/classes in commit Specifically, I extended the existing PHP fixtures and assertions with:
These run successfully with |
There was a problem hiding this comment.
Pull request overview
This PR introduces an optional PHP language frontend (cpg-language-php) and wires it into the existing “optional frontend” enablement mechanism so that PHP support can be included on demand without affecting default builds.
Changes:
- Adds the new
:cpg-language-phpmodule with an ANTLR-based minimal PHP 8 frontend plus basic unit tests and fixtures. - Extends the frontend enablement toggles (
enablePHPFrontend) and hooks PHP language registration into downstream entrypoints (Codyze, MCP, Neo4j app, console service). - Updates documentation to list PHP as an experimental language and updates the Codyze Console webapp README to use pnpm commands.
Reviewed changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| settings.gradle.kts | Adds enablePHPFrontend flag and conditionally includes :cpg-language-php. |
| build.gradle.kts | Logs PHP frontend enablement similarly to other frontends. |
| buildSrc/src/main/kotlin/cpg.frontend-dependency-conventions.gradle.kts | Adds conditional dependency on :cpg-language-php when enabled. |
| gradle.properties.example | Documents the new enablePHPFrontend toggle. |
| configure_frontends.sh | Adds interactive configuration prompt for the PHP frontend. |
| gradle/libs.versions.toml | Adds ANTLR entries to the version catalog (reviewed for consistency with the PR’s ANTLR goal). |
| README.md | Updates supported languages list/table to include PHP. |
| cpg-language-php/build.gradle.kts | New module build file with ANTLR generation + runtime deps. |
| cpg-language-php/src/main/antlr/PhpLexer.g4 | Adds PHP lexer grammar (from grammars-v4) for code parsing. |
| cpg-language-php/src/main/antlr/PhpParser.g4 | Adds PHP parser grammar (from grammars-v4) for code parsing. |
| cpg-language-php/src/main/java/.../PhpLexerBase.java | Lexer base support for mode transitions / heredoc etc. |
| cpg-language-php/src/main/kotlin/.../PHPLanguage.kt | Defines the PHP language model (extensions, built-in types, operators). |
| cpg-language-php/src/main/kotlin/.../PHPLanguageFrontend.kt | Implements parsing and TU construction for PHP sources. |
| cpg-language-php/src/main/kotlin/.../PHPHandler.kt | Base handler abstraction for PHP ANTLR contexts. |
| cpg-language-php/src/main/kotlin/.../DeclarationHandler.kt | Models PHP declarations (functions/classes/namespaces/params). |
| cpg-language-php/src/main/kotlin/.../ExpressionHandler.kt | Models PHP expressions (calls, literals, operators, etc.). |
| cpg-language-php/src/main/kotlin/.../StatementHandler.kt | Models PHP statements (blocks, loops, if, switch, try/catch, etc.). |
| cpg-language-php/src/main/kotlin/.../CaseChangingCharStream.kt | CharStream wrapper to support case-insensitive lexing. |
| cpg-language-php/src/test/kotlin/.../PHPLanguageFrontendTest.kt | Adds basic unit tests for PHP functions/classes/statements parsing. |
| cpg-language-php/src/test/resources/php/functions.php | Test fixture for PHP functions. |
| cpg-language-php/src/test/resources/php/classes.php | Test fixture for PHP namespaces/classes/methods. |
| cpg-language-php/src/test/resources/php/statements.php | Test fixture for representative PHP statements. |
| cpg-neo4j/.../Application.kt | Registers PHP as an optional language for the Neo4j visualization app. |
| cpg-mcp/.../SetupConfig.kt | Registers PHP as an optional language for MCP setup. |
| codyze-core/.../Project.kt | Registers PHP as an optional language for Codyze analysis projects. |
| codyze-core/.../dsl/Dsl.kt | Registers PHP as an optional language for DSL-created projects. |
| codyze-console/.../ConsoleService.kt | Registers PHP as an optional language for the console backend translation config. |
| codyze-console/src/main/webapp/README.md | Updates dev/build instructions to pnpm-based commands. |
Comments suppressed due to low confidence (2)
cpg-language-php/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/php/DeclarationHandler.kt:162
- Method return types declared as
:?typewill lose the nullable marker because onlyreturnTypeDecl().typeHint().textis passed intofrontend.typeOf(...)(the leading?is a separate token). If you wanttypeOfto treat nullable types differently (it currently checks for?), include theQuestionMarktoken when constructing the type string here.
ctx.returnTypeDecl()?.typeHint()?.let {
method.returnTypes = listOf(frontend.typeOf(it.text))
}
cpg-language-php/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/php/DeclarationHandler.kt:210
- Nullable parameter types (
?T $x) are not represented correctly: the nullable marker is a separate?token in the grammar, buthandleFormalParameterpasses onlyctx.typeHint().texttofrontend.typeOf(...). This means?Twill currently be treated asT(andtypeOf'scontains("?")branch is never reached). Consider prepending?whenctx.QuestionMark()is present (or explicitly modeling nullability if supported).
val rawName = varInit?.VarName()?.text ?: ""
val name = rawName.removePrefix("$")
val isVariadic = ctx.children?.any { it.text == "..." } == true
val type = ctx.typeHint()?.let { frontend.typeOf(it.text) } ?: autoType()
val param = newParameter(name, type, variadic = isVariadic, rawNode = ctx)
|
@copilot fix code review suggestions |
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/80f56e48-5cbb-4f63-8619-fda65c3309a3 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/80f56e48-5cbb-4f63-8619-fda65c3309a3 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/80f56e48-5cbb-4f63-8619-fda65c3309a3 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/80f56e48-5cbb-4f63-8619-fda65c3309a3 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Fraunhofer-AISEC/cpg/sessions/80f56e48-5cbb-4f63-8619-fda65c3309a3 Co-authored-by: oxisto <12459061+oxisto@users.noreply.github.com>
Done — I fixed the review suggestions in commit Included fixes:
Validation run:
|
Uh oh!
There was an error while loading. Please reload this page.