summaryrefslogtreecommitdiff
path: root/vendor/wikimedia/assert/src/ParameterAssertionException.php
blob: cb42cc6fad8ddba4448a0f22cce9a83ca51770c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

namespace Wikimedia\Assert;

use InvalidArgumentException;

/**
 * Exception indicating that an parameter assertion failed.
 * This generally means a disagreement between the caller and the implementation of a function.
 *
 * @license MIT
 * @author Daniel Kinzler
 * @copyright Wikimedia Deutschland e.V.
 */
class ParameterAssertionException extends InvalidArgumentException implements AssertionException {

	/**
	 * @var string
	 */
	private $parameterName;

	/**
	 * @param string $parameterName
	 * @param string $description
	 *
	 * @throws ParameterTypeException
	 */
	public function __construct( $parameterName, $description ) {
		if ( !is_string( $parameterName ) ) {
			throw new ParameterTypeException( 'parameterName', 'string' );
		}

		if ( !is_string( $description ) ) {
			throw new ParameterTypeException( 'description', 'string' );
		}

		parent::__construct( "Bad value for parameter $parameterName: $description" );

		$this->parameterName = $parameterName;
	}

	/**
	 * @return string
	 */
	public function getParameterName() {
		return $this->parameterName;
	}

}