Skip to content
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

PHPStan Rule Level 5 error in src/Data/ProcessedCodeCoverageData.php #1049

Closed
sebastianbergmann opened this issue Dec 9, 2024 · 3 comments
Closed
Labels

Comments

@sebastianbergmann
Copy link
Owner

The "only" errors left (after reapplying 60fe3d7 which was reverted in 48b98da) before we can go to PHPStan Rule Level 5 for #1039 are these:

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   src/Data/ProcessedCodeCoverageData.php                                                                                                                                                                                                                                                                                                                                           
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  195    Parameter #3 $functionData of method SebastianBergmann\CodeCoverage\Data\ProcessedCodeCoverageData::initPreviouslySeenFunction() expects array{branches: array<int, array{op_start: int, op_end: int, line_start: int, line_end: int, hit: int, out: array<int, int>, out_hit: array<int, int>}>, paths: array<int, array{path: array<int, int>, hit: int}>}, array{branches:    
         array<int, array{op_start: int, op_end: int, line_start: int, line_end: int, hit: list<string>, out: array<int, int>, out_hit: array<int, int>}>, paths: array<int, array{path: array<int, int>, hit: list<string>}>, hit: list<string>} given.                                                                                                                                  
         🪪  argument.type                                                                                                                                                                                                                                                                                                                                                                
         💡 Offset 'branches' (array<int, array{op_start: int, op_end: int, line_start: int, line_end: int, hit: int, out: array<int, int>, out_hit: array<int, int>}>) does not accept type array<int, array{op_start: int, op_end: int, line_start: int, line_end: int, hit: list<string>, out: array<int, int>, out_hit: array<int, int>}>: Offset 'hit' (int) does not accept type    
            list<string>.                                                                                                                                                                                                                                                                                                                                                                 
  197    Parameter #3 $functionData of method SebastianBergmann\CodeCoverage\Data\ProcessedCodeCoverageData::initPreviouslyUnseenFunction() expects array{branches: array<int, array{op_start: int, op_end: int, line_start: int, line_end: int, hit: int, out: array<int, int>, out_hit: array<int, int>}>, paths: array<int, array{path: array<int, int>, hit: int}>}, array{branches:  
         array<int, array{op_start: int, op_end: int, line_start: int, line_end: int, hit: list<string>, out: array<int, int>, out_hit: array<int, int>}>, paths: array<int, array{path: array<int, int>, hit: list<string>}>, hit: list<string>} given.                                                                                                                                  
         🪪  argument.type                                                                                                                                                                                                                                                                                                                                                                
         💡 Offset 'branches' (array<int, array{op_start: int, op_end: int, line_start: int, line_end: int, hit: int, out: array<int, int>, out_hit: array<int, int>}>) does not accept type array<int, array{op_start: int, op_end: int, line_start: int, line_end: int, hit: list<string>, out: array<int, int>, out_hit: array<int, int>}>: Offset 'hit' (int) does not accept type    
            list<string>.                                                                                                                                                                                                                                                                                                                                                                 
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

However, I cannot seem to see the forest for the trees at the moment. May I bother you, @staabm, to have a look? Thanks!

@staabm
Copy link
Contributor

staabm commented Dec 9, 2024

I think the problem is that hit: list<TestIdType>,

is not compatible with hit: int,

when passing functionData into initPreviouslySeenFunction in

$this->initPreviouslySeenFunction($file, $functionName, $functionData);

@staabm
Copy link
Contributor

staabm commented Dec 9, 2024

looking deeper now

@staabm
Copy link
Contributor

staabm commented Dec 9, 2024

I think PHPStan is right that you are passing the wrong array into the initPreviously function calls

if (isset($this->functionCoverage[$file][$functionName])) {
$this->initPreviouslySeenFunction($file, $functionName, $functionData);
} else {
$this->initPreviouslyUnseenFunction($file, $functionName, $functionData);
}

the initPreviously* calls expect a hit: int but you pass in a hit: list<string> (at least if the types are declared correctly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants