<commit_before><?php
namespace PharIo\Phive;

class PharService {

    /**
     * @var PharDownloader
     */
    private $downloader;

    /**
     * @var PharInstaller
     */
    private $installer;

    /**
     * @var PharRegistry
     */
    private $pharRegistry;

    /**
     * @var AliasResolverService
     */
    private $aliasResolver;

    /**
     * @var Cli\Output
     */
    private $output;

    /**
     * @var SourceRepositoryLoader
     */
    private $sourceRepositoryLoader;

    /**
     * @param PharDownloader         $downloader
     * @param PharInstaller          $installer
     * @param PharRegistry           $pharRegistry
     * @param AliasResolverService   $resolver
     * @param Cli\Output             $output
     * @param SourceRepositoryLoader $sourceRepositoryLoader
     */
    public function __construct(
        PharDownloader $downloader,
        PharInstaller $installer,
        PharRegistry $pharRegistry,
        AliasResolverService $resolver,
        Cli\Output $output,
        SourceRepositoryLoader $sourceRepositoryLoader
    ) {
        $this->downloader = $downloader;
        $this->installer = $installer;
        $this->pharRegistry = $pharRegistry;
        $this->aliasResolver = $resolver;
        $this->output = $output;
        $this->sourceRepositoryLoader = $sourceRepositoryLoader;
    }

    /**
     * @param RequestedPhar $requestedPhar
     * @param Directory     $destination
     * @param bool          $makeCopy
     *
     * @return Phar|null
     */
    public function install(RequestedPhar $requestedPhar, Directory $destination, $makeCopy) {
        return $this->doInstall($requestedPhar, $destination, $makeCopy, false);
    }

    /**
     * @param RequestedPhar $requestedPhar
     * @param Directory     $destination
     *
     * @return Phar|null
     */
    public function update(RequestedPhar $requestedPhar, Directory $destination) {
        return $this->doInstall($requestedPhar, $destination, false, true);
    }

    /**
     * @param RequestedPhar $requestedPhar
     * @param Directory     $destination
     * @param bool          $makeCopy
     * @param bool          $replaceExisting
     *
     * @return InstalledPhar
     */
    private function doInstall(RequestedPhar $requestedPhar, Directory $destination, $makeCopy, $replaceExisting) {
        $release = $this->getRelease($requestedPhar);

        $name = $release->getName();
        $version = $release->getVersion();
        $pharName = $release->getUrl()->getPharName();

        $destinationFile = $destination->file($pharName);
        if (!$replaceExisting && $destinationFile->exists()) {
            $this->output->writeInfo(sprintf('%s is already installed, skipping.', $pharName));
            return null;
        }

        if (!$this->pharRegistry->hasPhar($name, $version)) {
            $phar = $this->downloader->download($release);
            $this->pharRegistry->addPhar($phar);<commit_msg>fix return types<commit_after><?php
namespace PharIo\Phive;

class PharService {

    /**
     * @var PharDownloader
     */
    private $downloader;

    /**
     * @var PharInstaller
     */
    private $installer;

    /**
     * @var PharRegistry
     */
    private $pharRegistry;

    /**
     * @var AliasResolverService
     */
    private $aliasResolver;

    /**
     * @var Cli\Output
     */
    private $output;

    /**
     * @var SourceRepositoryLoader
     */
    private $sourceRepositoryLoader;

    /**
     * @param PharDownloader         $downloader
     * @param PharInstaller          $installer
     * @param PharRegistry           $pharRegistry
     * @param AliasResolverService   $resolver
     * @param Cli\Output             $output
     * @param SourceRepositoryLoader $sourceRepositoryLoader
     */
    public function __construct(
        PharDownloader $downloader,
        PharInstaller $installer,
        PharRegistry $pharRegistry,
        AliasResolverService $resolver,
        Cli\Output $output,
        SourceRepositoryLoader $sourceRepositoryLoader
    ) {
        $this->downloader = $downloader;
        $this->installer = $installer;
        $this->pharRegistry = $pharRegistry;
        $this->aliasResolver = $resolver;
        $this->output = $output;
        $this->sourceRepositoryLoader = $sourceRepositoryLoader;
    }

    /**
     * @param RequestedPhar $requestedPhar
     * @param Directory     $destination
     * @param bool          $makeCopy
     *
     * @return InstalledPhar|null
     */
    public function install(RequestedPhar $requestedPhar, Directory $destination, $makeCopy) {
        return $this->doInstall($requestedPhar, $destination, $makeCopy, false);
    }

    /**
     * @param RequestedPhar $requestedPhar
     * @param Directory     $destination
     *
     * @return InstalledPhar|null
     */
    public function update(RequestedPhar $requestedPhar, Directory $destination) {
        return $this->doInstall($requestedPhar, $destination, false, true);
    }

    /**
     * @param RequestedPhar $requestedPhar
     * @param Directory     $destination
     * @param bool          $makeCopy
     * @param bool          $replaceExisting
     *
     * @return InstalledPhar|null
     */
    private function doInstall(RequestedPhar $requestedPhar, Directory $destination, $makeCopy, $replaceExisting) {
        $release = $this->getRelease($requestedPhar);

        $name = $release->getName();
        $version = $release->getVersion();
        $pharName = $release->getUrl()->getPharName();

        $destinationFile = $destination->file($pharName);
        if (!$replaceExisting && $destinationFile->exists()) {
            $this->output->writeInfo(sprintf('%s is already installed, skipping.', $pharName));
            return null;
        }

        if (!$this->pharRegistry->hasPhar($name, $version)) {
            $phar = $this->downloader->download($release);
            $this->pharRegistry->addPhar($phar);
{'fraction_non_alphanumeric': 0.11816962789138451, 'fraction_numerical': 0.0, 'mean_word_length': 2.3730921424533635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1988265', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1678, 'n_words': 331}