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

[Php73] Skip JsonThrowOnErrorRector on passed exact value #1051

Merged
merged 6 commits into from
Oct 24, 2021

Conversation

samsonasik
Copy link
Member

Given the following code:

function skipExactValue(){
    $jsonData = [
        'validation_messages' =>
        [
            'foo' => [
                'regexNotMatch' => 'The input does not match against pattern \'/^[a-zA-Z0-9 .\-]+$/\''
            ]
        ],
        'type' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html',
        'title' => 'Unprocessable Entity',
        'status' => 422,
        'detail' => 'Failed Validation'
    ];

    $response = json_encode($jsonData);
    assert(is_string($response));
}

function skipExactValue2(){
    $json = '{}';

    $response = json_decode($json);
    assert(is_array($response));
}

the JSON_THROW_ON_ERROR seems unneded, it mostly used on tests for testing exact value with the class that uses it.

I think it will only make sense to pass consist of variable.

@samsonasik
Copy link
Member Author

It seems it will cause mixed content:

function processMixedContent(array $message, int $code, string $detail)
{
    $jsonData = [
        'validation_messages' => $message,
        'type' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html',
        'title' => 'Unprocessable Entity',
        'status' => $code,
        'detail' => $detail,
    ];

    $response = json_encode($jsonData);
}

not processed, closing for now.

@samsonasik samsonasik closed this Oct 24, 2021
@samsonasik samsonasik deleted the skip-exact-value branch October 24, 2021 10:50
@samsonasik samsonasik restored the skip-exact-value branch October 24, 2021 11:30
@samsonasik samsonasik reopened this Oct 24, 2021
@samsonasik
Copy link
Member Author

samsonasik commented Oct 24, 2021

Re-open, update ValueResolver to returns null when ConstantArrayType not sure about the value 04342c1#diff-e8d39b18c808064651946f5daf0d52d8bdc6b67a6fbe165c466f5d6c24b9c894 for mixed data array:

function processMixedContent(array $message, int $code, string $detail)
{
    $jsonData = [
        'validation_messages' => $message,
        'type' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html',
        'title' => 'Unprocessable Entity',
        'status' => $code,
        'detail' => $detail,
    ];

    $response = json_encode($jsonData);
}

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@TomasVotruba
Copy link
Member

Thank you 👍

@TomasVotruba TomasVotruba merged commit a504819 into main Oct 24, 2021
@TomasVotruba TomasVotruba deleted the skip-exact-value branch October 24, 2021 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants