<commit_before><?php

namespace Adldap\Log;

use Psr\Log\LoggerInterface;
use Adldap\Auth\Events\Failed;
use Adldap\Auth\Events\Event as AuthEvent;
use Adldap\Models\Events\Event as ModelEvent;

class EventLogger
{
    /**
     * The logger instance.
     *
     * @var LoggerInterface|null
     */
    protected $logger;

    /**
     * Constructor.
     *
     * @param LoggerInterface $logger
     */
    public function __construct(LoggerInterface $logger = null)
    {
        $this->logger = $logger;
    }

    /**
     * Logs an authentication event.
     *
     * @param AuthEvent $event
     *
     * @return void
     */
    public function auth(AuthEvent $event)
    {
        if (isset($this->logger)) {
            $type = is_a($event, Failed::class) ? 'warning' : 'info';

            $operation = get_class($event);

            $message = "LDAP ({$event->connection->getHost()}) - Operation: {$operation} - Username: {$event->username} - Result: {$event->connection->getLastError()}";

            $this->logger->$type($message);
        }
    }

    /**
     * Logs a model event.
     *
     * @param ModelEvent $event
     *
     * @return void
     */
    public function model(ModelEvent $event)
    {
        if (isset($this->logger)) {
            $operation = get_class($event);

            $on = get_class($event->model);

            $connection = $event->model->getQuery()->getConnection();

            $message = "LDAP ({$connection->getHost()}) - Operation: {$operation} - On: {$on} - Distinguished Name: {$event->model->getDn()}";

            $this->logger->info($message);
        }
    }
}<commit_msg>Use new methods.<commit_after><?php

namespace Adldap\Log;

use Psr\Log\LoggerInterface;
use Adldap\Auth\Events\Failed;
use Adldap\Auth\Events\Event as AuthEvent;
use Adldap\Models\Events\Event as ModelEvent;

class EventLogger
{
    /**
     * The logger instance.
     *
     * @var LoggerInterface|null
     */
    protected $logger;

    /**
     * Constructor.
     *
     * @param LoggerInterface $logger
     */
    public function __construct(LoggerInterface $logger = null)
    {
        $this->logger = $logger;
    }

    /**
     * Logs an authentication event.
     *
     * @param AuthEvent $event
     *
     * @return void
     */
    public function auth(AuthEvent $event)
    {
        if (isset($this->logger)) {
            $type = is_a($event, Failed::class) ? 'warning' : 'info';

            $operation = get_class($event);

            $message = "LDAP ({$event->getConnection()->getHost()})"
                . " - Operation: {$operation}"
                . " - Username: {$event->getUsername()}"
                . " - Result: {$event->getConnection()->getLastError()}";

            $this->logger->$type($message);
        }
    }

    /**
     * Logs a model event.
     *
     * @param ModelEvent $event
     *
     * @return void
     */
    public function model(ModelEvent $event)
    {
        if (isset($this->logger)) {
            $operation = get_class($event);

            $model = $event->getModel();

            $on = get_class($model);

            $connection = $model->getQuery()->getConnection();

            $message = "LDAP ({$connection->getHost()})"
                . " - Operation: {$operation}"
                . " - On: {$on}"
                . " - Distinguished Name: {$model->getDn()}";

            $this->logger->info($message);
        }
    }
}
{'fraction_non_alphanumeric': 0.15789473684210525, 'fraction_numerical': 0.0, 'mean_word_length': 1.9502572898799313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '7213472', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1012, 'n_words': 202}