-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[OptionsResolver] Exception doesn't report the actual type used #11021
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
Closed
cleentfaar
wants to merge
5
commits into
symfony:master
from
cleentfaar:issue-11020-exception-doesnt-report-actual-type-used
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
replaced 'static'-calls with 'self', removed alignment
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,13 +98,13 @@ class Options implements \ArrayAccess, \Iterator, \Countable | |
public static function resolve(array $options, $defaults) | ||
{ | ||
if (is_array($defaults)) { | ||
static::validateNames($options, $defaults, true); | ||
self::validateNames($options, $defaults, true); | ||
|
||
return array_replace($defaults, $options); | ||
} | ||
|
||
if ($defaults instanceof self) { | ||
static::validateNames($options, $defaults->options, true); | ||
self::validateNames($options, $defaults->options, true); | ||
|
||
// Make sure this method can be called multiple times | ||
$combinedOptions = clone $defaults; | ||
|
@@ -119,8 +119,8 @@ public static function resolve(array $options, $defaults) | |
} | ||
|
||
if ($defaults instanceof OptionsConfig) { | ||
static::validateNames($options, $defaults->knownOptions, true); | ||
static::validateRequired($options, $defaults->requiredOptions, true); | ||
self::validateNames($options, $defaults->knownOptions, true); | ||
self::validateRequired($options, $defaults->requiredOptions, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same applies to |
||
|
||
// Make sure this method can be called multiple times | ||
$combinedOptions = clone $defaults->defaultOptions; | ||
|
@@ -133,8 +133,8 @@ public static function resolve(array $options, $defaults) | |
// Resolve options | ||
$resolvedOptions = $combinedOptions->all(); | ||
|
||
static::validateTypes($resolvedOptions, $defaults->allowedTypes); | ||
static::validateValues($resolvedOptions, $defaults->allowedValues); | ||
self::validateTypes($resolvedOptions, $defaults->allowedTypes); | ||
self::validateValues($resolvedOptions, $defaults->allowedValues); | ||
|
||
return $resolvedOptions; | ||
} | ||
|
@@ -263,8 +263,8 @@ public static function validateTypes(array $options, array $acceptedTypes) | |
throw new InvalidOptionsException(sprintf( | ||
'The option "%s" with value "%s" is expected to be of type "%s"', | ||
$option, | ||
static::formatValue($value), | ||
static::formatTypesOf($optionTypes) | ||
self::formatValue($value), | ||
self::formatTypesOf($optionTypes) | ||
)); | ||
} | ||
} | ||
|
@@ -288,7 +288,7 @@ public static function validateValues(array $options, array $acceptedValues) | |
foreach ($acceptedValues as $option => $optionValues) { | ||
if (array_key_exists($option, $options)) { | ||
if (is_array($optionValues) && !in_array($options[$option], $optionValues, true)) { | ||
throw new InvalidOptionsException(sprintf('The option "%s" has the value "%s", but is expected to be one of "%s"', $option, $options[$option], static::formatValues($optionValues))); | ||
throw new InvalidOptionsException(sprintf('The option "%s" has the value "%s", but is expected to be one of "%s"', $option, $options[$option], self::formatValues($optionValues))); | ||
} | ||
|
||
if (is_callable($optionValues) && !call_user_func($optionValues, $options[$option])) { | ||
|
@@ -325,7 +325,7 @@ private static function formatTypeOf($value) | |
private static function formatTypesOf(array $types) | ||
{ | ||
foreach ($types as $key => $value) { | ||
$types[$key] = static::formatTypeOf($value); | ||
$types[$key] = self::formatTypeOf($value); | ||
} | ||
|
||
return implode(', ', $types); | ||
|
@@ -348,9 +348,9 @@ private static function formatTypesOf(array $types) | |
private static function formatValue($value) | ||
{ | ||
$isDateTime = $value instanceof \DateTime || $value instanceof \DateTimeInterface; | ||
if (static::PRETTY_DATE && $isDateTime) { | ||
if (self::PRETTY_DATE && $isDateTime) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a condition with a constant? makes no sense |
||
if (class_exists('IntlDateFormatter')) { | ||
$locale = \Locale::getDefault(); | ||
$locale = \Locale::getDefault(); | ||
$formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT); | ||
// neither the native nor the stub IntlDateFormatter support | ||
// DateTimeImmutable as of yet | ||
|
@@ -368,7 +368,7 @@ private static function formatValue($value) | |
} | ||
|
||
if (is_object($value)) { | ||
if (static::OBJECT_TO_STRING && method_exists($value, '__toString')) { | ||
if (self::OBJECT_TO_STRING && method_exists($value, '__toString')) { | ||
return $value->__toString(); | ||
} | ||
|
||
|
@@ -417,7 +417,7 @@ private static function formatValue($value) | |
private static function formatValues(array $values) | ||
{ | ||
foreach ($values as $key => $value) { | ||
$values[$key] = static::formatValue($value); | ||
$values[$key] = self::formatValue($value); | ||
} | ||
|
||
return implode(', ', $values); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateNames()
ispublic
. Therefore,static
must be kept here.