<commit_before><?php

namespace Vladimino\Geo\Client;

use Vladimino\Geo\Console\EscapeColors;
use Vladimino\Geo\Provider\GeoProviderFactory;

/**
 * Class GeoClient
 *
 * @package Vladimino\Geo\Client
 * @author vladimino
 */
class GeoClient
{
    /**
     * Version
     */
    const VERSION = '0.1';

    /**
     * Version
     */
    const NAME = 'GeoCoder Console Application';

    /**
     * @var string
     */
    protected $sProviderName = 'google';

    /**
     * @var string
     */
    protected $sLocation;

    /**
     * @var \Vladimino\Geo\Provider\GeoProviderInterface
     */
    protected $oProvider;

    /**
     * @var \Vladimino\Geo\Entity\ResultCollection
     */
    protected $oResultCollection;

    /**
     * Allowed short options
     *
     * @var array
     */
    protected $aShortOptions = [
        "l:",
        "p:",
        "f:",
        "h"
    ];

    /**
     * Allowed long options
     *
     * @var array
     */
    protected $aLongOptions = [
        "location:",
        "provider:",
        "format:",
        "help"
    ];

    /**
     * @var string
     */
    protected $sCommand;

    public function __construct()
    {
        $this->handleRequest();
    }

    /**
     * Gets the name of the application.
     *
     * @return string The application name
     */
    public function getName()
    {
        return self::NAME;
    }

    /**
     * Gets the application version.
     *
     * @return string The application version
     */
    public function getVersion()
    {
        return self::VERSION;
    }

    /**
     * Gets given command
     *
     * @return string|null Given command
     */
    protected function getCommand()
    {
        return $this->sCommand;
    }

    /**
     * @param string $sCommand
     */
    protected function setCommand($sCommand)
    {
        $this->sCommand = $sCommand;
    }

    /**
     * @return \Vladimino\Geo\Provider\GeoProviderInterface
     */
    private function getProviderObject()
    {
        try {
            if (is_null($this->oProvider)) {
                $this->oProvider = GeoProviderFactory::getProvider($this->sProviderName);
            }
            return $this->oProvider;
        } catch (\Exception $e) {
            $this->terminate($e->getMessage());
        }

    }

    /**
     * @return \Vladimino\Geo\Entity\ResultCollection
     * @throws \Exception if can't get results
     */
    public function getResultsByLocation()
    {
        try {
            $this->oResultCollection = $this->getProviderObject()->getResultsByLocation($this->sLocation);
            return $this->oResultCollection;
        } catch (\Exception $e) {
            $this->terminate($e->getMessage());
        }
    }

    protected function printGeoResults()
    {

        //if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        //    echo 'This is a server using Windows!';
        //} else {
        //    echo 'This is a server not using Windows!';
        //}

        if ($this->oResultCollection) {
            printf("Given Location '%s' with provider '%s'.\n", $this->oResultCollection->sLocation, $this->oResultCollection->sProvider);
            printf("Found %d result(s).\n\n", $this->oResultCollection->iCount);

            /** @var \Vladimino\Geo\Entity\Result $oResult */
            foreach ($this->oResultCollection as $oResult) {
                printf("* Result #%d:\n", $this->oResultCollection->iPosition + 1);
                printf("\t** Country: %s;\n", $oResult->sCountry);
                printf("\t** State: %s;\n", $oResult->sState);
                printf("\t** City: %s;\n", $oResult->sCity);
                printf("\t** Longitude: %s;\n", $oResult->fLongitude);
                printf("\t** Latitude: %s.\n\n", $oResult->fLatitude);
            }

        } else {
            print "Unfortunately, no results found\n";
        }
    }

    /**
     * Returns the long version of the application.
     *<commit_msg>Some TODOs added<commit_after><?php

namespace Vladimino\Geo\Client;

use Vladimino\Geo\Console\EscapeColors;
use Vladimino\Geo\Provider\GeoProviderFactory;

/**
 * Class GeoClient
 *
 * @package Vladimino\Geo\Client
 * @author vladimino
 */
class GeoClient
{
    /**
     * Version
     */
    const VERSION = '0.1';

