Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ParameterAssertionException
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getParameterName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Wikimedia\Assert;
4
5use 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 */
17class 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}