<commit_before><?php

namespace Timiki\Bundle\RpcServerBundle\Handler;

use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
use Timiki\Bundle\RpcServerBundle\JsonRequest;
use Timiki\Bundle\RpcServerBundle\JsonResponse;
use Timiki\Bundle\RpcServerBundle\Mapper\Mapper;
use Timiki\Bundle\RpcServerBundle\Serializer\SerializerInterface;
use Timiki\Bundle\RpcServerBundle\Exceptions;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Timiki\Bundle\RpcServerBundle\Traits\CacheTrait;
use Timiki\Bundle\RpcServerBundle\Traits\EventDispatcherTrait;
use Timiki\Bundle\RpcServerBundle\Traits\StopwatchTrait;
use Timiki\Bundle\RpcServerBundle\Event;

/**
 * RPC handler
 */
class JsonHandler implements ContainerAwareInterface
{
    use ContainerAwareTrait;
    use CacheTrait;
    use StopwatchTrait;
    use EventDispatcherTrait;

    /**
     * Rpc mapper.
     *
     * @var Mapper|null
     */
    protected $mapper;

    /**
     * Serializer.
     *
     * @var SerializerInterface
     */
    protected $serializer;

    /**
     * JsonHandler constructor.
     *
     * @param Mapper $mapper
     * @param SerializerInterface|null $serializer
     */
    public function __construct(Mapper $mapper, SerializerInterface $serializer = null)
    {
        $this->mapper     = $mapper;
        $this->serializer = $serializer;
    }

    /**
     * Is debug.
     *
     * @return bool
     */
    public function isDebug()
    {
        if ($this->container && $this->container->has('kernel')) {
            return $this->container->get('kernel')->isDebug();
        }

        return true;
    }

    /**
     * Get serializer.
     *
     * @return SerializerInterface|null
     */
    public function getSerializer()
    {
        return $this->serializer;
    }

    /**
     * Serialize data.
     *
     * @param $data
     * @return array|string|integer|null|\JsonSerializable
     */
    public function serialize($data)
    {
        if (is_array($data) || is_numeric($data) || is_string($data) || empty($data) || $data instanceof \JsonSerializable) {
            return $data;<commit_msg>Set serialize array;<commit_after><?php

namespace Timiki\Bundle\RpcServerBundle\Handler;

use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
use Timiki\Bundle\RpcServerBundle\JsonRequest;
use Timiki\Bundle\RpcServerBundle\JsonResponse;
use Timiki\Bundle\RpcServerBundle\Mapper\Mapper;
use Timiki\Bundle\RpcServerBundle\Serializer\SerializerInterface;
use Timiki\Bundle\RpcServerBundle\Exceptions;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Timiki\Bundle\RpcServerBundle\Traits\CacheTrait;
use Timiki\Bundle\RpcServerBundle\Traits\EventDispatcherTrait;
use Timiki\Bundle\RpcServerBundle\Traits\StopwatchTrait;
use Timiki\Bundle\RpcServerBundle\Event;

/**
 * RPC handler
 */
class JsonHandler implements ContainerAwareInterface
{
    use ContainerAwareTrait;
    use CacheTrait;
    use StopwatchTrait;
    use EventDispatcherTrait;

    /**
     * Rpc mapper.
     *
     * @var Mapper|null
     */
    protected $mapper;

    /**
     * Serializer.
     *
     * @var SerializerInterface
     */
    protected $serializer;

    /**
     * JsonHandler constructor.
     *
     * @param Mapper $mapper
     * @param SerializerInterface|null $serializer
     */
    public function __construct(Mapper $mapper, SerializerInterface $serializer = null)
    {
        $this->mapper     = $mapper;
        $this->serializer = $serializer;
    }

    /**
     * Is debug.
     *
     * @return bool
     */
    public function isDebug()
    {
        if ($this->container && $this->container->has('kernel')) {
            return $this->container->get('kernel')->isDebug();
        }

        return true;
    }

    /**
     * Get serializer.
     *
     * @return SerializerInterface|null
     */
    public function getSerializer()
    {
        return $this->serializer;
    }

    /**
     * Serialize data.
     *
     * @param $data
     * @return array|string|integer|null|\JsonSerializable
     */
    public function serialize($data)
    {
        if (is_numeric($data) || is_string($data) || empty($data) || $data instanceof \JsonSerializable) {
            return $data;
{'fraction_non_alphanumeric': 0.11273391145595618, 'fraction_numerical': 0.0, 'mean_word_length': 2.9099018733273865, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '775689', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1305, 'n_words': 226}