<commit_before><?php

namespace Hook\Traits;

trait HandlesEvents
{
    /**
     * The event header.
     *
     * @var string
     */
    private $event;

    /**
     * The registered event listeners.
     *
     * @var array
     */
    public $listeners = [];

    /**
     * Register the event and delegate to the appropriate handler.
     *
     * @return void
     */
    private function registerEvent()
    {
        if (array_key_exists($this->event, $this->eventMap)) {
            $this->output = new $this->eventMap[$this->event]($this->payload);
        }
    }

    /**
     * Check if the event is set up to be watched.
     *
     * @return bool
     */
    private function notWatchingEvent()
    {
        if (!array_key_exists($this->event, $this->listeners) && !in_array($this->event, $this->listeners)) {
            if (!empty($this->event)) {
                $this->apiMessages[] = "Not watching $this->event event";
            }

            return true;
        }

        return false;
    }

    /**
     * Set the event listeners.
     *
     * @param array $listeners
     *
     * @return mixed
     */
    public function listen(array $listeners = [])
    {
        if ($this->secret && !$this->authenticated) {
            return false;
        }

        if (empty($listeners)) {
            $listeners = $this->defaultListeners;
        }

        foreach ($listeners as $listener => $callback) {
            if (!in_array($listener, $this->defaultListeners) && !in_array($callback, $this->defaultListeners)) {
                $this->apiMessages[] = "Can't watch an invalid event";

                return false;
            }
        }

        $this->listeners = $listeners;

        if ($this->notWatchingEvent()) {
            return false;
        }

        $this->registerEvent();

        if (isset($this->listeners[$this->event])) {
            call_user_func($this->listeners[$this->event], $this->output->__toString());
        }
    }
}
<commit_msg>fix bug where bit bucket hook wouldnt recognize $secret<commit_after><?php

namespace Hook\Traits;

trait HandlesEvents
{
    /**
     * The event header.
     *
     * @var string
     */
    private $event;

    /**
     * The registered event listeners.
     *
     * @var array
     */
    public $listeners = [];

    /**
     * Register the event and delegate to the appropriate handler.
     *
     * @return void
     */
    private function registerEvent()
    {
        if (array_key_exists($this->event, $this->eventMap)) {
            $this->output = new $this->eventMap[$this->event]($this->payload);
        }
    }

    /**
     * Check if the event is set up to be watched.
     *
     * @return bool
     */
    private function notWatchingEvent()
    {
        if (!array_key_exists($this->event, $this->listeners) && !in_array($this->event, $this->listeners)) {
            if (!empty($this->event)) {
                $this->apiMessages[] = "Not watching $this->event event";
            }

            return true;
        }

        return false;
    }

    /**
     * Set the event listeners.
     *
     * @param array $listeners
     *
     * @return mixed
     */
    public function listen(array $listeners = [])
    {
        if (property_exists($this, 'secret') && isset($this->secret) && !$this->authenticated) {
            return false;
        }

        if (empty($listeners)) {
            $listeners = $this->defaultListeners;
        }

        foreach ($listeners as $listener => $callback) {
            if (!in_array($listener, $this->defaultListeners) && !in_array($callback, $this->defaultListeners)) {
                $this->apiMessages[] = "Can't watch an invalid event";

                return false;
            }
        }

        $this->listeners = $listeners;

        if ($this->notWatchingEvent()) {
            return false;
        }

        $this->registerEvent();

        if (isset($this->listeners[$this->event])) {
            call_user_func($this->listeners[$this->event], $this->output->__toString());
        }
    }
}

{'fraction_non_alphanumeric': 0.1453787693062025, 'fraction_numerical': 0.0, 'mean_word_length': 1.7906976744186047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '1853821', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1156, 'n_words': 254}