<commit_before><?php declare(strict_types=1);

namespace Symplify\CodingStandard\Tokenizer;

use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Tokenizer\TokensAnalyzer;
use Symplify\CodingStandard\Exception\UnexpectedTokenException;

final class ClassTokensAnalyzer
{
    /**
     * @var int
     */
    private $endBracketIndex;

    /**
     * @var TokensAnalyzer
     */
    private $tokensAnalyzer;

    private function __construct(Tokens $tokens, int $startIndex)
    {
        $this->ensureIsClassyToken($tokens[$startIndex]);

        $startBracketIndex = $tokens->getNextTokenOfKind($startIndex, ['{']);
        $this->endBracketIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startBracketIndex);

        $this->tokensAnalyzer = new TokensAnalyzer($tokens);
    }

    public static function createFromTokensArrayStartPosition(Tokens $tokens, int $startIndex): self
    {
        return new self($tokens, $startIndex);
    }

    /**
     * @return mixed[]
     */
    public function getPropertiesAndConstants(): array
    {
        return $this->filterClassyTokens($this->tokensAnalyzer->getClassyElements(), ['property', 'const']);
    }

    public function getClassEnd(): int
    {
        return $this->endBracketIndex;
    }

    /**
     * @return mixed[]
     */
    public function getProperties(): array
    {
        return $this->filterClassyTokens($this->tokensAnalyzer->getClassyElements(), ['property']);
    }

    /**
     * @return mixed[]
     */
    public function getLastPropertyPosition(): ?int
    {
        $properties = $this->getProperties();
        if ($properties === 0) {
            return null;
        }

        end($properties);

        return key($properties);
    }

    /**
     * @return mixed[]
     */
    public function getFirstMethodPosition(): ?int
    {
        $methods = $this->getMethods();
        if ($methods === 0) {
            return null;
        }

        end($methods);

        return key($methods);
    }

    /**
     * @return mixed[]
     */
    private function getMethods(): array
    {<commit_msg>cs and phpstan fixes<commit_after><?php declare(strict_types=1);

namespace Symplify\CodingStandard\Tokenizer;

use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Tokenizer\TokensAnalyzer;
use Symplify\CodingStandard\Exception\UnexpectedTokenException;

final class ClassTokensAnalyzer
{
    /**
     * @var int
     */
    private $endBracketIndex;

    /**
     * @var TokensAnalyzer
     */
    private $tokensAnalyzer;

    private function __construct(Tokens $tokens, int $startIndex)
    {
        $this->ensureIsClassyToken($tokens[$startIndex]);

        $startBracketIndex = $tokens->getNextTokenOfKind($startIndex, ['{']);
        $this->endBracketIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startBracketIndex);

        $this->tokensAnalyzer = new TokensAnalyzer($tokens);
    }

    public static function createFromTokensArrayStartPosition(Tokens $tokens, int $startIndex): self
    {
        return new self($tokens, $startIndex);
    }

    /**
     * @return mixed[]
     */
    public function getPropertiesAndConstants(): array
    {
        return $this->filterClassyTokens($this->tokensAnalyzer->getClassyElements(), ['property', 'const']);
    }

    public function getClassEnd(): int
    {
        return $this->endBracketIndex;
    }

    /**
     * @return mixed[]
     */
    public function getProperties(): array
    {
        return $this->filterClassyTokens($this->tokensAnalyzer->getClassyElements(), ['property']);
    }

    public function getLastPropertyPosition(): ?int
    {
        $properties = $this->getProperties();
        if ($properties === []) {
            return null;
        }

        end($properties);

        return key($properties);
    }

    public function getFirstMethodPosition(): ?int
    {
        $methods = $this->getMethods();
        if ($methods === []) {
            return null;
        }

        end($methods);

        return key($methods);
    }

    /**
     * @return mixed[]
     */
    private function getMethods(): array
    {
{'fraction_non_alphanumeric': 0.1312574850299401, 'fraction_numerical': 0.0009580838323353293, 'mean_word_length': 2.695575221238938, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '2274655', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1190, 'n_words': 223}