diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index f129b1523..fecdd4c89 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -409,7 +409,15 @@ EOT throw new \InvalidArgumentException('Invalid stability provided ('.$stability.'), must be one of: '.implode(', ', array_keys(BasePackage::$stabilities))); } - $composer = Factory::create($io, $config->all(), $disablePlugins); + $composerJson = array_merge( + // prevent version guessing from happening + array('version' => '1.0.0'), + $config->all(), + // ensure the vendor dir and its plugins does not get loaded if CWD/vendor has plugins in it + array('config' => array('vendor-dir' => Platform::getDevNull())) + ); + $factory = new Factory; + $composer = $factory->createComposer($io, $composerJson, $disablePlugins, Platform::getDevNull(), true, $disableScripts); $config = $composer->getConfig(); $rm = $composer->getRepositoryManager(); diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index b7ebb2312..340f499b2 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -283,6 +283,7 @@ class Factory * @throws \InvalidArgumentException * @throws \UnexpectedValueException * @return Composer|PartialComposer Composer if $fullLoad is true, otherwise PartialComposer + * @phpstan-return ($fullLoad is true ? Composer : PartialComposer) */ public function createComposer(IOInterface $io, $localConfig = null, bool $disablePlugins = false, ?string $cwd = null, bool $fullLoad = true, bool $disableScripts = false) { @@ -452,10 +453,7 @@ class Factory { $factory = new static(); - $composer = $factory->createGlobalComposer($io, static::createConfig($io), $disablePlugins, $disableScripts, true); - assert(null === $composer || $composer instanceof Composer); - - return $composer; + return $factory->createGlobalComposer($io, static::createConfig($io), $disablePlugins, $disableScripts, true); } /** @@ -476,6 +474,7 @@ class Factory /** * @return PartialComposer|Composer|null By default PartialComposer, but Composer if $fullLoad is set to true + * @phpstan-return ($fullLoad is true ? Composer|null : PartialComposer|null) */ protected function createGlobalComposer(IOInterface $io, Config $config, bool $disablePlugins, bool $disableScripts, bool $fullLoad = false): ?PartialComposer { @@ -617,10 +616,7 @@ class Factory { $factory = new static(); - $composer = $factory->createComposer($io, $config, $disablePlugins, null, true, $disableScripts); - assert($composer instanceof Composer); - - return $composer; + return $factory->createComposer($io, $config, $disablePlugins, null, true, $disableScripts); } /**