<commit_before><?php
/**
 * @package syrup-component-bundle
 * @copyright 2015 Keboola
 * @author <NAME> <<EMAIL>>
 */

namespace Keboola\Syrup\Monolog\Handler;

use Keboola\StorageApi\Client;
use Keboola\StorageApi\Event;
use Keboola\StorageApi\Exception as SapiException;
use Monolog\Logger;
use Keboola\Syrup\Exception\NoRequestException;
use Keboola\Syrup\Exception\UserException;
use Keboola\Syrup\Service\StorageApi\StorageApiService;

class StorageApiHandler extends \Monolog\Handler\AbstractHandler
{
    /** @var \Keboola\StorageApi\Client */
    protected $storageApiClient;

    /** @var  StorageApiService */
    protected $storageApiService;

    protected $appName;

    public function __construct($appName, StorageApiService $storageApiService)
    {
        $this->appName = $appName;
        $this->storageApiService = $storageApiService;
        parent::__construct();
    }

    protected function initStorageApiClient()
    {
        try {
            $this->storageApiClient = $this->storageApiService->getClient();
        } catch (NoRequestException $e) {
            // Ignore when no SAPI client setup
        } catch (UserException $e) {
            // Ignore when no SAPI client setup
        } catch (SapiException $e) {
            // Ignore when SAPI client setup is wrong
        }
    }

    /** @deprecated StorageApiClient should be obtained via StorageApiService */
    public function setStorageApiClient(Client $client)
    {
        $this->storageApiClient = $client;
    }

    public function handle(array $record)
    {
        $this->initStorageApiClient();

        if (!$this->storageApiClient || $record['level'] == Logger::DEBUG) {
            return false;
        }

        $event = new Event();
        if (!empty($record['component'])) {
            $event->setComponent($record['component']);
        } else {
            $event->setComponent($this->appName);<commit_msg>refactor (StorageApiHandler): removed deprecated setStorageApiClient method<commit_after><?php
/**
 * @package syrup-component-bundle
 * @copyright 2015 Keboola
 * @author <NAME> <<EMAIL>>
 */

namespace Keboola\Syrup\Monolog\Handler;

use Keboola\StorageApi\Event;
use Keboola\StorageApi\Exception as SapiException;
use Monolog\Logger;
use Keboola\Syrup\Exception\NoRequestException;
use Keboola\Syrup\Exception\UserException;
use Keboola\Syrup\Service\StorageApi\StorageApiService;

class StorageApiHandler extends \Monolog\Handler\AbstractHandler
{
    /** @var \Keboola\StorageApi\Client */
    protected $storageApiClient;

    /** @var  StorageApiService */
    protected $storageApiService;

    protected $appName;

    public function __construct($appName, StorageApiService $storageApiService)
    {
        $this->appName = $appName;
        $this->storageApiService = $storageApiService;
        parent::__construct();
    }

    protected function initStorageApiClient()
    {
        try {
            $this->storageApiClient = $this->storageApiService->getClient();
        } catch (NoRequestException $e) {
            // Ignore when no SAPI client setup
        } catch (UserException $e) {
            // Ignore when no SAPI client setup
        } catch (SapiException $e) {
            // Ignore when SAPI client setup is wrong
        }
    }

    public function handle(array $record)
    {
        $this->initStorageApiClient();

        if (!$this->storageApiClient || $record['level'] == Logger::DEBUG) {
            return false;
        }

        $event = new Event();
        if (!empty($record['component'])) {
            $event->setComponent($record['component']);
        } else {
            $event->setComponent($this->appName);
{'fraction_non_alphanumeric': 0.11747151383613673, 'fraction_numerical': 0.002170374389582203, 'mean_word_length': 2.8647798742138364, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 30, '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': '133254', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1041, 'n_words': 223}