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

Ensure nullable properties are handled #597

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

flavioheleno
Copy link

@flavioheleno flavioheleno commented Feb 5, 2022

This is a first try at fixing #559. It may not even be the right fix, but I want to help fix it :)

I'm pretty sure that it's missing things like:

  1. Instead of adding a pre-condition to every foreach, it should only be applied to props that are nullable;
  2. Instead of having the pre-condition in ArrayType, it could be moved to MapType;

I need advice/guidance in how to properly approach this.

The effect this change does is, for example, from this:

if (\array_key_exists('Ports', $data) && $data['Ports'] !== null) {
    $values = new \ArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS);
    foreach ($data['Ports'] as $key => $value) {
        $values_1 = array();
        foreach ($value as $value_1) {
            $values_1[] = $this->denormalizer->denormalize($value_1, 'Docker\\API\\Model\\PortBinding', 'json', $context);
        }
        $values[$key] = $values_1;
    }
    $object->setPorts($values);
}

To this:

if (\array_key_exists('Ports', $data) && $data['Ports'] !== null) {
    $values = new \ArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS);
    foreach ($data['Ports'] as $key => $value) {
        if ($value === null) {
            $values[$key] = null;
            continue;
        }
        $values_1 = array();
        foreach ($value as $value_1) {
            $values_1[] = $this->denormalizer->denormalize($value_1, 'Docker\\API\\Model\\PortBinding', 'json', $context);
        }
        $values[$key] = $values_1;
    }
    $object->setPorts($values);
}

@flavioheleno
Copy link
Author

ping @Korbeil

@Rid
Copy link

Rid commented Feb 14, 2023

@Korbeil could you take a look at this? It's been bugging me for years now.

@Korbeil Korbeil marked this pull request as ready for review February 14, 2023 13:29
@Korbeil
Copy link
Member

Korbeil commented Feb 14, 2023

Could you update the code ? (like rebasing on next) so it would trigger CI ?

@flavioheleno
Copy link
Author

@Korbeil done

@flavioheleno
Copy link
Author

Tests are failing due to a missing plugin configuration in composer.json:

Error: php-http/discovery contains a Composer plugin which is blocked by your allow-plugins config. You may add it to the list if you consider it safe.
You can run "composer config --no-plugins allow-plugins.php-http/discovery [true|false]" to enable it (true) or disable it explicitly and suppress this exception (false)
See https://getcomposer.org/allow-plugins

In PluginManager.php line 740:
                                                                               
  php-http/discovery contains a Composer plugin which is blocked by your allo  
  w-plugins config. You may add it to the list if you consider it safe.        
  You can run "composer config --no-plugins allow-plugins.php-http/discovery   
  [true|false]" to enable it (true) or disable it explicitly and suppress thi  
  s exception (false)                                                          
  See https://getcomposer.org/allow-plugins

@Korbeil
Copy link
Member

Korbeil commented Feb 14, 2023

I pushed a commit on next branch fixing this, could you rebase again please ?

@flavioheleno
Copy link
Author

@Korbeil there's nothing new in next, did your push go through?

@Korbeil
Copy link
Member

Korbeil commented Feb 14, 2023

Sorry, I pushed on my fork but forgot to push here :< (it's fixed now)

@Rid
Copy link

Rid commented Feb 14, 2023

@flavioheleno You will need to force-push again to trigger the CI.

@flavioheleno
Copy link
Author

@Rid yeah, it's just @Korbeil 's fix that wasn't in next, now that it is I've rebased it again :-)

@flavioheleno
Copy link
Author

I'll fix the failing tests right away

@flavioheleno
Copy link
Author

flavioheleno commented Feb 15, 2023

this PR is affecting more productions than it should, I'll dig through it again and rework on its solution to ensure it's only changing the bits that should be changed.

eg. of unwanted side effect:

foreach ($data['object'] as $key => $value_2) {
    if ($value_2 === null) {
        $values_1[$key] = null;
        continue;
    }
    $values_1[$key] = $value_2;
}

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.

None yet

3 participants