8000 merged branch Tobion/formguess (PR #5361) · symfony/symfony@deb41a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit deb41a1

Browse files
committed
merged branch Tobion/formguess (PR #5361)
Commits ------- e7e39e0 [Form] refactor Guess dcbeeb1 [Form] replaced UnexpectedValueException by InvalidArgumentException in Guess Discussion ---------- [Form] replaced UnexpectedValueException by InvalidArgumentException in Guess BC break: yes this is a better fit because the error is a logic exception (that can be detected at compile time, i.e. when writing the code) instead of a runtime exception --------------------------------------------------------------------------- by bschussek at 2012-08-29T10:51:54Z :+1:
2 parents 77a47d3 + e7e39e0 commit deb41a1

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/Symfony/Component/Form/Guess/Guess.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,6 @@ abstract class Guess
4646
*/
4747
const LOW_CONFIDENCE = 0;
4848

49-
/**
50-
* The list of allowed confidence values
51-
* @var array
52-
*/
53-
private static $confidences = array(
54-
self::VERY_HIGH_CONFIDENCE,
55-
self::HIGH_CONFIDENCE,
56-
self::MEDIUM_CONFIDENCE,
57-
self::LOW_CONFIDENCE,
58-
);
59-
6049
/**
6150
* The confidence about the correctness of the value
6251
*
@@ -97,12 +86,13 @@ public static function getBestGuess(array $guesses)
9786
*
9887
* @param integer $confidence The confidence
9988
*
100-
* @throws \UnexpectedValueException if the given value of confidence is unknown
89+
* @throws \InvalidArgumentException if the given value of confidence is unknown
10190
*/
10291
public function __construct($confidence)
10392
{
104-
if (!in_array($confidence, self::$confidences)) {
105-
throw new \UnexpectedValueException(sprintf('The confidence should be one of "%s"', implode('", "', self::$confidences)));
93+
if (self::VERY_HIGH_CONFIDENCE !== $confidence && self::HIGH_CONFIDENCE !== $confidence &&
94+
self::MEDIUM_CONFIDENCE !== $confidence && self::LOW_CONFIDENCE !== $confidence) {
95+
throw new \InvalidArgumentException('The confidence should be one of the constants defined in Guess.');
10696
}
10797

10898
$this->confidence = $confidence;

src/Symfony/Component/Form/Tests/Guess/GuessTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testGetBestGuessReturnsGuessWithHighestConfidence()
2727
}
2828

2929
/**
30-
* @expectedException \UnexpectedValueException
30+
* @expectedException \InvalidArgumentException
3131
*/
3232
public function testGuessExpectsValidConfidence()
3333
{

0 commit comments

Comments
 (0)
0