deptrac icon indicating copy to clipboard operation
deptrac copied to clipboard

PHAR: ComposerFilesParser.php searches for composer.(json|lock) inside the phar

Open gennadigennadigennadi opened this issue 2 years ago • 4 comments


$ ./deptrac.phar -c ../deptrac.yaml 

Warning: file_get_contents(composer.lock): Failed to open stream: No such file or directory in phar:///var/www/deptrac/tmp/deptrac.phar/src/Core/Layer/Collector/ComposerFilesParser.php on line 37
                                                                                                                        
 [ERROR] Analysis finished with an Exception.                                                                           
                                                                                                                        
         Could not parse file.                                                                                          
                                                                                                                        
         Could not parse composer files.                                                                                
                                                                                                                        
         Could not load composer.lock file                                                                              

gennadigennadigennadi avatar Jun 20 '23 14:06 gennadigennadigennadi

This kind of begs the question, what should be the base path that this collector should look at in case a relative path to the file is provided?

patrickkusebauch avatar Jun 20 '23 15:06 patrickkusebauch

Did you @patrickkusebauch or @dbrumann discussed, what deptrac sees as its base path?

  • the users current dir?
  • the path of the deptrac executable?
  • the paht of the deptrac-config?

In the code I have seen Parameters for currentWorkingDirectory and projectDirectory and both get getcwd() assigned.

The documentations says:

* `%currentWorkingDirectory%` The path Deptrac runs in
* `%projectDirectory%` The path where the configuration is stored.

But what I see in the code is:

        if (false === ($currentWorkingDirectory = getcwd())) {
            throw CannotGetCurrentWorkingDirectoryException::cannotGetCWD();
        }

        ....
        $factory = new ServiceContainerBuilder($currentWorkingDirectory);

    public function build(): ContainerBuilder
    {
        $container = new ContainerBuilder();

        $container->setParameter('currentWorkingDirectory', $this->workingDirectory);

        self::registerCompilerPasses($container);
        self::loadServices($container, $this->cacheFile);

        $container->registerExtension(new DeptracExtension());

        $container->setParameter('projectDirectory', $this->workingDirectory);
        if (null !== $this->configFile) {
            self::loadConfiguration($container, $this->configFile);
        }

        $container->compile(true);

        return $container;
    }

I could work on this problem as soon as I understand the path situation. Btw it's also relevant for the #1078, I think.

gennadigennadigennadi avatar Jun 20 '23 15:06 gennadigennadigennadi

Nope, we didn't.

patrickkusebauch avatar Jun 20 '23 16:06 patrickkusebauch

This kind of begs the question, what should be the base path that this collector should look at in case a relative path to the file is provided?

I would say, relative to the config-file.

gennadigennadigennadi avatar Jun 21 '23 07:06 gennadigennadigennadi