<commit_before><?php
namespace Phoebe\Event;

use Phergie\Irc\Client\React\WriteStream;
use Phergie\Irc\Connection;
use Monolog\Logger;

class Command extends Event
{
    protected $message;
    protected $write;
    protected $connection;
    protected $logger;

    public function setMessage($message)
    {
        $this->message = $message;
    }

    public function getMessage()
    {
        return $this->message;
    }

    public function setWriteStream(WriteStream $writeStream)
    {
        $this->write = $writeStream;
    }

    public function getWriteStream()
    {
        return $this->write;
    }

    public function setConnection(Connection $connection)
    {
        $this->connection = $connection;
    }

    public function getConnection()
    {
        return $this->connection;
    }

    public function setLogger(Logger $logger)
    {
        $this->logger = $logger;
    }

    public function getLogger()
    {
        return $this->logger;
    }

    /**
     * Determines whether a given string is a valid IRC channel name.
     *
     * @param string $string String to analyze
     *
     * @return bool TRUE if $string contains a valid channel name, FALSE
     *         otherwise
     */
    protected function isChannelName($string)
    {
        // Per the 2000 RFCs 2811 and 2812, channels may begin with &, #, +, or !
        return (strspn($string, '#&+!', 0, 1) >= 1);
    }

    /**
     * Returns the channel name if the event occurred in a channel or the
     * user nick if the event was a private message directed at the bot by a
     * user.
     *
     * @return string
     */
    public function getSource()
    {
        $msg = $this->getMessage();
        
        if (!empty($msg['targets'])) {
            return $msg['targets'][0];
        }
    }

    /**
     * Returns whether or not the event occurred within a channel.
     *
     * @return TRUE if the event is in a channel, FALSE otherwise
     */
    public function isInChannel()
    {
        return $this->isChannelName($this->getSource());
    }<commit_msg>Fixed getSource() method<commit_after><?php
namespace Phoebe\Event;

use Phergie\Irc\Client\React\WriteStream;
use Phergie\Irc\Connection;
use Monolog\Logger;

class Command extends Event
{
    protected $message;
    protected $write;
    protected $connection;
    protected $logger;

    public function setMessage($message)
    {
        $this->message = $message;
    }

    public function getMessage()
    {
        return $this->message;
    }

    public function setWriteStream(WriteStream $writeStream)
    {
        $this->write = $writeStream;
    }

    public function getWriteStream()
    {
        return $this->write;
    }

    public function setConnection(Connection $connection)
    {
        $this->connection = $connection;
    }

    public function getConnection()
    {
        return $this->connection;
    }

    public function setLogger(Logger $logger)
    {
        $this->logger = $logger;
    }

    public function getLogger()
    {
        return $this->logger;
    }

    /**
     * Determines whether a given string is a valid IRC channel name.
     *
     * @param string $string String to analyze
     *
     * @return bool TRUE if $string contains a valid channel name, FALSE
     *         otherwise
     */
    protected function isChannelName($string)
    {
        // Per the 2000 RFCs 2811 and 2812, channels may begin with &, #, +, or !
        return (strspn($string, '#&+!', 0, 1) >= 1);
    }

    /**
     * Returns the channel name if the event occurred in a channel or the
     * user nick if the event was a private message directed at the bot by a
     * user.
     *
     * @return string
     */
    public function getSource()
    {
        $msg = $this->getMessage();
        
        if (isset($msg['targets'][0]) && $this->isChannelName($msg['targets'][0])) {
            return $msg['targets'][0];
        } else {
            return $msg['nick'];
        }
    }

    /**
     * Returns whether or not the event occurred within a channel.
     *
     * @return TRUE if the event is in a channel, FALSE otherwise
     */
    public function isInChannel()
    {
        return $this->isChannelName($this->getSource());
    }
{'fraction_non_alphanumeric': 0.10954726718273516, 'fraction_numerical': 0.007975604034717336, 'mean_word_length': 2.137601177336277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '4305320', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1190, 'n_words': 364}