private function findComposerVersion(string $packageName, string $projectDir): ?string
    {
        // A library app, but being ran from source so use git version.
        if (file_exists("$projectDir/vendor")) {
            return $this->findGitVersion($projectDir);
        }

        $composerFile = "$projectDir/../../../composer.lock";
        if (!file_exists($composerFile)) {
            return null;
        }
        $composer = Json::parse(file_get_contents($composerFile));

        foreach (['packages', 'packages-dev'] as $group) {
            foreach ($composer[$group] as $package) {
                if ($package['name'] === $packageName) {
                    return ltrim($package['version'] ?? null, 'v');
                }
            }
        }

        return null;
    }
private function findComposerVersion(string $packageName, string $projectDir): ?string
    {
        // A library app, but being ran from source so use git version.
        if (file_exists("$projectDir/vendor")) {
            return $this->findGitVersion($projectDir);
        }

        $composerFile = "$projectDir/../../../composer.lock";
        if (!file_exists($composerFile)) {
            return null;
        }
        $composer = Json::parse(file_get_contents($composerFile));

        foreach (['packages', 'packages-dev'] as $group) {
            foreach ($composer[$group] as $package) {
                if ($package['name'] === $packageName) {
                    return ltrim($package['version'] ?? null, 'v');
                }
            }
        }

        return null;
    }
private function findComposerVersion ( string $ packageName , string $ projectDir ) : ? string { // A library app, but being ran from source so use git version. if ( file_exists ( "$projectDir/vendor" ) ) { return $ this -> findGitVersion ( $ projectDir ) ; } $ composerFile = "$projectDir/../../../composer.lock" ; if ( ! file_exists ( $ composerFile ) ) { return null ; } $ composer = Json :: parse ( file_get_contents ( $ composerFile ) ) ; foreach ( [ 'packages' , 'packages-dev' ] as $ group ) { foreach ( $ composer [ $ group ] as $ package ) { if ( $ package [ 'name' ] === $ packageName ) { return ltrim ( $ package [ 'version' ] ?? null , 'v' ) ; } } } return null ; }
Reads the composer lock file based on the project directory
and parses the version for the specified package name.

@param string $packageName
@param string $projectDir

@return string|null
Reads the composer lock file based on the project directory and parses the version for the specified package name .