> */ private $cachedComposerJsonPSR4AutoloadPaths = []; /** * @var JsonFileSystem */ private $jsonFileSystem; public function __construct(JsonFileSystem $jsonFileSystem) { $this->jsonFileSystem = $jsonFileSystem; } /** * @return array> */ public function provide(): array { if ($this->cachedComposerJsonPSR4AutoloadPaths !== []) { return $this->cachedComposerJsonPSR4AutoloadPaths; } $composerJson = $this->jsonFileSystem->loadFilePathToJson($this->getComposerJsonPath()); $psr4Autoloads = array_merge( $composerJson[ComposerJsonSection::AUTOLOAD]['psr-4'] ?? [], $composerJson[ComposerJsonSection::AUTOLOAD_DEV]['psr-4'] ?? [] ); $this->cachedComposerJsonPSR4AutoloadPaths = $this->removeEmptyNamespaces($psr4Autoloads); return $this->cachedComposerJsonPSR4AutoloadPaths; } private function getComposerJsonPath(): string { // assume the project has "composer.json" in root directory return getcwd() . '/composer.json'; } /** * @param array> $psr4Autoloads * @return array> */ private function removeEmptyNamespaces(array $psr4Autoloads): array { return array_filter($psr4Autoloads, function (string $psr4Autoload): bool { return $psr4Autoload !== ''; }, ARRAY_FILTER_USE_KEY); } }