-
-
Notifications
You must be signed in to change notification settings - Fork 95
Closed
Description
The following line:
| $table[$tableJson['tableHeader']['location']['line']] = array_column($tableJson['tableHeader']['cells'], 'value'); |
assumes that tableHeader is always set, but according to the spec schema, tableHeader is not required, and therefore optional.
I discovered this while implementing PHPStan fixes, using hand-written schema in PHPStan types DSL:
/**
* @phpstan-type TExamples THasTags&array{
* location: TLocation,
* keyword: string,
* name: string,
* description: string,
* tableHeader?: TTableRow, <-----
* tableBody: list<TTableRow>,
* id: string,
* }
*/What shall we do about this?
- Make the PHPStan type mandatory (by removing the
?) and generally ignore the code. - Make PHPStan ignore that line (
@phpstan-ignore-next-line) - Skip that line when the header is not set:
if (isset($tableJson['tableHeader'])) { $table[$tableJson['tableHeader']['location']['line']] = array_column($tableJson['tableHeader']['cells'], 'value'); }
- Create an empty table row (representing the header) when not set. I tried to hack up some code, but it's not as easy as it sounds:
- if we take the line (row index) as the first-body-row-line - 1, it might conflict with an existing line
- what would the columns be? empty strings?
- Something else...?
I think option 3 sounds reasonable, but we need to be sure it doesn't change behaviour.
In conclusion, we want to have this logic:
if (tableBody is empty) { // Header is not important at this point.
return // -> Example should be skipped.
}
if (tableHeader is missing) { // Here it is implied that body is not empty.
throw exception // -> This is not a valid or current case, we should
be notified if this happens in the future.
}
load tableHeader and tableBody // -> The normal/existing case.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels