<commit_before><?php

/*
 * This file is part of Octower.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * Based on work for Composer of :
 * (c) <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Octower\Command;

use Octower\Octower;
use Octower\Util\RemoteFilesystem;
use Octower\Downloader\FilesystemException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class SelfUpdateCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('self-update')
            ->setDescription('Updates octower.phar to the latest version.')
            ->setHelp(<<<EOT
The <info>self-update</info> command checks getoctower.org for newer
versions of composer and if found, installs the latest.

<info>php octower.phar self-update</info>

EOT
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $localFilename = realpath($_SERVER['argv'][0]) ? : $_SERVER['argv'][0];
        $tempFilename  = dirname($localFilename) . '/' . basename($localFilename, '.phar') . '-temp.phar';

        // check for permissions in local filesystem before start connection process
        if (!is_writable($tempDirectory = dirname($tempFilename))) {
            throw new FilesystemException('Octower update failed: the "' . $tempDirectory . '" directory used to download the temp file could not be written');
        }

        if (!is_writable($localFilename)) {
            throw new FilesystemException('Octower update failed: the "' . $localFilename . '" file could not be written');
        }

        //$protocol = extension_loaded('openssl') ? 'https' : 'http';
        $protocol = 'http';
        $rfs      = new RemoteFilesystem($this->getIO());
        $latest   = trim($rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/version', false));

        if (Octower::VERSION !== $latest) {
            $output->writeln(sprintf("Updating to version <info>%s</info>.", $latest));

            $remoteFilename = $protocol . '://getoctower.org/octower.phar';

            $rfs->copy('getoctower.org', $remoteFilename, $tempFilename);

            if (!file_exists($tempFilename)) {
                $output->writeln('<error>The download of the new octower version failed for an unexpected reason');

                return 1;
            }

            try {
                chmod($tempFilename, 0777 & ~umask());
                // test the phar validity
                $phar = new \Phar($tempFilename);
                // free the variable to unlock the file
                unset($phar);
                rename($tempFilename, $localFilename);
            } catch (\Exception $e) {
                @unlink($tempFilename);
                if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
                    throw $e;
                }
                $output->writeln('<error>The download is corrupted (' . $e->getMessage() . ').</error>');
                $output->writeln('<error>Please re-run the self-update command to try again.</error>');
            }
        } else {
            $output->writeln("<info>You are using the latest octower version.</info>");
        }
    }
}
<commit_msg>remove reference to composer in self-update script<commit_after><?php

/*
 * This file is part of Octower.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * Based on work for Composer of :
 * (c) <NAME> <<EMAIL>>
 *     <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Octower\Command;

use Octower\Octower;
use Octower\Util\RemoteFilesystem;
use Octower\Downloader\FilesystemException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class SelfUpdateCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('self-update')
            ->setDescription('Updates octower.phar to the latest version.')
            ->setHelp(<<<EOT
The <info>self-update</info> command checks getoctower.org for newer
versions of octower and if found, installs the latest.

<info>php octower.phar self-update</info>

EOT
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $localFilename = realpath($_SERVER['argv'][0]) ? : $_SERVER['argv'][0];
        $tempFilename  = dirname($localFilename) . '/' . basename($localFilename, '.phar') . '-temp.phar';

        // check for permissions in local filesystem before start connection process
        if (!is_writable($tempDirectory = dirname($tempFilename))) {
            throw new FilesystemException('Octower update failed: the "' . $tempDirectory . '" directory used to download the temp file could not be written');
        }

        if (!is_writable($localFilename)) {
            throw new FilesystemException('Octower update failed: the "' . $localFilename . '" file could not be written');
        }

        //$protocol = extension_loaded('openssl') ? 'https' : 'http';
        $protocol = 'http';
        $rfs      = new RemoteFilesystem($this->getIO());
        $latest   = trim($rfs->getContents('getoctower.org', $protocol . '://getoctower.org/version', false));

        if (Octower::VERSION !== $latest) {
            $output->writeln(sprintf("Updating to version <info>%s</info>.", $latest));

            $remoteFilename = $protocol . '://getoctower.org/octower.phar';

            $rfs->copy('getoctower.org', $remoteFilename, $tempFilename);

            if (!file_exists($tempFilename)) {
                $output->writeln('<error>The download of the new octower version failed for an unexpected reason');

                return 1;
            }

            try {
                chmod($tempFilename, 0777 & ~umask());
                // test the phar validity
                $phar = new \Phar($tempFilename);
                // free the variable to unlock the file
                unset($phar);
                rename($tempFilename, $localFilename);
            } catch (\Exception $e) {
                @unlink($tempFilename);
                if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
                    throw $e;
                }
                $output->writeln('<error>The download is corrupted (' . $e->getMessage() . ').</error>');
                $output->writeln('<error>Please re-run the self-update command to try again.</error>');
            }
        } else {
            $output->writeln("<info>You are using the latest octower version.</info>");
        }
    }
}

{'fraction_non_alphanumeric': 0.1348103098754706, 'fraction_numerical': 0.002027222704894295, 'mean_word_length': 2.4125494071146245, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3820504', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1847, 'n_words': 506}