PlayerAlreadyExists   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getJsonMessage() 0 13 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 10/1/17
7
 * Time: 11:31 PM
8
 */
9
10
namespace Tfboe\FmLib\Exceptions;
11
12
13
use Tfboe\FmLib\Entity\PlayerInterface;
14
15
/**
16
 * Class PlayerAlreadyExists
17
 * @package Tfboe\FmLib\Exceptions
18
 */
19
class PlayerAlreadyExists extends AbstractException
20
{
21
//<editor-fold desc="Fields">
22
  /** @var  PlayerInterface[] */
23
  private $players;
24
//</editor-fold desc="Fields">
25
//<editor-fold desc="Constructor">
26
  /**
27
   * PlayerAlreadyExists constructor.
28
   * @param PlayerInterface[] $players list of already existing players
29
   */
30
  public function __construct(array $players)
31
  {
32
    $this->players = $players;
33
    parent::__construct("Some players do already exist!", 409);
34
  }
35
//</editor-fold desc="Constructor">
36
37
//<editor-fold desc="Public Methods">
38
  /**
39
   * Gets a json representation of the exception
40
   * @return array
41
   */
42
  public function getJsonMessage()
43
  {
44
    return [
45
      'message' => "Some players do already exist",
46
      'players' => array_map(function (PlayerInterface $player) {
47
        return [
48
          "firstName" => $player->getFirstName(),
49
          "lastName" => $player->getLastName(),
50
          "id" => $player->getId(),
51
          "birthday" => $player->getBirthday()->format("Y-m-d")];
52
      }, $this->players)
53
    ];
54
  }
55
//</editor-fold desc="Public Methods">
56
}