<commit_before><?php
namespace Guywithnose\ReleaseNotes\Change;

class ChangeFactory
{
    /** @type callable A function that selects the type for a given change. */
    protected $_typeSelector;

    /**
     * Initialize the change factory with the type selector.
     *
     * The type selector is a function that is passed the change and must return a valid type (@see \Guywithnose\ReleaseNotes\Change::types) or
     * null to use the default type.
     *
     * @param callable $typeSelector The type selector function.
     */
    public function __construct(callable $typeSelector)
    {
        $this->_typeSelector = $typeSelector;
    }

    /**
     * Create the change from a github API commit representation.
     *
     * @param array $commit The commit representation from the github API.
     * @return \Guywithnose\ReleaseNotes\Change|null The change object for the commit, or null if none could be found.
     */
    public function createFromCommit(array $commit)
    {
        $typeSelector = $this->_typeSelector;

        if (count($commit['parents']) > 1) {
            $change = null;
            if (preg_match('/Merge pull request #([0-9]*)[^\n]*\n[^\n]*\n(.*)/s', $commit['commit']['message'], $matches)) {
                $change = new PullRequest((int)$matches[1], $matches[2]);
            } elseif (preg_match('/Merge branch \'([^\']*)\'[^\n]*\n[^\n]*\n(.*)/s', $commit['commit']['message'], $matches)) {
                $change = new Merge($matches[1], $matches[2]);
            } else {
                $change = new Change($commit['commit']['message']);
            }
        } else {<commit_msg>Make typeSelector optional for ChangeFactory.<commit_after><?php
namespace Guywithnose\ReleaseNotes\Change;

class ChangeFactory
{
    /** @type callable A function that selects the type for a given change. */
    protected $_typeSelector;

    /**
     * Initialize the change factory with the type selector.
     *
     * The type selector is a function that is passed the change and must return a valid type (@see \Guywithnose\ReleaseNotes\Change::types) or
     * null to use the default type.
     *
     * @param callable $typeSelector The type selector function.
     */
    public function __construct(callable $typeSelector = null)
    {
        $this->_typeSelector = $typeSelector ?: function(Change $change) {
            return $change->getType();
        };
    }

    /**
     * Create the change from a github API commit representation.
     *
     * @param array $commit The commit representation from the github API.
     * @return \Guywithnose\ReleaseNotes\Change|null The change object for the commit, or null if none could be found.
     */
    public function createFromCommit(array $commit)
    {
        $typeSelector = $this->_typeSelector;

        if (count($commit['parents']) > 1) {
            $change = null;
            if (preg_match('/Merge pull request #([0-9]*)[^\n]*\n[^\n]*\n(.*)/s', $commit['commit']['message'], $matches)) {
                $change = new PullRequest((int)$matches[1], $matches[2]);
            } elseif (preg_match('/Merge branch \'([^\']*)\'[^\n]*\n[^\n]*\n(.*)/s', $commit['commit']['message'], $matches)) {
                $change = new Merge($matches[1], $matches[2]);
            } else {
                $change = new Change($commit['commit']['message']);
            }
        } else {
{'fraction_non_alphanumeric': 0.14408284023668638, 'fraction_numerical': 0.004142011834319527, 'mean_word_length': 2.589171974522293, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '3802213', 'n_tokens_mistral': 956, 'n_tokens_neox': 922, 'n_words': 283}