    /**
     * Version
     */
    const NAME = 'GeoCoder Console Application';

    // TODO: Implement Getter & Setter

    /**
     * @var string
     */
    protected $sProviderName = 'google';

    // TODO: Implement Getter & Setter

    /**
     * @var string
     */
    protected $sLocation;

    /**
     * @var \Vladimino\Geo\Provider\GeoProviderInterface
     */
    protected $oProvider;

    /**
     * @var \Vladimino\Geo\Entity\ResultCollection
     */
    protected $oResultCollection;

    /**
     * Allowed short options
     *
     * @var array
     */
    protected $aShortOptions = [
        "l:",
        "p:",
        "f:",
        "h"
    ];

    /**
     * Allowed long options
     *
     * @var array
     */
    protected $aLongOptions = [
        "location:",
        "provider:",
        "format:", // TODO: Implement Format handling
        "help"
    ];

    /**
     * @var string
     */
    protected $sCommand;

    public function __construct()
    {
        $this->handleRequest();
    }

    /**
     * Gets the name of the application.
     *
     * @return string The application name
     */
    public function getName()
    {
        return self::NAME;
    }

    /**
     * Gets the application version.
     *
     * @return string The application version
     */
    public function getVersion()
    {
        return self::VERSION;
    }

    /**
     * Gets given command
     *
     * @return string|null Given command
     */
    protected function getCommand()
    {
        return $this->sCommand;
    }

    /**
     * @param string $sCommand
     */
    protected function setCommand($sCommand)
    {
        $this->sCommand = $sCommand;
    }

    /**
     * @return \Vladimino\Geo\Provider\GeoProviderInterface
     */
    private function getProviderObject()
    {
        try {
            if (is_null($this->oProvider)) {
                $this->oProvider = GeoProviderFactory::getProvider($this->sProviderName);
            }
            return $this->oProvider;
        } catch (\Exception $e) {
            $this->terminate($e->getMessage());
        }

    }

    /**
     * @return \Vladimino\Geo\Entity\ResultCollection
     * @throws \Exception if can't get results
     */
    public function getResultsByLocation()
    {
        try {
            $this->oResultCollection = $this->getProviderObject()->getResultsByLocation($this->sLocation);
            return $this->oResultCollection;
        } catch (\Exception $e) {
            $this->terminate($e->getMessage());
        }
    }

    protected function printGeoResults()
    {

        // TODO: Implement enviroment check
        //if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        //    echo 'This is a server using Windows!';
        //} else {
        //    echo 'This is a server not using Windows!';
        //}

        if ($this->oResultCollection) {
            printf("Given Location '%s' with provider '%s'.\n", $this->oResultCollection->sLocation, $this->oResultCollection->sProvider);
            printf("Found %d result(s).\n\n", $this->oResultCollection->iCount);

            /** @var \Vladimino\Geo\Entity\Result $oResult */
            foreach ($this->oResultCollection as $oResult) {
                printf("* Result #%d:\n", $this->oResultCollection->iPosition + 1);
                printf("\t** Country: %s;\n", $oResult->sCountry);
                printf("\t** State: %s;\n", $oResult->sState);
                printf("\t** City: %s;\n", $oResult->sCity);
                printf("\t** Longitude: %s;\n", $oResult->fLongitude);
                printf("\t** Latitude: %s.\n\n", $oResult->fLatitude);
            }

        } else {
            print "Unfortunately, no results found\n";
        }
    }

    /**
     * Returns the long version of the application.
     *
{'fraction_non_alphanumeric': 0.14465253819615576, 'fraction_numerical': 0.0012321340561853129, 'mean_word_length': 1.7864744249914177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '6186975', 'n_tokens_mistral': 2452, 'n_tokens_neox': 2384, 'n_words': 500}