-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add an option to check the development code. #163
base: master
Are you sure you want to change the base?
Changes from all commits
2595ac3
3b3fcd4
01b0a91
c1372bf
5271372
257dc11
03338e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -51,6 +51,18 @@ If this is already done, run it like this: | |||||||||
composer-require-checker check /path/to/your/project/composer.json | ||||||||||
``` | ||||||||||
|
||||||||||
### Check development code and dependencies (optional) | ||||||||||
|
||||||||||
By default, Composer require checker only checks the source code listed in the `autoload` section of `composer.json` | ||||||||||
against the dependencies listed in the `require` section. This checks that there are no indirect dependencies in the | ||||||||||
*production* code. | ||||||||||
|
||||||||||
To check the *development* code, use the `--dev` option. This will scan the source code from the `autoload-dev` section and will search for symbols in dependencies from both the `require` and `require-dev` | ||||||||||
section. | ||||||||||
Comment on lines
+60
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If max-width is somehow applied (looking at lines above), then it should be rather:
Suggested change
|
||||||||||
|
||||||||||
Please note these two checks are really different: a successful `--dev` check does not guarantee there are no | ||||||||||
no indirect dependencies in the *production* code. You probably want to do both. | ||||||||||
|
||||||||||
## Configuration | ||||||||||
|
||||||||||
Composer require checker is configured to whitelist some symbols per default. Have a look at the | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
build: false | ||
platform: | ||
- x64 | ||
|
||
environment: | ||
COMPOSER_NO_INTERACTION: "1" | ||
ANSICON: '121x90 (121x90)' | ||
matrix: | ||
- PHP_VERSION: '7.2' | ||
COMPOSER_FLAGS: '--prefer-stable --prefer-lowest' | ||
- PHP_VERSION: '7.3' | ||
- PHP_VERSION: '7.4' | ||
Comment on lines
+8
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHP version matrix needs to be updated. Or maybe AppVeyor is not required at this point? Github Actions support Windows 🤔. |
||
|
||
matrix: | ||
fast_finish: true | ||
|
||
init: | ||
- SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH% | ||
|
||
install: | ||
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/ChadSikorra/ps-install-php/master/Install-PHP.ps1" -OutFile "Install-PHP.ps1" | ||
- ps: .\Install-PHP.ps1 -Version $Env:PHP_VERSION -Highest -Arch x64 -Extensions mbstring,fileinfo,openssl | ||
- echo zend_extension=php_opcache.dll >> C:\tools\php\php.ini | ||
- refreshenv | ||
- php -r "readfile('https://getcomposer.org/installer');" | php | ||
- php composer.phar update %COMPOSER_FLAGS% --no-interaction --no-progress -vvv | ||
- php composer.phar info -D | sort | ||
|
||
test_script: | ||
- vendor/bin/phpunit -c phpunit.xml.dist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@php %~dp0\composer-require-checker.php %* |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -48,6 +48,12 @@ protected function configure() | |||||
InputOption::VALUE_NONE, | ||||||
'this will cause ComposerRequireChecker to ignore errors when files cannot be parsed, otherwise' | ||||||
. ' errors will be thrown' | ||||||
) | ||||||
->addOption( | ||||||
'dev', | ||||||
null, | ||||||
InputOption::VALUE_NONE, | ||||||
'check that the development sources (i.e. tests) have not indirect dependencies' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
); | ||||||
} | ||||||
|
||||||
|
@@ -63,19 +69,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |||||
} | ||||||
$composerData = $this->getComposerData($composerJson); | ||||||
|
||||||
$checkDevSources = (bool)$input->getOption('dev'); | ||||||
|
||||||
$options = $this->getCheckOptions($input); | ||||||
|
||||||
$getPackageSourceFiles = new LocateComposerPackageSourceFiles(); | ||||||
$getAdditionalSourceFiles = new LocateFilesByGlobPattern(); | ||||||
|
||||||
$sourcesASTs = $this->getASTFromFilesLocator($input); | ||||||
|
||||||
$additionalLocators = $checkDevSources ? [ | ||||||
$getPackageSourceFiles($composerData, dirname($composerJson), 'autoload-dev'), | ||||||
(new LocateComposerPackageDirectDependenciesSourceFiles())->__invoke($composerJson, 'require-dev') | ||||||
] : []; | ||||||
|
||||||
$this->verbose("Collecting defined vendor symbols... ", $output); | ||||||
$definedVendorSymbols = (new LocateDefinedSymbolsFromASTRoots())->__invoke($sourcesASTs( | ||||||
(new ComposeGenerators())->__invoke( | ||||||
$getAdditionalSourceFiles($options->getScanFiles(), dirname($composerJson)), | ||||||
$getPackageSourceFiles($composerData, dirname($composerJson)), | ||||||
(new LocateComposerPackageDirectDependenciesSourceFiles())->__invoke($composerJson) | ||||||
$getPackageSourceFiles($composerData, dirname($composerJson), 'autoload'), | ||||||
(new LocateComposerPackageDirectDependenciesSourceFiles())->__invoke($composerJson, 'require'), | ||||||
...$additionalLocators | ||||||
) | ||||||
)); | ||||||
$this->verbose("found " . count($definedVendorSymbols) . " symbols.", $output, true); | ||||||
|
@@ -89,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |||||
$this->verbose("Collecting used symbols... ", $output); | ||||||
$usedSymbols = (new LocateUsedSymbolsFromASTRoots())->__invoke($sourcesASTs( | ||||||
(new ComposeGenerators())->__invoke( | ||||||
$getPackageSourceFiles($composerData, dirname($composerJson)), | ||||||
$getPackageSourceFiles($composerData, dirname($composerJson), $checkDevSources ? 'autoload-dev' : 'autoload'), | ||||||
$getAdditionalSourceFiles($options->getScanFiles(), dirname($composerJson)) | ||||||
) | ||||||
)); | ||||||
|
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.