KnpLabs / DictionaryBundle

Are you often tired to repeat static choices like gender or civility in your apps ?
MIT License
86 stars 24 forks source link

Add type to constraint violation if different from values. #119

Closed vibby closed 4 years ago

vibby commented 4 years ago

Avoid useless error message : «The key 0 doesn't exist in the given dictionary. 0,1,2 available» Replace it with this : «The key 0 (string) doesn't exist in the given dictionary. 0,1,2 (integer) available»

PedroTroller commented 4 years ago

@vibby v3.1 has been released. Can you rebase your PR ?

vibby commented 4 years ago

Done

vibby commented 4 years ago

Can you please consider merging it @PedroTroller ?

PedroTroller commented 4 years ago

@vibby I think there is a problem. If you have a dictionary like

"foo" => "bar",
12 => null,

When you try to access the key 0, you will have the error

The key 0 (integer) doesn't exist in the given dictionary. foo, 12 (string) available

But the key 12 is not a string.

vibby commented 4 years ago

Maybe I am wrong @PedroTroller, but I think the method getKeys of interface Knp\DictionaryBundle\Dictionary always returns an array with integer keys (0, 1, 2…), not an associative array. Anyway, I can ensure it with a reset function

PedroTroller commented 4 years ago

True but you don't check the keys of the return of getKeys but the values.

vibby commented 4 years ago

I changed it to use the reset function. Is that ok this way ?

PedroTroller commented 4 years ago

@vibby no, the problem remains the same. Not all keys have the same type.

PedroTroller commented 4 years ago

How about this : https://github.com/KnpLabs/DictionaryBundle/pull/125/files ?

vibby commented 4 years ago

I got it. A proposal soon :)

vibby commented 4 years ago

Got it, it now search for the «same» key but in a different type