private function extractPackage(
        string $vendorPath,
        SymbolInterface $symbol
    ): ?string {
        static $packagesPerSymbol = [];

        $name = $symbol->getName();

        if (!array_key_exists($name, $packagesPerSymbol)) {
            $reflection = $this->getClassReflection($name);
            $file       = str_replace('\\', '/', $reflection->getFileName());

            // This happens for symbols in the current package.
            if (strpos($file, $vendorPath) !== 0) {
                return null;
            }

            $structure = explode(
                '/',
                preg_replace(
                    sprintf(
                        '/^%s/',
                        preg_quote($vendorPath . '/', '/')
                    ),
                    '',
                    $file
                ),
                3
            );

            // This happens when other code extends Composer root code, like:
            // composer/ClassLoader.php
            if (count($structure) < 3) {
                $packagesPerSymbol[$name] = null;
            }

            [$vendor, $package] = $structure;

            $packagesPerSymbol[$name] = sprintf('%s/%s', $vendor, $package);
        }

        return $packagesPerSymbol[$name] ?? null;
    }
private function extractPackage(
        string $vendorPath,
        SymbolInterface $symbol
    ): ?string {
        static $packagesPerSymbol = [];

        $name = $symbol->getName();

        if (!array_key_exists($name, $packagesPerSymbol)) {
            $reflection = $this->getClassReflection($name);
            $file       = str_replace('\\', '/', $reflection->getFileName());

            // This happens for symbols in the current package.
            if (strpos($file, $vendorPath) !== 0) {
                return null;
            }

            $structure = explode(
                '/',
                preg_replace(
                    sprintf(
                        '/^%s/',
                        preg_quote($vendorPath . '/', '/')
                    ),
                    '',
                    $file
                ),
                3
            );

            // This happens when other code extends Composer root code, like:
            // composer/ClassLoader.php
            if (count($structure) < 3) {
                $packagesPerSymbol[$name] = null;
            }

            [$vendor, $package] = $structure;

            $packagesPerSymbol[$name] = sprintf('%s/%s', $vendor, $package);
        }

        return $packagesPerSymbol[$name] ?? null;
    }
private function extractPackage ( string $ vendorPath , SymbolInterface $ symbol ) : ? string { static $ packagesPerSymbol = [ ] ; $ name = $ symbol -> getName ( ) ; if ( ! array_key_exists ( $ name , $ packagesPerSymbol ) ) { $ reflection = $ this -> getClassReflection ( $ name ) ; $ file = str_replace ( '\\' , '/' , $ reflection -> getFileName ( ) ) ; // This happens for symbols in the current package. if ( strpos ( $ file , $ vendorPath ) !== 0 ) { return null ; } $ structure = explode ( '/' , preg_replace ( sprintf ( '/^%s/' , preg_quote ( $ vendorPath . '/' , '/' ) ) , '' , $ file ) , 3 ) ; // This happens when other code extends Composer root code, like: // composer/ClassLoader.php if ( count ( $ structure ) < 3 ) { $ packagesPerSymbol [ $ name ] = null ; } [ $ vendor , $ package ] = $ structure ; $ packagesPerSymbol [ $ name ] = sprintf ( '%s/%s' , $ vendor , $ package ) ; } return $ packagesPerSymbol [ $ name ] ?? null ; }
Extract the package name from the given PHP symbol.

@param string          $vendorPath
@param SymbolInterface $symbol

@return string|null
Extract the package name from the given PHP symbol .