<commit_before><?php
/*
 * This file is part of the Hierarchy package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace GM\Hierarchy\Branch;

/**
 * @author  <NAME> <<EMAIL>>
 * @license http://opensource.org/licenses/MIT MIT
 * @package Hierarchy
 */
final class BranchPostTypeArchive implements BranchInterface
{
    /**
     * @inheritdoc
     */
    public function name()
    {
        return 'archive';
    }

    /**
     * @inheritdoc
     */
    public function is(\WP_Query $query)
    {
        if (! $query->is_post_type_archive()) {
            return false;
        }

        $object = get_post_type_object($this->postType($query));

        return is_object($object) && ! empty($object->has_archive);
    }

    /**
     * @inheritdoc
     */
    public function leaves(\WP_Query $query)
    {
        $type = $this->postType($query);

        return $type ? ["archive-{$type}", 'archive'] : ['archive'];
    }

    /**
     * @param  \WP_Query    $query
     * @return mixed|string
     */
    private function postType(\WP_Query $query)
    {
        $type = $query->get('post_type');
        if (is_array($type)) {
            $type = reset($post_type);
        }

        return is_string($type) ? $type : '';
    }
}<commit_msg>Make BranchPostTypeArchive methods more solid<commit_after><?php
/*
 * This file is part of the Hierarchy package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace GM\Hierarchy\Branch;

/**
 * @author  <NAME> <<EMAIL> <EMAIL>>
 * @license http://opensource.org/licenses/MIT MIT
 * @package Hierarchy
 */
final class BranchPostTypeArchive implements BranchInterface
{
    /**
     * @inheritdoc
     */
    public function name()
    {
        return 'archive';
    }

    /**
     * @inheritdoc
     */
    public function is(\WP_Query $query)
    {
        return $query->is_post_type_archive() && $this->postType($query);
    }

    /**
     * @inheritdoc
     */
    public function leaves(\WP_Query $query)
    {
        $type = $this->postType($query);

        return $type ? ["archive-{$type}", 'archive'] : ['archive'];
    }

    /**
     * @param  \WP_Query    $query
     * @return mixed|string
     */
    private function postType(\WP_Query $query)
    {
        $type = $query->get('post_type');
        is_array($type) and $type = reset($post_type);

        $object = get_post_type_object($type);
        (is_object($object) && $object->has_archive) or $type = '';

        return $type;
    }
}
{'fraction_non_alphanumeric': 0.14929785661492978, 'fraction_numerical': 0.0, 'mean_word_length': 2.358560794044665, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 26, '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': '5433333', 'n_tokens_mistral': 836, 'n_tokens_neox': 822, 'n_words': 196}