DuplicateException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 44
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getJsonMessage() 0 8 1
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
}