<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 Brain\Hierarchy\Branch;

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

    /**
     * @inheritdoc
     */
    public function is(\WP_Query $query)
    {
        return $query->is_single();
    }

    /**
     * @inheritdoc
     */
    public function leaves(\WP_Query $query)
    {
        /** @var \WP_Post $post */
        $post = $query->get_queried_object();
        $post instanceof \WP_Post or $post = new \WP_Post((object) ['ID' => 0]);

        $leaves = empty($post->ID) ? ['single'] : ["single-{$post->post_type}", 'single'];

        return $leaves;
    }
}<commit_msg>WP 4.7 compatibility for Single branch<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 Brain\Hierarchy\Branch;

/**
 * @author  <NAME> <<EMAIL>>
 * @license http://opensource.org/licenses/MIT MIT
 * @package Hierarchy
 */
final class BranchSingle implements BranchInterface
{

    /**
     * @inheritdoc
     */
    public function name()
    {
        return 'single';
    }

    /**
     * @inheritdoc
     */
    public function is(\WP_Query $query)
    {
        return $query->is_single();
    }

    /**
     * @inheritdoc
     */
    public function leaves(\WP_Query $query)
    {
        /** @var \WP_Post $post */
        $post = $query->get_queried_object();
        if ( ! $post instanceof \WP_Post) {
            return ['single'];
        }

        $leaves = [
            "single-{$post->post_type}-{$post->post_name}",
            "single-{$post->post_type}",
            'single'
        ];

        $decoded = urldecode($post->post_name);
        if ($decoded !== $post->post_name) {
            array_unshift($leaves, "single-{$post->post_type}-{$decoded}");
        }

        return $leaves;
    }
}
{'fraction_non_alphanumeric': 0.15250637213254037, 'fraction_numerical': 0.001274426508071368, 'mean_word_length': 2.204081632653061, 'pattern_counts': {'":': 0, '<': 17, '<?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': '213515', 'n_tokens_mistral': 730, 'n_tokens_neox': 718, 'n_words': 178}