Skip to content

Commit

Permalink
bug #35987 [DoctrineBridge][DoctrineExtractor] Fix wrong guessed type…
Browse files Browse the repository at this point in the history
… for "json" type (fancyweb)

This PR was merged into the 3.4 branch.

Discussion
----------

[DoctrineBridge][DoctrineExtractor] Fix wrong guessed type for "json" type

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #35968
| License       | MIT
| Doc PR        | -

After checking the code, it appears that `json` have a different behavior than `json_array`.

> In json_array doctrine was converting null or empty value to array, but json type doesn't do that

@norkunas is right about this. Consequently, we cannot safely guess a built in type for the `json` Doctrine type.

Commits
-------

f9f5f8d [DoctrineBridge][DoctrineExtractor] Fix wrong guessed type for "json" type
  • Loading branch information
nicolas-grekas committed Mar 13, 2020
2 parents c561eb0 + f9f5f8d commit f020876
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
Expand Up @@ -178,7 +178,6 @@ public function getTypes($class, $property, array $context = [])
switch ($typeOfField) {
case self::$useDeprecatedConstants ? DBALType::TARRAY : 'array':
case 'json_array':
case self::$useDeprecatedConstants ? false : Types::JSON:
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)];

case self::$useDeprecatedConstants ? DBALType::SIMPLE_ARRAY : Types::SIMPLE_ARRAY:
Expand Down Expand Up @@ -266,7 +265,6 @@ private function getPhpType($doctrineType)
case self::$useDeprecatedConstants ? DBALType::TARRAY : 'array':
case self::$useDeprecatedConstants ? DBALType::SIMPLE_ARRAY : Types::SIMPLE_ARRAY:
case 'json_array':
case self::$useDeprecatedConstants ? false : Types::JSON:
return Type::BUILTIN_TYPE_ARRAY;
}

Expand Down
Expand Up @@ -182,7 +182,7 @@ public function typesProvider()
];

if (class_exists(Types::class)) {
$provider[] = ['json', [new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)]];
$provider[] = ['json', null];
}

return $provider;
Expand Down

0 comments on commit f020876

Please sign in to comment.