WsdlToPhp/PackageGenerator

Composer::getComposerFilePath() must be of the type string, bool returned

Closed this issue · 4 comments

Hi,
after updating the package generator from version 3.3.4 to version 4.1.0, I've get following error when starting the generator in standalone mode:

Return value of WsdlToPhp\PackageGenerator\File\Composer::getComposerFilePath() must be of the type string, bool returned
at ...\wsdltophp\packagegenerator\src\File\Composer.php(146)
#0 ...\wsdltophp\packagegenerator\src\File\Composer.php(121): WsdlToPhp\PackageGenerator\File\Composer->getComposerFilePath()
#1 ...\wsdltophp\packagegenerator\src\File\Composer.php(72): WsdlToPhp\PackageGenerator\File\Composer->getComposerFileContent()
#2 ...\wsdltophp\packagegenerator\src\File\Composer.php(57): WsdlToPhp\PackageGenerator\File\Composer->completeComposerJson()
#3 ...\wsdltophp\packagegenerator\src\File\AbstractFile.php(40): WsdlToPhp\PackageGenerator\File\Composer->writeFile()
#4 ...\wsdltophp\packagegenerator\src\Generator\GeneratorFiles.php(106): WsdlToPhp\PackageGenerator\File\AbstractFile->write()
#5 ...\wsdltophp\packagegenerator\src\Generator\GeneratorFiles.php(41): WsdlToPhp\PackageGenerator\Generator\GeneratorFiles->generateComposerFile()
#6 ...\wsdltophp\packagegenerator\src\Generator\Generator.php(1092): WsdlToPhp\PackageGenerator\Generator\GeneratorFiles->doGenerate()
#7 ...\wsdltophp\packagegenerator\src\Generator\Generator.php(58): WsdlToPhp\PackageGenerator\Generator\Generator->doGenerate()
#8 ...\main.php: WsdlToPhp\PackageGenerator\Generator\Generator->generatePackage()

My code is very similar to the README example:

        $options = GeneratorOptions::instance();
        $options->setOrigin(TEMP_DIR . '/roc.wsdl')
            ->setDestination(OUTPUT_DIR)
            ->setComposerName('mycompany/roc');
        // Generator instanciation
        $generator = new Generator($options);
        // Package generation
        $generator->generatePackage();

Workaround:
When I manually create a composer.json file directly in the output dir, the generator works again (and the PHP files are correctly generated) but the composer.json file isn't updated, the composer.lock file isn't created and the vendor directory isn't created.

Expected:
The composer.json file, the composer.lock file and the vendor directory should automatically be created.

The culprit is following code in WsdlToPhp\PackageGenerator\File\Composer, that expects composer.json to exist, even in standalone mode:

    protected function getComposerFilePath(): string
    {
        return realpath(sprintf('%s/composer.json', $this->getGenerator()->getOptionDestination()));
    }

Probably the cause of the issue #206

Actually, the composer.json file is first created by Composer itself at https://github.com/WsdlToPhp/PackageGenerator/blob/develop/src/File/Composer.php#L39-L55.

Could you try adding a exit(); call after these lines and check if Composer succeeds to initiate the composer.json file?

Oh well, you are right!
I've previously launched my script using Apache, but when I launch same script as PHP CLI everything works as expected:

Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug
Writing composer.json
Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug
Loading composer repositories with package information
Updating dependencies
Dependency resolution completed in 0.002 seconds
Analyzed 87 packages to resolve dependencies
Analyzed 95 rules to resolve dependencies
Lock file operations: 1 install, 0 updates, 0 removals
Installs: wsdltophp/packagebase:5.0.1
  - Locking wsdltophp/packagebase (5.0.1)
Writing lock file
Installing dependencies from lock file
Package operations: 1 install, 0 updates, 0 removals
Installs: wsdltophp/packagebase:5.0.1
  - Installing wsdltophp/packagebase (5.0.1): Extracting archive
Generating optimized autoload files

Feel free to close my bug report, since it works as expected in CLI mode.

And thank you for your great work :)

I'll improve the method anyway, thanks for your feedback.