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

Analyse even php extension dependencies (ext-*) #118

Merged
merged 14 commits into from
Oct 31, 2024
12 changes: 11 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
ini-file: development

-
name: List enabled extensions
run: php -m

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

-
name: Run analyser (--disable-ext-analysis)
working-directory: ${{ matrix.repo }}
run: php ../../analyser/bin/composer-dependency-analyser --show-all-usages --disable-ext-analysis ${{ matrix.cdaArgs }}

-
name: Run analyser
working-directory: ${{ matrix.repo }}
run: php ../../analyser/bin/composer-dependency-analyser ${{ matrix.cdaArgs }}
run: php ../../analyser/bin/composer-dependency-analyser --show-all-usages ${{ matrix.cdaArgs }}
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Found unused dependencies!
```

## Detected issues:
This tool reads your `composer.json` and scans all paths listed in `autoload` & `autoload-dev` sections while analysing:
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**).

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

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

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

## Contributing:
- Check your code by `composer check`
Expand Down
8 changes: 7 additions & 1 deletion composer-dependency-analyser.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php declare(strict_types = 1);

use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;

return (new Configuration())
->addPathToScan(__FILE__, true)
->addPathToScan(__DIR__ . '/bin', false)
->addPathToExclude(__DIR__ . '/tests/data');
->addPathToExclude(__DIR__ . '/tests/data')
->ignoreErrorsOnExtensionsAndPaths(
['ext-dom', 'ext-libxml'],
[__DIR__ . '/src/Result/JunitFormatter.php'], // optional usages guarded with extension_loaded()
[ErrorType::DEV_DEPENDENCY_IN_PROD]
);
Loading
Loading