Parse the organization and repo from a composer file.

@param array $composer
@return array [$org, $repo]
183175
private function getOrgAndRepo(array $composer)
    {
        $target = $composer['target'];

        $matches = [];
        preg_match(self::TARGET_REGEX, $target, $matches);

        $org = $matches[1];
        $repo = $matches[2];

        return [$org, $repo];
    }
1316564
private function getAutoloadSectionNames($composer)
    {
        $sections = array();

        if (array_key_exists('autoload', $composer)) {
            $sections[] = 'autoload';
        }

        if (array_key_exists('autoload-dev', $composer)) {
            $sections[] = 'autoload-dev';
        }

        return $sections;
    }
1436
private static function parseValid(Composer $composer, $class, $constraint)
    {
        if ($constraint === null) {
            return false;
        }

        $provides = $composer->getPackage()->getProvides();
        $boltVersion = isset($provides['bolt/bolt']) ? $provides['bolt/bolt'] : new Link('__root__', 'bolt/bolt', new Constraint('=', '0.0.0'));

        return $class && Semver::satisfies($boltVersion->getPrettyConstraint(), $constraint);
    }
51708
public function version($dir) {
        if ($this->source($dir)) {
            // Check if unbuilt Drupal
            foreach ($this->getMakefiles($dir) as $file) {
                $f = fopen($file, 'r');
                $peek = fread($f, 1000);
                fclose($f);
                foreach (explode(PHP_EOL, $peek) as $line) {
                    preg_match("/core\s*(:|=)\s*\"?(\d.\w?)\"?$/", $line, $output_array);
                    if (!empty($output_array)) {
                        return ($output_array[2] == self::DRUPAL7) ? self::DRUPAL7 : self::DRUPAL8;
                    }
                }
            }
        } elseif ($this->built($dir)) {
            return (file_exists($dir . '/core/composer.json')) ? self::DRUPAL8 : self::DRUPAL7;
        }
        return null;
    }
162773
public function find(Composer $composer, NpmBridge $bridge): array
    {
        $packages = $composer->getRepositoryManager()->getLocalRepository()
            ->getPackages();

        $dependantPackages = [];

        foreach ($packages as $package) {
            if ($bridge->isDependantPackage($package, false)) {
                $dependantPackages[] = $package;
            }
        }

        return $dependantPackages;
    }
535171
public function load(Repo $repo)
    {
        $project = $this->client->createProject($this->composerLoader->getFile($repo));

        $repo->setDependencies($project->getDependencies());

        return $repo;
    }
1100686
protected function parse_tags( $response, $repo_type ) {
		$tags     = [];
		$rollback = [];

		foreach ( (array) $response as $tag ) {
			$download_link    = implode(
				'/',
				[
					$repo_type['base_uri'],
					'repos',
					$this->type->owner,
					$this->type->slug,
					'archive/',
				]
			);
			$tags[]           = $tag;
			$rollback[ $tag ] = $download_link . $tag . '.zip';
		}

		return [ $tags, $rollback ];
	}
174762
protected function parse_extra_headers( $header, $headers, $header_parts, $repo_parts ) {
		$hosted_domains = [ 'github.com', 'bitbucket.org', 'gitlab.com' ];
		$theme          = null;

		$header['enterprise_uri'] = null;
		$header['enterprise_api'] = null;
		$header['languages']      = null;
		$header['ci_job']         = false;
		$header['release_asset']  = false;

		if ( ! empty( $header['host'] ) && ! in_array( $header['host'], $hosted_domains, true ) ) {
			$header['enterprise_uri'] = $header['base_uri'];
			$header['enterprise_api'] = trim( $header['enterprise_uri'], '/' );
			switch ( $header_parts[0] ) {
				case 'GitHub':
					$header['enterprise_api'] .= '/api/v3';
					break;
				case 'GitLab':
					$header['enterprise_api'] .= '/api/v4';
					break;
				case 'Bitbucket':
					$header['enterprise_api'] .= '/rest/api';
					break;
			}
		}

		if ( $headers instanceof \WP_Theme ) {
			$theme                    = $headers;
			$headers                  = [];
			$headers['Release Asset'] = '';
			$header['release_asset']  = 'true' === $theme->get( 'Release Asset' );
		}

		$self_hosted_parts = array_keys( self::$extra_repo_headers );
		foreach ( $self_hosted_parts as $part ) {
			if ( $theme instanceof \WP_Theme ) {
				$headers[ $repo_parts[ $part ] ] = $theme->get( $repo_parts[ $part ] );
			}
			if ( array_key_exists( $repo_parts[ $part ], $headers ) &&
				! empty( $headers[ $repo_parts[ $part ] ] )
			) {
				switch ( $part ) {
					case 'Languages':
						$header['languages'] = $headers[ $repo_parts[ $part ] ];
						break;
					case 'CIJob':
						$header['ci_job'] = $headers[ $repo_parts[ $part ] ];
						break;
				}
			}
		}
		$header['release_asset'] = ! $header['release_asset'] && isset( $headers['Release Asset'] ) ? 'true' === $headers['Release Asset'] : $header['release_asset'];

		return $header;
	}
