]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/wikimedia/assert/src/ParameterAssertionException.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / assert / src / ParameterAssertionException.php
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  * @license MIT
12  * @author Daniel Kinzler
13  * @copyright Wikimedia Deutschland e.V.
14  */
15 class ParameterAssertionException extends InvalidArgumentException implements AssertionException {
16
17         /**
18          * @var string
19          */
20         private $parameterName;
21
22         /**
23          * @param string $parameterName
24          * @param string $description
25          *
26          * @throws ParameterTypeException
27          */
28         public function __construct( $parameterName, $description ) {
29                 if ( !is_string( $parameterName ) ) {
30                         throw new ParameterTypeException( 'parameterName', 'string' );
31                 }
32
33                 if ( !is_string( $description ) ) {
34                         throw new ParameterTypeException( 'description', 'string' );
35                 }
36
37                 parent::__construct( "Bad value for parameter $parameterName: $description" );
38
39                 $this->parameterName = $parameterName;
40         }
41
42         /**
43          * @return string
44          */
45         public function getParameterName() {
46                 return $this->parameterName;
47         }
48
49 }