| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\Assert; |
| 4 |
|
| 5 |
use InvalidArgumentException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Exception indicating that an parameter assertion failed. |
| 9 |
* This generally means a disagreement between the caller and the implementation of a function. |
| 10 |
* |
| 11 |
* @since 0.1.0 |
| 12 |
* |
| 13 |
* @license MIT |
| 14 |
* @author Daniel Kinzler |
| 15 |
* @copyright Wikimedia Deutschland e.V. |
| 16 |
*/ |
| 17 |
class ParameterAssertionException extends InvalidArgumentException implements AssertionException { |
| 18 |
|
| 19 |
/** |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
private $parameterName; |
| 23 |
|
| 24 |
/** |
| 25 |
* @param string $parameterName |
| 26 |
* @param string $description |
| 27 |
* |
| 28 |
* @throws ParameterTypeException |
| 29 |
*/ |
| 30 |
public function __construct( $parameterName, $description ) { |
| 31 |
if ( !is_string( $parameterName ) ) { |
| 32 |
throw new ParameterTypeException( 'parameterName', 'string' ); |
| 33 |
} |
| 34 |
|
| 35 |
if ( !is_string( $description ) ) { |
| 36 |
throw new ParameterTypeException( 'description', 'string' ); |
| 37 |
} |
| 38 |
|
| 39 |
parent::__construct( "Bad value for parameter $parameterName: $description" ); |
| 40 |
|
| 41 |
$this->parameterName = $parameterName; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
public function getParameterName(): string { |
| 48 |
return $this->parameterName; |
| 49 |
} |
| 50 |
|
| 51 |
} |