<commit_before><?php
namespace Psalm\Tests;

use const DIRECTORY_SEPARATOR;
use Psalm\Config;
use Psalm\Context;

class PropertyTypeTest extends TestCase
{
    use Traits\InvalidCodeAnalysisTestTrait;
    use Traits\ValidCodeAnalysisTestTrait;

    /**
     * @return void
     */
    public function testForgetPropertyAssignments()
    {
        $this->expectExceptionMessage('NullableReturnStatement');
        $this->expectException(\Psalm\Exception\CodeException::class);
        Config::getInstance()->remember_property_assignments_after_call = false;

        $this->addFile(
            'somefile.php',
            '<?php
                class X {
                    /** @var ?int **/
                    private $x;

                    public function getX(): int {
                        $this->x = 5;

                        $this->modifyX();

                        return $this->x;
                    }

                    private function modifyX(): void {
                        $this->x = null;
                    }
                }'
        );

        $this->analyzeFile('somefile.php', new Context());
    }

    /**
     * @return void
     */
    public function testForgetPropertyAssignmentsInBranchWithThrow()
    {
        Config::getInstance()->remember_property_assignments_after_call = false;

        $this->addFile(
            'somefile.php',
            '<?php
                class X {
                    /** @var ?int **/
                    private $x;

                    public function getX(): int {
                        $this->x = 5;

                        if (rand(0, 1)) {
                            $this->modifyX();
                            throw new \Exception("bad");
                        }

                        return $this->x;
                    }

                    private function modifyX(): void {
                        $this->x = null;
                    }
                }'
        );

        $this->analyzeFile('somefile.php', new Context());<commit_msg>Fix call to impure function<commit_after><?php
namespace Psalm\Tests;

use const DIRECTORY_SEPARATOR;
use Psalm\Config;
use Psalm\Context;

class PropertyTypeTest extends TestCase
{
    use Traits\InvalidCodeAnalysisTestTrait;
    use Traits\ValidCodeAnalysisTestTrait;

    /**
     * @return void
     */
    public function testForgetPropertyAssignments()
    {
        $this->expectExceptionMessage('NullableReturnStatement');
        $this->expectException(\Psalm\Exception\CodeException::class);
        Config::getInstance()->remember_property_assignments_after_call = false;

        $this->addFile(
            'somefile.php',
            '<?php
                class X {
                    /** @var ?int **/
                    private $x;

                    public function getX(): int {
                        $this->x = 5;

                        $this->modifyX();

                        return $this->x;
                    }

                    private function modifyX(): void {
                        $this->x = null;
                    }
                }'
        );

        $this->analyzeFile('somefile.php', new Context());
    }

    /**
     * @return void
     */
    public function testForgetPropertyAssignmentsInBranchWithThrow()
    {
        Config::getInstance()->remember_property_assignments_after_call = false;

        $this->addFile(
            'somefile.php',
            '<?php
                class X {
                    /** @var ?int **/
                    private $x;

                    public function getX(bool $b): int {
                        $this->x = 5;

                        if ($b) {
                            $this->modifyX();
                            throw new \Exception("bad");
                        }

                        return $this->x;
                    }

                    private function modifyX(): void {
                        $this->x = null;
                    }
                }'
        );

        $this->analyzeFile('somefile.php', new Context());
{'fraction_non_alphanumeric': 0.10812789846228948, 'fraction_numerical': 0.001464486209421528, 'mean_word_length': 1.169401799894124, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, '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': '91354', 'n_tokens_mistral': 1057, 'n_tokens_neox': 959, 'n_words': 191}