<commit_before><?php
namespace Atotrukis\MainBundle\Service;

use Doctrine\ORM\EntityManager;

/**
 * Class CityService
 * @package Atotrukis\MainBundle\Service
 */
class CityService
{
    protected $entityManager;


    /**
     * @param EntityManager $entityManager
     */
    public function __construct(EntityManager $entityManager)
    {
        $this->entityManager = $entityManager;
    }

    /**
     * @param $city
     * @param $userId
     */
    public function setCity($city, $userId)
    {
        $user = $this->entityManager->getRepository("AtotrukisMainBundle:User")->
            findOneBy(array('id' => $userId));
        if ($user->getCity() != "NULL") {
            $user->setCity($city);
            $this->entityManager->persist($user);
            $this->entityManager->flush();
        }
    }

    // when in server runs in virtual box this function wont get correct ip
    private function getUserIP($testServer = false)
    {
        if (!$testServer) {
            $client = @$_SERVER['HTTP_CLIENT_IP'];
            $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
            $remote = $_SERVER['REMOTE_ADDR'];

            if (filter_var($client, FILTER_VALIDATE_IP)) {
                $ip = $client;
            } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
                $ip = $forward;
            } else {
                $ip = $remote;
            }

            return $ip;
        } else {
            return '172.16.31.10';
        }
    }



    public function setCityCookie( $city)
    {
        if (!isset($_COOKIE['userCity'])) {
            $cookie_name = "userCity";
            $cookie_value = $city;
            setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
        }
    }
}
<commit_msg>user ip gets from script<commit_after><?php
namespace Atotrukis\MainBundle\Service;

use Doctrine\ORM\EntityManager;

/**
 * Class CityService
 * @package Atotrukis\MainBundle\Service
 */
class CityService
{
    protected $entityManager;


    /**
     * @param EntityManager $entityManager
     */
    public function __construct(EntityManager $entityManager)
    {
        $this->entityManager = $entityManager;
    }

    /**
     * @param $city
     * @param $userId
     */
    public function setCity($city, $userId)
    {
        $user = $this->entityManager->getRepository("AtotrukisMainBundle:User")->
            findOneBy(array('id' => $userId));
        if ($user->getCity() != "NULL") {
            $user->setCity($city);
            $this->entityManager->persist($user);
            $this->entityManager->flush();
        }
    }

    // when in server runs in virtual box this function wont get correct ip
    public function getUserIP($testServer = false)
    {
        if (!$testServer) {
            $client = @$_SERVER['HTTP_CLIENT_IP'];
            $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
            $remote = $_SERVER['REMOTE_ADDR'];

            if (filter_var($client, FILTER_VALIDATE_IP)) {
                $ip = $client;
            } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
                $ip = $forward;
            } else {
                $ip = $remote;
            }

            return $ip;
        } else {
            return '172.16.31.10';
        }
    }



    public function setCityCookie( $city)
    {
        if (!isset($_COOKIE['userCity'])) {
            $cookie_name = "userCity";
            $cookie_value = $city;
            setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
        }
    }
}

{'fraction_non_alphanumeric': 0.13918390162101732, 'fraction_numerical': 0.012297372833985467, 'mean_word_length': 1.970124481327801, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5706458', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1060, 'n_words': 206}