438126
protected function addAssetRepositoryToRootComposer()
    {
        $composer = json_decode(file_get_contents(base_path('composer.json')), true);

        $composer['repositories'][] = [
            'type' => 'path',
            'url' => './'.$this->relativeAssetPath(),
        ];

        file_put_contents(
            base_path('composer.json'),
            json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
        );
    }
259670
protected function parsePackageVersion($package)
    {
        $parts = explode(':', $package, 2);
        $parts[1] = isset($parts[1]) ? trim($parts[1]) : '*';
        if ($parts[1] !== '') {
            $name = $parts[0];
            $version = $parts[1];
        } else {
            $name = $package;
            $version = '*';
        }

        return array($name, $version);
    }
391687
public function parse_meta_response( $response ) {
		if ( $this->validate_response( $response ) ) {
			return $response;
		}
		$arr      = [];
		$response = [ $response ];

		array_filter(
			$response,
			function ( $e ) use ( &$arr ) {
				$arr['private']      = ! $e->public;
				$arr['last_updated'] = null;
				$arr['watchers']     = 0;
				$arr['forks']        = 0;
				$arr['open_issues']  = 0;
			}
		);

		return $arr;
	}
994399
public function create(Composer $composer): FileIteratorInterface
    {
        $config              = $composer->getConfig();
        $autoloadGenerator   = $composer->getAutoloadGenerator();
        $installationManager = $composer->getInstallationManager();
        $package             = $composer->getPackage();

        $autoloadGenerator->setClassMapAuthoritative(
            $config->get('classmap-authoritative')
        );
        $autoloadGenerator->setDevMode(false);

        $packageMap = $autoloadGenerator->buildPackageMap(
            $installationManager,
            $package,
            [$package]
        );

        $directives = $autoloadGenerator->parseAutoloads($packageMap, $package);

        $files = new AppendIterator();

        $files->append(
            $this->createClassmapIterator(
                $directives['classmap'] ?? [],
                $directives['exclude-from-classmap'] ?? []
            )
        );
        $files->append(
            $this->createFilesIterator(
                ...array_values($directives['files'] ?? [])
            )
        );
        $files->append(
            $this->createNamespaceIterator($directives['psr-0'] ?? [])
        );
        $files->append(
            $this->createNamespaceIterator($directives['psr-4'] ?? [])
        );

        return new FileIterator($files);
    }
1228991
public function activate(Composer $composer, IOInterface $io) {
		$vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/');

		$overwriteFiles = ['.gitignore','.travis.yml','.scrutinizer.yml','CONTRIBUTING.md','phpunit.xml','phpmd.xml','build.xml'];
		$copyFiles = ['LICENCE.md'];

		foreach ($overwriteFiles as $file) {
			$contents = file_get_contents($vendorDir . DIRECTORY_SEPARATOR . 'opsbears' . DIRECTORY_SEPARATOR .
				'piccolo-dev-tools' . DIRECTORY_SEPARATOR . $file);
			$contents = str_replace('opsbears/piccolo-dev-tools', $composer->getPackage()->getName(), $contents);
			file_put_contents($file, $contents);
		}
		foreach ($copyFiles as $file) {
			if (!file_exists($file)) {
				$contents = file_get_contents($vendorDir . DIRECTORY_SEPARATOR . 'opsbears' . DIRECTORY_SEPARATOR .
					'piccolo-dev-tools' . DIRECTORY_SEPARATOR . $file);
				$contents = str_replace('opsbears/piccolo-dev-tools', $composer->getPackage()->getName(), $contents);
				file_put_contents($file, $contents);
			}
		}
	}
668389
private function getCommandNamespace(array $composer)
    {
        if(! $this->isset('autoload.psr-4', $composer)) {
            return null;
        }

        foreach($composer['autoload']['psr-4'] as $namespace => $folder) {
            if($folder === 'src/') return $namespace . 'Commands\\';
        }
        return null;
    }
184910
private static function getConfigBase(Composer $composer, $io = null)
    {
        $globalPackageConfig = self::getGlobalConfig($composer, 'composer', $io);
        $globalConfig = self::getGlobalConfig($composer, 'config', $io);
        $packageConfig = $composer->getPackage()->getConfig();
        $packageConfig = isset($packageConfig['foxy']) && \is_array($packageConfig['foxy'])
            ? $packageConfig['foxy']
            : array();

        return array_merge($globalPackageConfig, $globalConfig, $packageConfig);
    }
720333
public function removeComposerRepository($repo_url) {
    $composer_json = $this->getComposerJson();
    if (!empty($composer_json['repositories'])) {
      foreach ($composer_json['repositories'] as $key => $repo) {
        $url = $repo['url'];
        if ($repo_url == $url) {
          unset($composer_json['repositories'][$key]);
          $this->writeComposerJson($composer_json);

          return TRUE;
        }
      }
    }
    return FALSE;
  }
654019
private function getSuluVersion($dir)
    {
        $version = '_._._';

        /** @var SplFileInfo $composerFile */
        $composerFile = new SplFileInfo($dir . '/composer.lock', '', '');
        if (!$composerFile->isFile()) {
            return $version;
        }

        $composer = json_decode($composerFile->getContents(), true);
        foreach ($composer['packages'] as $package) {
            if ('sulu/sulu' === $package['name']) {
                return $package['version'];
            }
        }

        return $version;
    }