<commit_before><?php

/**
 * Created by PhpStorm.
 * User: <NAME>
 * Date: 2015/07/06
 * Time: 1:56 PM.
 */

namespace Repository;

use Elasticsearch\Common\Exceptions\Serializer\JsonErrorException;
use ESGateway\Factory;
use ESGateway\User;
use Persistency\IPersistency;

/**
 * Class ESGatewayUserRepo.
 */
class ESGatewayUserRepo
{
    /**
     * @param IPersistency $persistency
     * @param Factory      $factory
     */
    public function __construct(IPersistency $persistency, Factory $factory)
    {
        $this->persistency = $persistency;
        $this->factory = $factory;
    }

    /**
     * @return Factory
     */
    public function getFactory()
    {
        return $this->factory;
    }

    /**
     * @param User $user
     */
    public function fire(User $user)
    {
        $this->persistency->persist([$this->factory->toArray($user)]);
    }

    /**
     * @param User[] $list
     */
    public function burst(array $list)
    {
        $users = [];
        foreach ($list as $user) {
            $users[] = $this->factory->toArray($user);
        }
        try {
            $this->persistency->persist($users);
        } catch (JsonErrorException $e) {
            dump($e->getMessage());
            dump($list);
        }
    }
}
<commit_msg>support error reporting<commit_after><?php

/**
 * Created by PhpStorm.
 * User: <NAME>
 * Date: 2015/07/06
 * Time: 1:56 PM.
 */

namespace Repository;

use Elasticsearch\Common\Exceptions\Serializer\JsonErrorException;
use ESGateway\Factory;
use ESGateway\User;
use Persistency\IPersistency;

/**
 * Class ESGatewayUserRepo.
 */
class ESGatewayUserRepo
{
    /**
     * @param IPersistency $persistency
     * @param Factory      $factory
     */
    public function __construct(IPersistency $persistency, Factory $factory)
    {
        $this->persistency = $persistency;
        $this->factory = $factory;
    }

    /**
     * @return Factory
     */
    public function getFactory()
    {
        return $this->factory;
    }

    /**
     * @param User   $user
     * @param string $errorInfo
     *
     * @return bool
     */
    public function fire(User $user, &$errorInfo)
    {
        $list = [$this->factory->toArray($user)];

        return $this->burst($list, $errorInfo);
    }

    /**
     * @param User[] $list
     * @param string $errorString
     *
     * @return bool
     */
    public function burst(array $list, &$errorString)
    {
        $users = [];
        foreach ($list as $user) {
            $users[] = $this->factory->toArray($user);
        }

        $errorString = null;
        try {
            $this->persistency->persist($users);
        } catch (JsonErrorException $e) {
            $errorString = $e->getMessage();
        } catch (\RuntimeException $e) {
            $errorString = $e->getMessage();
        }

        if ($errorString) {
            return false;
        }

        return true;
    }
}

{'fraction_non_alphanumeric': 0.14261344251108837, 'fraction_numerical': 0.007505970658478335, 'mean_word_length': 2.03205791106515, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '5698526', 'n_tokens_mistral': 927, 'n_tokens_neox': 914, 'n_words': 185}