DuplicateException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 10/20/17
7
 * Time: 3:16 PM
8
 */
9
10
namespace Tfboe\FmLib\Exceptions;
11
12
/**
13
 * Class DuplicateException
14
 * @package Tfboe\FmLib\Exceptions
15
 */
16
class DuplicateException extends AbstractException
17
{
18
//<editor-fold desc="Fields">
19
  /** @var string */
20
  private $duplicateValue;
21
  /** @var string */
22
  private $duplicateName;
23
  /** @var string */
24
  private $arrayName;
25
//</editor-fold desc="Fields">
26
27
//<editor-fold desc="Constructor">
28
  /**
29
   * DuplicateException constructor.
30
   * @param mixed $duplicateValue
31
   * @param string $duplicateName
32
   * @param string $arrayName
33
   */
34
  public function __construct($duplicateValue, string $duplicateName, string $arrayName)
35
  {
36
    $this->duplicateValue = $duplicateValue;
37
    $this->duplicateName = $duplicateName;
38
    $this->arrayName = $arrayName;
39
40
    $message = "The $duplicateName $duplicateValue occurs twice in $arrayName";
41
    parent::__construct($message, 409);
42
  }
43
//</editor-fold desc="Constructor">
44
45
//<editor-fold desc="Public Methods">
46
  /**
47
   * Gets a json representation of the exception
48
   * @return array
49
   */
50
  public function getJsonMessage()
51
  {
52
    return [
53
      'message' => "Duplicate Exception",
54
      'duplicateValue' => $this->duplicateValue,
55
      'arrayName' => $this->arrayName
56
    ];
57
  }
58
//</editor-fold desc="Public Methods">
59
}