<commit_before><?php
namespace Yandex\Geo;

/**
 * Class GeoObject
 * @package Yandex\Geo
 * @author <NAME> <<EMAIL>>
 * @license The MIT License (MIT)
 */
class GeoObject
{
    protected $_data;

    public function __construct(array $data)
    {
        $this->_data = $data;
    }

    public function __sleep()
    {
        return array('_data');
    }

    /**
     * Исходные данные
     * @return array
     */
    public function getData()
    {
        return $this->_data;
    }

    /**
     * Широта в градусах. Имеет десятичное представление с точностью до семи знаков после запятой
     * @return float|null
     */
    public function getLatitude()
    {
        $result = null;
        if (isset($this->_data['Point']['pos'])) {
            list(, $latitude) = explode(' ', $this->_data['Point']['pos']);
            $result = (float)$latitude;
        }
        return $result;
    }

    /**
     * Долгота в градусах. Имеет десятичное представление с точностью до семи знаков после запятой
     * @return float|null
     */
    public function getLongitude()
    {
        $result = null;
        if (isset($this->_data['Point']['pos'])) {
            list($longitude, ) = explode(' ', $this->_data['Point']['pos']);
            $result = (float)$longitude;
        }
        return $result;
    }

    /**
     * Полный адрес
     * @return string|null
     */
    public function getAddress()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['text'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['text'];
        }
        return $result;
    }

    /**
     * Страна
     * @return string|null
     */
    public function getCountry()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['CountryName'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['CountryName'];
        }
        return $result;
    }

    /**
     * Код страны
     * @return string|null
     */
    public function getCountryCode()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['CountryNameCode'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['CountryNameCode'];
        }
        return $result;
    }

    /**
     * Административный округ
     * @return string|null
     */
    public function getAdministrativeAreaName()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName'];
        }
        return $result;
    }

    /**
     * @return string|null
     */
    public function getSubAdministrativeAreaName()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName'];
        }
        return $result;
    }

    /**
     * @return string|null
     */
    public function getLocalityName()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName'];
        }
        elseif(isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['Locality']['LocalityName'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['Locality']['LocalityName'];
        }
        return $result;
    }

    /**
     * @return string|null
     */
    public function getDependentLocalityName()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['DependentLocalityName'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['DependentLocalityName'];
        }
        return $result;
    }

    /**
     * @return string|null
     */
    public function getThoroughfareName()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['Thoroughfare']['ThoroughfareName'])) {
            $result = $this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['Thoroughfare']['ThoroughfareName'];
        }
        return $result;
    }

    /**
     * @return int|null
     */
    public function getPremiseNumber()
    {
        $result = null;
        if (isset($this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['Thoroughfare']['Premise']['PremiseNumber'])) {
            $result = (int)$this->_data['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['Thoroughfare']['Premise']['PremiseNumber'];
        }
        return $result;
    }
}<commit_msg>Better approach to get data from response<commit_after><?php
namespace Yandex\Geo;

/**
 * Class GeoObject
 * @package Yandex\Geo
 * @author <NAME> <<EMAIL>>
 * @license The MIT License (MIT)
 */
class GeoObject
{
    protected $_data;
    protected $_rawData;

    public function __construct(array $rawData)
    {
        $data = array(
            'Address' => $rawData['metaDataProperty']['GeocoderMetaData']['text'],
        );
        array_walk_recursive($rawData, function($value, $key) use(&$data) {
            if (in_array($key, array('CountryName', 'CountryNameCode', 'AdministrativeAreaName', 'SubAdministrativeArea', 'LocalityName', 'DependentLocalityName', 'ThoroughfareName', 'PremiseNumber'))) {
                $data[$key] = $value;
            }
        });
        if (isset($rawData['Point']['pos'])) {
            $pos = explode(' ', $rawData['Point']['pos']);
            $data['Longitude'] = (float)$pos[0];
            $data['Latitude'] = (float)$pos[1];
        }
        $this->_data = $data;
        $this->_rawData = $rawData;
    }

    public function __sleep()
    {
        return array('_data');
    }

    /**
     * Необработанные данные
     * @return array
     */
    public function getRawData()
    {
        return $this->_rawData;
    }
    
    /**
     * Обработанные данные
     * @return array
     */
    public function getData()
    {
        return $this->_data;
    }

    /**
     * Широта в градусах. Имеет десятичное представление с точностью до семи знаков после запятой
     * @return float|null
     */
    public function getLatitude()
    {
        return isset($this->_data['Latitude']) ? $this->_data['Latitude'] : null;
    }

    /**
     * Долгота в градусах. Имеет десятичное представление с точностью до семи знаков после запятой
     * @return float|null
     */
    public function getLongitude()
    {
        return isset($this->_data['Longitude']) ? $this->_data['Longitude'] : null;
    }

    /**
     * Полный адрес
     * @return string|null
     */
    public function getAddress()
    {
        return isset($this->_data['Address']) ? $this->_data['Address'] : null;
    }

    /**
     * Страна
     * @return string|null
     */
    public function getCountry()
    {
        return isset($this->_data['CountryName']) ? $this->_data['CountryName'] : null;
    }

    /**
     * Код страны
     * @return string|null
     */
    public function getCountryCode()
    {
        return isset($this->_data['CountryNameCode']) ? $this->_data['CountryNameCode'] : null;
    }

    /**
     * Административный округ
     * @return string|null
     */
    public function getAdministrativeAreaName()
    {
        return isset($this->_data['AdministrativeAreaName']) ? $this->_data['AdministrativeAreaName'] : null;
    }

    /**
     * @return string|null
     */
    public function getSubAdministrativeAreaName()
    {
        return isset($this->_data['SubAdministrativeAreaName']) ? $this->_data['SubAdministrativeAreaName'] : null;
    }

    /**
     * @return string|null
     */
    public function getLocalityName()
    {
        return isset($this->_data['LocalityName']) ? $this->_data['LocalityName'] : null;
    }

    /**
     * @return string|null
     */
    public function getDependentLocalityName()
    {
        return isset($this->_data['DependentLocalityName']) ? $this->_data['DependentLocalityName'] : null;
    }

    /**
     * @return string|null
     */
    public function getThoroughfareName()
    {
        return isset($this->_data['ThoroughfareName']) ? $this->_data['ThoroughfareName'] : null;
    }

    /**
     * @return int|null
     */
    public function getPremiseNumber()
    {
        return isset($this->_data['PremiseNumber']) ? $this->_data['PremiseNumber'] : null;
    }
}
{'fraction_non_alphanumeric': 0.16619404496657889, 'fraction_numerical': 0.00020255215718047398, 'mean_word_length': 3.004460665044607, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 62, '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': '1532970', 'n_tokens_mistral': 2836, 'n_tokens_neox': 2864, 'n_words': 444}