Issues (215)

Exceptions/Validation/InvalidArgumentException.php (6 issues)

1
<?php
2
3
namespace GloBee\PaymentApi\Exceptions\Validation;
4
5
class InvalidArgumentException extends ValidationException
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $expectedType;
11
12
    /**
13
     * @var string
14
     */
15
    protected $actualType;
16
17
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$field" missing
Loading history...
18
     * InvalidArgumentException constructor.
19
     *
20
     * @param        $field
0 ignored issues
show
Missing parameter name
Loading history...
21
     * @param string $expectedType
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
22
     * @param mixed  $actual
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
23
     */
24 9
    public function __construct($field, $expectedType, $actual)
0 ignored issues
show
Type hint "field" missing for
Loading history...
Type hint "string" missing for $expectedType
Loading history...
25
    {
26 9
        $this->expectedType = $expectedType;
27 9
        $this->actualType = gettype($actual);
28 9
        $message = sprintf('Expected %s but found %s.', $this->expectedType, $this->actualType);
29
        $error = [
30 9
            'type' => 'invalid_argument',
31 9
            'extra' => [$this->expectedType, $this->actualType],
32 9
            'field' => $field,
33 9
            'message' => $message,
34
        ];
35 9
        parent::__construct([$error], $message);
36 9
    }
37
38
    /**
39
     * @return string
40
     */
41 1
    public function getExpectedType()
42
    {
43 1
        return $this->expectedType;
44
    }
45
46
    /**
47
     * @return string
48
     */
49 1
    public function getActualType()
50
    {
51 1
        return $this->actualType;
52
    }
53
}
54