ConnectionAlreadyEstablished   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 45
loc 45
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_id() 4 4 1
A __construct() 6 6 1
A format_message() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\ActiveRecord;
13
14
use ICanBoogie\Accessor\AccessorTrait;
15
16
/**
17
 * Exception thrown in attempt to set the definition of an already established connection.
18
 *
19
 * @property-read string $id The identifier of the connection.
20
 */
21 View Code Duplication
class ConnectionAlreadyEstablished extends \LogicException implements Exception
22
{
23
	use AccessorTrait;
24
25
	/**
26
	 * @var string
27
	 */
28
	private $id;
29
30
	/**
31
	 * @return string
32
	 */
33
	protected function get_id()
34
	{
35
		return $this->id;
36
	}
37
38
	/**
39
	 * @param string $id
40
	 * @param int $code
41
	 * @param \Exception|null $previous
42
	 */
43
	public function __construct($id, $code = 500, \Exception $previous = null)
44
	{
45
		$this->id = $id;
46
47
		parent::__construct($this->format_message($id), $code, $previous);
48
	}
49
50
	/**
51
	 * Formats exception message.
52
	 *
53
	 * @param string $id
54
	 *
55
	 * @return string
56
	 */
57
	protected function format_message($id)
58
	{
59
		return \ICanBoogie\format("Connection already established: %id.", [
60
61
			'id' => $id
62
63
		]);
64
	}
65
}
66