Skip to content

Commit 1116e7e

Browse files
committed
Update action and phpstan config, add docs, update devcontainer
1 parent ad28d91 commit 1116e7e

File tree

6 files changed

+168
-1
lines changed

6 files changed

+168
-1
lines changed

.devcontainer/devcontainer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
"mehedidracula.php-namespace-resolver"
1616
],
1717
"settings": {
18-
"php.validate.executablePath": "/usr/local/bin/php"
18+
"php.validate.executablePath": "/usr/local/bin/php",
19+
"terminal.integrated.defaultProfile.linux": "bash",
20+
"terminal.integrated.profiles.linux": {
21+
"bash": {
22+
"path": "/bin/bash",
23+
"args": ["-l"]
24+
}
25+
}
1926
}
2027
}
2128
},
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: PHPStan Baseline Check
2+
3+
on:
4+
pull_request:
5+
branches: [ main, master ]
6+
paths:
7+
- 'src/**/*.php'
8+
9+
jobs:
10+
phpstan:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
php-version: ['8.4']
16+
fail-fast: false
17+
18+
steps:
19+
- uses: actions/checkout@v5
20+
21+
- name: Setup PHP
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: ${{ matrix.php-version }}
25+
extensions: dom, json, libxml
26+
coverage: xdebug
27+
28+
- name: Cache Composer packages
29+
id: composer-cache
30+
uses: actions/cache@v4
31+
with:
32+
path: vendor
33+
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-php-${{ matrix.php-version }}-
36+
37+
- name: Install dependencies
38+
run: composer install --prefer-dist --no-progress
39+
40+
- name: Run PHPStan with baseline
41+
run: vendor/bin/phpstan analyse --error-format=github

docs/codecontributions.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Code Quality
2+
3+
This project uses PHPStan for static analysis and Rector for automated code refactoring to maintain high code quality standards.
4+
5+
## PHPStan - Static Analysis
6+
7+
PHPStan analyzes the code for potential issues and type safety problems. The configuration is stored in `phpstan.neon.dist`.
8+
9+
### Generate a new baseline
10+
When introducing PHPStan to legacy code or after major refactoring, you can create a baseline to suppress existing errors:
11+
```bash
12+
vendor/bin/phpstan analyse --generate-baseline
13+
```
14+
15+
### Run analysis
16+
To analyze the codebase and find issues:
17+
```bash
18+
vendor/bin/phpstan analyse
19+
```
20+
21+
### Configuration
22+
- Configuration file: `phpstan.neon.dist`
23+
- Current analysis level: 5
24+
- Baseline file: `phpstan-baseline.neon` (suppresses known issues)
25+
26+
## Rector - Automated Refactoring
27+
28+
Rector automatically modernizes PHP code and applies coding standards. The configuration is stored in `rector.php`.
29+
30+
### Preview changes (recommended first step)
31+
Run a dry-run to see what changes Rector would make without actually modifying files:
32+
```bash
33+
vendor/bin/rector process --dry-run
34+
```
35+
36+
### Apply changes
37+
Apply the refactoring rules to actually modify the code:
38+
```bash
39+
vendor/bin/rector process
40+
```
41+
42+
### Debug mode
43+
To see detailed information about what Rector is doing:
44+
```bash
45+
vendor/bin/rector process --dry-run --debug
46+
```
47+
48+
### Finding new rules
49+
To discover additional Rector rules for your project, visit: https://getrector.com/find-rule
50+
51+
## Workflow
52+
53+
1. **Before making changes**: Run `vendor/bin/phpstan analyse` to check current code quality
54+
2. **Use Rector for improvements**: Run `vendor/bin/rector process --dry-run` to preview automated fixes
55+
3. **Apply safe changes**: Run `vendor/bin/rector process` to apply the changes
56+
4. **Verify with tests**: Run `make test` to ensure changes don't break functionality
57+
5. **Final analysis**: Run `vendor/bin/phpstan analyse` to confirm improvements
58+
59+
## CI/CD Integration
60+
61+
Both PHPStan and Rector are integrated into the CI pipeline to ensure:
62+
- No new PHPStan errors are introduced (beyond the baseline)
63+
- Code follows modern PHP practices through Rector

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
site_name: feed-io Documentation
22
theme:
33
name: material
4+
5+
nav:
6+
- Home: index.md
7+
- Code Quality: codecontributions.md

phpstan-baseline.neon

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Call to an undefined method FeedIo\\Feed\\ItemInterface\:\:setHostInContent\(\)\.$#'
5+
identifier: method.notFound
6+
count: 1
7+
path: src/FeedIo/Feed.php
8+
9+
-
10+
message: '#^Call to an undefined method FeedIo\\Feed\\ItemInterface\:\:setLinkForAnalysis\(\)\.$#'
11+
identifier: method.notFound
12+
count: 1
13+
path: src/FeedIo/Parser/XmlParser.php
14+
15+
-
16+
message: '#^Deprecated in PHP 8\.0\: Required parameter \$url follows optional parameter \$modifiedSince\.$#'
17+
identifier: parameter.requiredAfterOptional
18+
count: 1
19+
path: src/FeedIo/Reader/Result.php
20+
21+
-
22+
message: '#^Deprecated in PHP 8\.1\: Required parameter \$response follows optional parameter \$modifiedSince\.$#'
23+
identifier: parameter.requiredAfterOptional
24+
count: 1
25+
path: src/FeedIo/Reader/Result.php
26+
27+
-
28+
message: '#^Offset float on list in isset\(\) does not exist\.$#'
29+
identifier: isset.offset
30+
count: 1
31+
path: src/FeedIo/Reader/Result/UpdateStats.php
32+
33+
-
34+
message: '#^Call to an undefined method FeedIo\\Feed\\NodeInterface\:\:getHostFromLink\(\)\.$#'
35+
identifier: method.notFound
36+
count: 1
37+
path: src/FeedIo/Rule/Atom/Link.php
38+
39+
-
40+
message: '#^Call to an undefined method FeedIo\\Feed\\NodeInterface\:\:getHostFromLink\(\)\.$#'
41+
identifier: method.notFound
42+
count: 1
43+
path: src/FeedIo/Rule/Link.php
44+
45+
-
46+
message: '#^PHPDoc tag @var with type FeedIo\\Reader\\FixerAbstract is not subtype of native type FeedIo\\Reader\\Fixer\\HttpLastModified\|FeedIo\\Reader\\Fixer\\PublicId\.$#'
47+
identifier: varTag.nativeType
48+
count: 1
49+
path: src/FeedIo/Specification.php

phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
14
parameters:
25
errorFormat: table
36
level: 5

0 commit comments

Comments
 (0)