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

MixedArgument for checked second array offset in 3.11.0 #3128

Closed
vudaltsov opened this issue Apr 12, 2020 · 3 comments
Closed

MixedArgument for checked second array offset in 3.11.0 #3128

vudaltsov opened this issue Apr 12, 2020 · 3 comments
Labels

Comments

@vudaltsov
Copy link
Contributor

https://psalm.dev/r/2284b270fa
The strange thing about this case is that the first array offset passes.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/2284b270fa
<?php

/**
 * @todo psalm-immutable
 */
final class StudyJwtPayload
{
    public const USER_ID = 'usrid';
    public const STUDY_ID = 'studid';
    
    public string $userId;
    public string $studyId;

    public function __construct(string $userId, string $studyId)
    {
        $this->userId = $userId;
        $this->studyId = $studyId;
    }

    public static function fromClaims(array $claims): self
    {
        if (!isset($claims[self::USER_ID])) {
            throw new \InvalidArgumentException();
        }

        if (!\is_string($claims[self::USER_ID])) {
            throw new \InvalidArgumentException();
        }

        if (!isset($claims[self::STUDY_ID])) {
            throw new \InvalidArgumentException();
        }

        if (!\is_string($claims[self::STUDY_ID])) {
            throw new \InvalidArgumentException();
        }

        return new self($claims[self::USER_ID], $claims[self::STUDY_ID]);
    }
}
Psalm output (using commit 5bc9b09):

INFO: MixedArgument - 38:49 - Argument 2 of StudyJwtPayload::__construct cannot be mixed, expecting string

@vudaltsov vudaltsov changed the title MixedArgument for checked second array offset MixedArgument for checked second array offset in 3.11.0 Apr 12, 2020
@muglug
Copy link
Collaborator

muglug commented Apr 12, 2020

It's an issue with class constant offsets – explicit strings work fine: https://psalm.dev/r/772d804019

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/772d804019
<?php

/**
 * @todo psalm-immutable
 */
final class StudyJwtPayload
{
    public const USER_ID = 'usrid';
    public const STUDY_ID = 'studid';
    
    public string $userId;
    public string $studyId;

    public function __construct(string $userId, string $studyId)
    {
        $this->userId = $userId;
        $this->studyId = $studyId;
    }

    public static function fromClaims(array $claims): self
    {
        if (!isset($claims['usrid'])) {
            throw new \InvalidArgumentException();
        }

        if (!\is_string($claims['usrid'])) {
            throw new \InvalidArgumentException();
        }

        if (!isset($claims['studid'])) {
            throw new \InvalidArgumentException();
        }

        if (!\is_string($claims['studid'])) {
            throw new \InvalidArgumentException();
        }

        return new self($claims['usrid'], $claims['studid']);
    }
}
Psalm output (using commit 5bc9b09):

No issues!

@muglug muglug added the bug label Apr 12, 2020
@muglug muglug closed this as completed in 73f8f96 Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants