Skip to content

Commit b655392

Browse files
authored
Analyse even php extension dependencies (ext-*) (#118)
1 parent 9c43766 commit b655392

22 files changed

+760
-131
lines changed

.github/workflows/e2e.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ jobs:
119119
uses: shivammathur/setup-php@v2
120120
with:
121121
php-version: 8.3
122+
ini-file: development
123+
124+
-
125+
name: List enabled extensions
126+
run: php -m
122127

123128
-
124129
name: Install analyser dependencies
@@ -136,7 +141,12 @@ jobs:
136141
working-directory: ${{ matrix.repo }}
137142
run: composer install --no-progress --no-interaction --ignore-platform-reqs ${{ matrix.composerArgs }}
138143

144+
-
145+
name: Run analyser (--disable-ext-analysis)
146+
working-directory: ${{ matrix.repo }}
147+
run: php ../../analyser/bin/composer-dependency-analyser --show-all-usages --disable-ext-analysis ${{ matrix.cdaArgs }}
148+
139149
-
140150
name: Run analyser
141151
working-directory: ${{ matrix.repo }}
142-
run: php ../../analyser/bin/composer-dependency-analyser ${{ matrix.cdaArgs }}
152+
run: php ../../analyser/bin/composer-dependency-analyser --show-all-usages ${{ matrix.cdaArgs }}

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Found unused dependencies!
4949
```
5050

5151
## Detected issues:
52-
This tool reads your `composer.json` and scans all paths listed in `autoload` & `autoload-dev` sections while analysing:
52+
This tool reads your `composer.json` and scans all paths listed in `autoload` & `autoload-dev` sections while analysing you dependencies (both **packages and PHP extensions**).
5353

5454
### Shadowed dependencies
5555
- Those are dependencies of your dependencies, which are not listed in `composer.json`
@@ -84,6 +84,7 @@ This tool reads your `composer.json` and scans all paths listed in `autoload` &
8484
- `--verbose` to see more example classes & usages
8585
- `--show-all-usages` to see all usages
8686
- `--format` to use different output format, available are: `console` (default), `junit`
87+
- `--disable-ext-analysis` to disable php extensions analysis (e.g. `ext-xml`)
8788
- `--ignore-unknown-classes` to globally ignore unknown classes
8889
- `--ignore-unknown-functions` to globally ignore unknown functions
8990
- `--ignore-shadow-deps` to globally ignore shadow dependencies
@@ -128,6 +129,7 @@ return $config
128129
//// Adjust analysis
129130
->enableAnalysisOfUnusedDevDependencies() // dev packages are often used only in CI, so this is not enabled by default
130131
->disableReportingUnmatchedIgnores() // do not report ignores that never matched any error
132+
->disableExtensionsAnalysis() // do not analyse ext-* dependencies
131133

132134
//// Use symbols from yaml/xml/neon files
133135
// - designed for DIC config files (see below)
@@ -166,8 +168,8 @@ Another approach for DIC-only usages is to scan the generated php file, but that
166168
NO_COLOR=1 vendor/bin/composer-dependency-analyser
167169
```
168170

169-
## Limitations:
170-
- Extension dependencies are not analysed (e.g. `ext-json`)
171+
## Recommendations:
172+
- For precise `ext-*` analysis, your enabled extensions of your php runtime should be superset of those used in the scanned project
171173

172174
## Contributing:
173175
- Check your code by `composer check`

composer-dependency-analyser.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<?php declare(strict_types = 1);
22

33
use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
4+
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;
45

56
return (new Configuration())
67
->addPathToScan(__FILE__, true)
78
->addPathToScan(__DIR__ . '/bin', false)
8-
->addPathToExclude(__DIR__ . '/tests/data');
9+
->addPathToExclude(__DIR__ . '/tests/data')
10+
->ignoreErrorsOnExtensionsAndPaths(
11+
['ext-dom', 'ext-libxml'],
12+
[__DIR__ . '/src/Result/JunitFormatter.php'], // optional usages guarded with extension_loaded()
13+
[ErrorType::DEV_DEPENDENCY_IN_PROD]
14+
);

0 commit comments

Comments
 (0)