[
https://issues.apache.org/jira/browse/THRIFT-5959?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Volodymyr Panivko updated THRIFT-5959:
--------------------------------------
Description:
The PHP coding standard documented at lib/php/coding_standards.md is
PSR-2 (frozen since 2019; superseded by PSR-12). The PHP-CodeSniffer
config at phpcs.xml.dist still pins it. Meanwhile, generated PHP code
emitted by the C++ generator at compiler/cpp/src/thrift/generate/
t_php_generator.cc has its own hand-written formatting that does not
follow either standard precisely.
This ticket adopts PSR-12 across both surfaces in one cycle to avoid
two style families coexisting in the repo:
* Add friendsofphp/php-cs-fixer as a require-dev dependency.
* Add lib/php/.php-cs-fixer.dist.php with @PSR12 + @PHP81Migration
presets (see roadmap doc for full ruleset).
* Run php-cs-fixer fix once across lib/php/lib/ and lib/php/test/ to
reformat to PSR-12.
* Update phpcs.xml.dist to reference PSR12 instead of PSR2 (or remove
it if cs-fixer fully replaces it — to be decided in PR).
* Update lib/php/coding_standards.md to point at PSR-12.
* Update C++ generator emission in t_php_generator.cc so newly
generated PHP matches PSR-12: indentation, blank lines, brace
placement, namespace block, use ordering.
* Regenerate golden test fixtures under test/php/gen-php/,
test/php/gen-phpi/, test/php/gen-php-classmap/.
* Add lib-php-quality CI step that runs php-cs-fixer in --dry-run
mode (alongside the existing phpstan step from THRIFT-5957).
This is a breaking change for downstream users whose own coding-style
linters rely on the previous format of generated files. Plain runtime
behaviour is unaffected — pure formatting.
was:
The PHP runtime library at lib/php/lib/ has no static-analysis tooling.
Refactors and type-modernization PRs go in without an automated safety
net to catch regressions.
This ticket adds phpstan/phpstan ^1.12 as a require-dev dependency,
configures it at lib/php/phpstan.neon (level 1) with a generated
baseline that pins the current state, and wires a new lib-php-quality
job in the GitHub Actions workflow that runs phpstan on PHP 8.3.
The chosen level (1) catches undefined variables and obvious type
mismatches without requiring widespread code changes. Higher levels
will be raised in follow-up tickets as the runtime library gains
native types and PHPDoc cleanup.
Out of scope:
* PSR-12 migration / php-cs-fixer (separate ticket).
* declare(strict_types=1) and native types in lib (separate ticket).
* Static analysis of generated PHP under test/Resources/packages/.
> Adopt PSR-12 across the PHP library and align C++ generator emission style
> --------------------------------------------------------------------------
>
> Key: THRIFT-5959
> URL: https://issues.apache.org/jira/browse/THRIFT-5959
> Project: Thrift
> Issue Type: New Feature
> Components: PHP - Library
> Affects Versions: 0.24.0
> Reporter: Volodymyr Panivko
> Assignee: Volodymyr Panivko
> Priority: Major
>
> The PHP coding standard documented at lib/php/coding_standards.md is
> PSR-2 (frozen since 2019; superseded by PSR-12). The PHP-CodeSniffer
> config at phpcs.xml.dist still pins it. Meanwhile, generated PHP code
> emitted by the C++ generator at compiler/cpp/src/thrift/generate/
> t_php_generator.cc has its own hand-written formatting that does not
> follow either standard precisely.
> This ticket adopts PSR-12 across both surfaces in one cycle to avoid
> two style families coexisting in the repo:
> * Add friendsofphp/php-cs-fixer as a require-dev dependency.
> * Add lib/php/.php-cs-fixer.dist.php with @PSR12 + @PHP81Migration
> presets (see roadmap doc for full ruleset).
> * Run php-cs-fixer fix once across lib/php/lib/ and lib/php/test/ to
> reformat to PSR-12.
> * Update phpcs.xml.dist to reference PSR12 instead of PSR2 (or remove
> it if cs-fixer fully replaces it — to be decided in PR).
> * Update lib/php/coding_standards.md to point at PSR-12.
> * Update C++ generator emission in t_php_generator.cc so newly
> generated PHP matches PSR-12: indentation, blank lines, brace
> placement, namespace block, use ordering.
> * Regenerate golden test fixtures under test/php/gen-php/,
> test/php/gen-phpi/, test/php/gen-php-classmap/.
> * Add lib-php-quality CI step that runs php-cs-fixer in --dry-run
> mode (alongside the existing phpstan step from THRIFT-5957).
> This is a breaking change for downstream users whose own coding-style
> linters rely on the previous format of generated files. Plain runtime
> behaviour is unaffected — pure formatting.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)