mediact / dependency-guard

Static production dependency analysis.
MIT License
84 stars 5 forks source link

Dependencies in bin-files only are not counted as used #28

Open Idrinth opened 5 years ago

Idrinth commented 5 years ago

Description

Additionally to autoloading composer also allows the declaration of a bin-file array. These files may very well be the only ones using a specific dependency, like in a single command symfony/console application.

Steps to Reproduce

  1. create a single command symfony console application
  2. only use symfony/console in bin/your-command

Example Code

#!/usr/bin/env php
<?php

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

require_once '../vendor/autoload.php';
$application = new Application('An App');
$application
    ->register('all')
    ->setCode(function(InputInterface $input, OutputInterface $output) {
        return 0;
    })
    ->getApplication()
    ->setDefaultCommand('all');
$application->run();

Expected behavior: No errors

Actual behavior: "[ERROR] Package \"symfony/console\" is installed, but never used."

Reproduces how often: always

Versions

Root Package: 1.0.5

Fixing

I assume adding the files of bin to the list as in https://github.com/mediact/dependency-guard/blob/master/src/Composer/Iterator/SourceFileIteratorFactory.php#L59 would be sufficient.

Idrinth commented 5 years ago

if this is considered either a bug or a valid feature, I'd be happy to implement it.

janmartenjongerius commented 5 years ago

@Idrinth I would be really appreciative of a pull request that pulls in the bin entries in the analysis. Do you concur, @sjokki ? I'm currently less available to write a pull request myself, so if you'd please @Idrinth ?