[
https://issues.apache.org/jira/browse/THRIFT-5958?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Volodymyr Panivko updated THRIFT-5958:
--------------------------------------
Description:
THRIFT-5957 introduced phpstan/phpstan ^1.12 with a baseline that pins
5 issues already present in lib/php/lib/. All are "should return X but
return statement is missing" errors caught at level 1.
This ticket clears the baseline to zero by fixing each finding
individually. After this PR, lib/php/phpstan-baseline.neon should
contain only "parameters: ignoreErrors: []".
Findings to fix:
1. lib/ClassLoader/ThriftClassLoader.php:130
Method findFile() declares @return string but the function can
fall through without a return when no file is matched.
Fix: declare native return type ?string and add `return null` at
the end of the function body. PSR-4 autoloaders may legitimately
return null.
2. lib/Protocol/TJSONProtocol.php:477 writeStructBegin
3. lib/Protocol/TJSONProtocol.php:488 writeStructEnd
4. lib/Protocol/TSimpleJSONProtocol.php:165 writeStructBegin
5. lib/Protocol/TSimpleJSONProtocol.php:175 writeStructEnd
Method declares @return int (bytes written) but delegates to a
writeJSONObjectStart/End helper without returning. Other Thrift
libraries (Java, Go) treat JSON struct delimiters as 0-byte from
the protocol-counter perspective.
Fix: explicitly `return 0;` after the helper call. Document
intent with a brief // comment.
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/.
> Resolve initial PHPStan baseline findings
> -----------------------------------------
>
> Key: THRIFT-5958
> URL: https://issues.apache.org/jira/browse/THRIFT-5958
> Project: Thrift
> Issue Type: New Feature
> Components: PHP - Library
> Affects Versions: 0.24.0
> Reporter: Volodymyr Panivko
> Assignee: Volodymyr Panivko
> Priority: Major
>
> THRIFT-5957 introduced phpstan/phpstan ^1.12 with a baseline that pins
> 5 issues already present in lib/php/lib/. All are "should return X but
> return statement is missing" errors caught at level 1.
> This ticket clears the baseline to zero by fixing each finding
> individually. After this PR, lib/php/phpstan-baseline.neon should
> contain only "parameters: ignoreErrors: []".
> Findings to fix:
> 1. lib/ClassLoader/ThriftClassLoader.php:130
> Method findFile() declares @return string but the function can
> fall through without a return when no file is matched.
> Fix: declare native return type ?string and add `return null` at
> the end of the function body. PSR-4 autoloaders may legitimately
> return null.
> 2. lib/Protocol/TJSONProtocol.php:477 writeStructBegin
> 3. lib/Protocol/TJSONProtocol.php:488 writeStructEnd
> 4. lib/Protocol/TSimpleJSONProtocol.php:165 writeStructBegin
> 5. lib/Protocol/TSimpleJSONProtocol.php:175 writeStructEnd
> Method declares @return int (bytes written) but delegates to a
> writeJSONObjectStart/End helper without returning. Other Thrift
> libraries (Java, Go) treat JSON struct delimiters as 0-byte from
> the protocol-counter perspective.
> Fix: explicitly `return 0;` after the helper call. Document
> intent with a brief // comment.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)