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