<commit_before><?php
namespace ShinyDeploy\Domain;

use ShinyDeploy\Core\Domain;
use ShinyDeploy\Core\Server\Server;
use ShinyDeploy\Core\Server\SftpServer;

class Deploy extends Domain
{
    /** @var array $supportedServerTypes */
    protected $supportedServerTypes = ['sftp'];

    /**
     * Creates server object.
     *
     * @param string $type
     * @return mixed
     */
    public function getServer($type)
    {
        if (!in_array($type, $this->supportedServerTypes)) {
            throw new \RuntimeException('Unknown server-type.');
        }
        switch ($type) {
            case 'sftp':
                return new SftpServer;
                break;
        }
        return false;
    }

    /**
     * Checks if connection to server is possible.
     *
     * @param Server $server
     * @param array $serverData
     * @return bool
     */
    public function checkConnectivity(Server $server, array $serverData)
    {
        $connectionResult = $server->connect(
            $serverData['hostname'],
            $serverData['username'],
            $serverData['password'],
            $serverData['port']
        );
        return $connectionResult;
    }

    /**
     * Fetches remote revision from REVISION file in project root.
     *
     * @param Server $server
     * @param string $targetPath
     * @return string|bool
     */
    public function getRemoteRevision(Server $server, $targetPath)
    {
        if (empty($targetPath)) {
            throw new \RuntimeException('No target path for remote server provided');
        }
        $revision = $server->getFileContent($targetPath);
        if (!empty($revision) && preg_match('#[0-9a-f]{40}#', $revision) === 1) {
            return $revision;
        }
        $targetDir = dirname($targetPath);
        $targetDirContent = $server->listDir($targetDir);
        if ($targetDirContent === false) {
            return false;
        }
        if (is_array($targetDirContent) && empty($targetDirContent)) {
            return '-1';
        }
        return false;
    }

    /**
     * Fetches revision of local repository.<commit_msg>Trim possible line-break when fetching remote revision<commit_after><?php
namespace ShinyDeploy\Domain;

use ShinyDeploy\Core\Domain;
use ShinyDeploy\Core\Server\Server;
use ShinyDeploy\Core\Server\SftpServer;

class Deploy extends Domain
{
    /** @var array $supportedServerTypes */
    protected $supportedServerTypes = ['sftp'];

    /**
     * Creates server object.
     *
     * @param string $type
     * @return mixed
     */
    public function getServer($type)
    {
        if (!in_array($type, $this->supportedServerTypes)) {
            throw new \RuntimeException('Unknown server-type.');
        }
        switch ($type) {
            case 'sftp':
                return new SftpServer;
                break;
        }
        return false;
    }

    /**
     * Checks if connection to server is possible.
     *
     * @param Server $server
     * @param array $serverData
     * @return bool
     */
    public function checkConnectivity(Server $server, array $serverData)
    {
        $connectionResult = $server->connect(
            $serverData['hostname'],
            $serverData['username'],
            $serverData['password'],
            $serverData['port']
        );
        return $connectionResult;
    }

    /**
     * Fetches remote revision from REVISION file in project root.
     *
     * @param Server $server
     * @param string $targetPath
     * @return string|bool
     */
    public function getRemoteRevision(Server $server, $targetPath)
    {
        if (empty($targetPath)) {
            throw new \RuntimeException('No target path for remote server provided');
        }
        $revision = $server->getFileContent($targetPath);
        $revision = trim($revision);
        if (!empty($revision) && preg_match('#[0-9a-f]{40}#', $revision) === 1) {
            return $revision;
        }
        $targetDir = dirname($targetPath);
        $targetDirContent = $server->listDir($targetDir);
        if ($targetDirContent === false) {
            return false;
        }
        if (is_array($targetDirContent) && empty($targetDirContent)) {
            return '-1';
        }
        return false;
    }

    /**
     * Fetches revision of local repository.
{'fraction_non_alphanumeric': 0.12113520996769728, 'fraction_numerical': 0.0027688047992616522, 'mean_word_length': 2.089807555238774, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3847796', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1185, 'n_words': 285}