-
Notifications
You must be signed in to change notification settings - Fork 63
Add PHPStan static analysis at level 0, minimal fixes #42
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ceb129a
Add PHPStan static analysis, minimal fixes
sanmai fc5303b
Fix cache
sanmai ab1ddfa
cs
sanmai 0e071b3
Fix PHPStan duplicate array key errors while maintaining BC
sanmai ae9fe9e
Update Spreadsheet/Excel/Writer/Worksheet.php
sanmai 74ceff3
Ignore these
sanmai 6602047
Fixes
sanmai fd85b83
Merge branch 'master' into feat/phpstan
sanmai e3ac6c2
fix it
sanmai dd549bd
fiox
sanmai ae7e54c
fix
sanmai 9541ae8
assertSame
sanmai ae03660
cs
sanmai db3d197
fix
sanmai 25da8b1
cs
sanmai 87d2416
cs
sanmai 030298a
fix
sanmai faf5bd9
fix
sanmai fb44f25
fix
sanmai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| name: Static Analysis | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
| - master | ||
|
|
||
| jobs: | ||
| phpstan: | ||
| name: PHPStan | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| php-version: | ||
| - '8.2' | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: ${{ matrix.php-version }} | ||
| coverage: none | ||
|
|
||
| - name: Get composer cache directory | ||
| id: composer-cache | ||
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_ENV | ||
|
|
||
| - name: Cache dependencies | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ${{ env.dir }} | ||
| key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }} | ||
| restore-keys: | | ||
| composer-${{ runner.os }}-${{ matrix.php-version }}- | ||
| composer-${{ runner.os }}- | ||
|
|
||
| - name: Install dependencies | ||
| run: composer install --prefer-dist --no-progress --no-suggest | ||
|
|
||
| - name: Run PHPStan | ||
| run: vendor/bin/phpstan analyse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| parameters: | ||
| level: 0 | ||
| paths: | ||
| - Spreadsheet | ||
| ignoreErrors: | ||
| - | ||
| message: '#Method .*_substituteCellref.* should return array but return statement is missing#' | ||
| path: Spreadsheet/Excel/Writer/Worksheet.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,20 +15,25 @@ public function testConvertFunctionReturnsValue() | |
| { | ||
| $parser = new Spreadsheet_Excel_Writer_Parser(0, 0x0500); | ||
|
|
||
| // Access protected method via reflection | ||
| $method = new \ReflectionMethod($parser, '_convertFunction'); | ||
| $method->setAccessible(true); | ||
|
|
||
| // Test with a function that has fixed args (should return early) | ||
| // TIME has 3 fixed arguments | ||
| // Fixed args (TIME=3) should return without issue | ||
| $result = $method->invoke($parser, 'TIME', 3); | ||
| $this->assertNotEmpty($result); | ||
| $this->assertTrue(is_string($result)); | ||
|
|
||
| // Test variable args path - SUM has variable args | ||
| // Variable args (SUM=-1) should return without issue | ||
| $result = $method->invoke($parser, 'SUM', 2); | ||
| $this->assertNotEmpty($result); | ||
| $this->assertTrue(is_string($result)); | ||
|
|
||
| // Array structure: [function_number, arg_count, unknown, volatile_flag] | ||
| $parser->_functions['INVALID'] = array(999, -2, 0, 0); // -2 is not valid | ||
|
||
|
|
||
| $this->expectException(\InvalidArgumentException::class); | ||
| $this->expectExceptionMessage('Invalid argument count -2 for function INVALID'); | ||
| $method->invoke($parser, 'INVALID', 1); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -46,27 +51,19 @@ public function testDuplicatePtgValues() | |
| { | ||
| $parser = new Spreadsheet_Excel_Writer_Parser(0, 0x0500); | ||
|
|
||
| // Access protected property via reflection | ||
| $property = new \ReflectionProperty($parser, 'ptg'); | ||
| $property->setAccessible(true); | ||
| $ptg = $property->getValue($parser); | ||
|
|
||
| // Test ptgMemNoMemN - should have the LAST duplicate value | ||
| // Original duplicates: 0x2F (commented), 0x4F (commented), 0x6F (active) | ||
| $this->assertArrayHasKey('ptgMemNoMemN', $ptg, | ||
| 'ptgMemNoMemN key should exist in ptg array'); | ||
| $this->assertSame(0x6F, $ptg['ptgMemNoMemN'], | ||
| 'ptgMemNoMemN should be 0x6F (the last duplicate), not 0x2F or 0x4F'); | ||
| // ptgMemNoMemN: last duplicate at 0x6F wins (0x2F, 0x4F were overwritten) | ||
| $this->assertArrayHasKey('ptgMemNoMemN', $ptg); | ||
| $this->assertSame(0x6F, $ptg['ptgMemNoMemN']); | ||
|
|
||
| // Test ptgAreaErr3d - should have the LAST duplicate value | ||
| // Original duplicates: 0x3D (commented), 0x5D (commented), 0x7D (active) | ||
| $this->assertArrayHasKey('ptgAreaErr3d', $ptg, | ||
| 'ptgAreaErr3d key should exist in ptg array'); | ||
| $this->assertSame(0x7D, $ptg['ptgAreaErr3d'], | ||
| 'ptgAreaErr3d should be 0x7D (the last duplicate), not 0x3D or 0x5D'); | ||
| // ptgAreaErr3d: last duplicate at 0x7D wins (0x3D, 0x5D were overwritten) | ||
| $this->assertArrayHasKey('ptgAreaErr3d', $ptg); | ||
| $this->assertSame(0x7D, $ptg['ptgAreaErr3d']); | ||
|
|
||
| // Verify that ptgMemNoMem exists with value 0x28 | ||
| // (The duplicates at 0x48 and 0x68 are commented out per Excel spec) | ||
| $this->assertSame(0x28, $ptg['ptgMemNoMem'], 'ptgMemNoMem should be 0x28'); | ||
| // ptgMemNoMem base variant at 0x28 (0x48, 0x68 duplicates removed per Excel spec) | ||
| $this->assertSame(0x28, $ptg['ptgMemNoMem']); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly accessing the protected property
_functionswill cause a visibility error. UseReflectionPropertyto set accessibility before modifying this value.