Completed
Push — master ( 1b30cc...8b075a )
by Martin
02:23
created

BaseDns   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 83
Duplicated Lines 21.69 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 2
dl 18
loc 83
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setDbName() 9 9 2
A getDbName() 0 3 1
A setHost() 9 9 2
A getHost() 0 3 1
A setPort() 0 9 2
A getPort() 0 3 1
A __toString() 0 3 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
 * This file is part of the Yep package.
4
 * Copyright (c) 2016 Martin Zeman (Zemistr) (http://www.zemistr.eu)
5
 */
6
7
namespace Yep\Dsn;
8
9
/**
10
 * Class BaseDns
11
 *
12
 * @package Yep\Dsn
13
 * @author  Martin Zeman (Zemistr) <[email protected]>
14
 */
15
abstract class BaseDns implements IDsn {
16
  /** @var string */
17
  protected $dbName;
18
19
  /** @var string */
20
  protected $host;
21
22
  /** @var int */
23
  protected $port;
24
25
  /**
26
   * @param string $dbName
27
   * @return BaseDns|static
0 ignored issues
show
Documentation introduced by
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
28
   * @throws EmptyArgumentException
29
   */
30 8 View Code Duplication
  public function setDbName(string $dbName) : self {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31 8
    $this->dbName = trim($dbName);
32
33 8
    if ($this->dbName === '') {
34 2
      throw new EmptyArgumentException('dbName');
35
    }
36
37 8
    return $this;
38
  }
39
40
  /**
41
   * @return string
42
   */
43 2
  public function getDbName() : string {
44 2
    return $this->dbName;
45
  }
46
47
  /**
48
   * @param string $host
49
   * @return BaseDns|static
0 ignored issues
show
Documentation introduced by
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
50
   * @throws EmptyArgumentException
51
   */
52 8 View Code Duplication
  public function setHost(string $host) : self {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53 8
    $this->host = trim($host);
54
55 8
    if ($this->host === '') {
56 2
      throw new EmptyArgumentException('host');
57
    }
58
59 8
    return $this;
60
  }
61
62
  /**
63
   * @return string
64
   */
65 2
  public function getHost() : string {
66 2
    return $this->host;
67
  }
68
69
  /**
70
   * @param int $port
71
   * @return BaseDns|static
0 ignored issues
show
Documentation introduced by
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
72
   * @throws WrongArgumentException
73
   */
74 8
  public function setPort(int $port) : self {
75 8
    $this->port = $port;
76
77 8
    if ($this->port <= 0) {
78 2
      throw new WrongArgumentException('port', 'Port must be greater than 0!');
79
    }
80
81 8
    return $this;
82
  }
83
84
  /**
85
   * @return int
86
   */
87 2
  public function getPort() : int {
88 2
    return $this->port;
89
  }
90
91
  /**
92
   * @return string
93
   */
94 2
  public function __toString() : string {
95 2
    return $this->toString();
96
  }
97
}
98