<commit_before><?php

namespace Application\Hydrator\Api;

use Traversable;

use Zend\Hydrator\Strategy\DateTimeFormatterStrategy;
use Zend\Stdlib\ArrayUtils;

use Autowp\User\Model\User;

class TrafficHydrator extends RestHydrator
{
    /**
     * @var int|null
     */
    protected $userId = null;

    private $acl;

    private $router;

    /**
     * @var User
     */
    private $userModel;

    public function __construct($serviceManager)
    {
        parent::__construct();

        $this->router = $serviceManager->get('HttpRouter');
        $this->acl = $serviceManager->get(\Zend\Permissions\Acl\Acl::class);
        $this->userModel = $serviceManager->get(\Autowp\User\Model\User::class);

        $strategy = new DateTimeFormatterStrategy();
        $this->addStrategy('up_to', $strategy);

        $strategy = new Strategy\User($serviceManager);
        $this->addStrategy('ban_user', $strategy);
    }

    /**
     * @param  array|Traversable $options
     * @return RestHydrator
     * @throws \Zend\Hydrator\Exception\InvalidArgumentException
     */
    public function setOptions($options)
    {
        parent::setOptions($options);

        if ($options instanceof \Traversable) {
            $options = ArrayUtils::iteratorToArray($options);
        } elseif (! is_array($options)) {
            throw new \Zend\Hydrator\Exception\InvalidArgumentException(
                'The options parameter must be an array or a Traversable'
            );
        }

        if (isset($options['user_id'])) {
            $this->setUserId($options['user_id']);
        }

        return $this;
    }

    public function extract($object)
    {
        /*$row['users'] = $users->fetchAll([
            'last_ip = inet_aton(inet6_ntoa(?))' => $row['ip']
        ]);*/

        if ($object['ban']) {
            $date = \Autowp\Commons\Db\Table\Row::getDateTimeByColumnType('timestamp', $object['ban']['up_to']);
            $object['ban']['up_to'] = $this->extractValue('up_to', $date);
            $object['ban']['user'] = null;
            if ($object['ban']['by_user_id']) {
                $user = $this->userModel->getRow((int) $object['ban']['by_user_id']);
                if ($user) {
                    $object['ban']['user'] = $this->extractValue('ban_user', $user);
                }
            }
        }

        $object['whois_url'] = 'http://nic.ru/whois/?query='.urlencode($object['ip']);
        unset($object['ban']['ip']);


        return $object;
    }<commit_msg>Don't reparse date<commit_after><?php

namespace Application\Hydrator\Api;

use Traversable;

use Zend\Stdlib\ArrayUtils;

use Autowp\User\Model\User;

class TrafficHydrator extends RestHydrator
{
    /**
     * @var int|null
     */
    protected $userId = null;

    private $acl;

    private $router;

    /**
     * @var User
     */
    private $userModel;

    public function __construct($serviceManager)
    {
        parent::__construct();

        $this->router = $serviceManager->get('HttpRouter');
        $this->acl = $serviceManager->get(\Zend\Permissions\Acl\Acl::class);
        $this->userModel = $serviceManager->get(\Autowp\User\Model\User::class);

        $strategy = new Strategy\User($serviceManager);
        $this->addStrategy('ban_user', $strategy);
    }

    /**
     * @param  array|Traversable $options
     * @return RestHydrator
     * @throws \Zend\Hydrator\Exception\InvalidArgumentException
     */
    public function setOptions($options)
    {
        parent::setOptions($options);

        if ($options instanceof \Traversable) {
            $options = ArrayUtils::iteratorToArray($options);
        } elseif (! is_array($options)) {
            throw new \Zend\Hydrator\Exception\InvalidArgumentException(
                'The options parameter must be an array or a Traversable'
            );
        }

        if (isset($options['user_id'])) {
            $this->setUserId($options['user_id']);
        }

        return $this;
    }

    public function extract($object)
    {
        /*$row['users'] = $users->fetchAll([
            'last_ip = inet_aton(inet6_ntoa(?))' => $row['ip']
        ]);*/

        if ($object['ban']) {
            $object['ban']['up_to'] = $object['ban']['up_to'];
            $object['ban']['user'] = null;
            if ($object['ban']['by_user_id']) {
                $user = $this->userModel->getRow((int) $object['ban']['by_user_id']);
                if ($user) {
                    $object['ban']['user'] = $this->extractValue('ban_user', $user);
                }
            }
        }

        $object['whois_url'] = 'http://nic.ru/whois/?query='.urlencode($object['ip']);
        unset($object['ban']['ip']);


        return $object;
    }
{'fraction_non_alphanumeric': 0.16617336152219872, 'fraction_numerical': 0.00042283298097251583, 'mean_word_length': 2.338743824982357, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '6961324', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1398, 'n_words': 227}