Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior of TypedPropertyFromAssignsRector #8296

Closed
staabm opened this issue Nov 8, 2023 · 5 comments · Fixed by rectorphp/rector-src#5314
Closed

Incorrect behavior of TypedPropertyFromAssignsRector #8296

staabm opened this issue Nov 8, 2023 · 5 comments · Fixed by rectorphp/rector-src#5314
Assignees
Labels

Comments

@staabm
Copy link
Contributor

staabm commented Nov 8, 2023

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/9dae40b0-c632-4c38-a96c-4490c5b54f3c

<?php

final class PaypalRepository
{
    /**
     * @var string
     */
    private $apiUrl;

    public function __construct()
    {
        if (rand(0,1)) {
            $this->apiUrl = 'https://example.com/';
        } else {
            $this->apiUrl = 'https://another.example.com/';
        }
    }
}

Responsible rules

  • TypedPropertyFromAssignsRector

Expected Behavior

the created property type should be non-nullable and without a default value

@staabm staabm added the bug label Nov 8, 2023
@samsonasik
Copy link
Member

A service to get type by if else only with same assignment single property seems needed.

For note: the implementation need to be carefully applied, eg, start with only assign 2 times in if and else in whole class inside first level statement of __construct.

I will look into it.

@samsonasik samsonasik self-assigned this Nov 8, 2023
@TomasVotruba
Copy link
Member

@samsonasik Could you add this one? Should be only simple if/else check, keep it simple

@samsonasik
Copy link
Member

I will try

@samsonasik
Copy link
Member

@staabm
Copy link
Contributor Author

staabm commented Dec 3, 2023

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants