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

MySqlUnixSocketDsn::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 MySQLDsn
11
 *
12
 * @package Yep\Dsn
13
 * @author  Martin Zeman (Zemistr) <[email protected]>
14
 *
15
 * PDO_MYSQL
16
 * mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
17
 */
18
class MySqlUnixSocketDsn implements IDsn {
19
  /** @var string */
20
  private $unixSocket;
21
22
  /** @var string */
23
  private $dbName;
24
25 3
  public function __construct(string $unixSocket, string $dbName) {
26 3
    $this->setUnixSocket($unixSocket);
27 3
    $this->setDbName($dbName);
28 3
  }
29
30
  /**
31
   * @param string $unixSocket
32
   * @return MySqlUnixSocketDsn
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...
33
   * @throws EmptyArgumentException
34
   */
35 3
  public function setUnixSocket(string $unixSocket) : self {
36 3
    $this->unixSocket = trim($unixSocket);
37
38 3
    if ($this->unixSocket == '') {
39 1
      throw new EmptyArgumentException('unixSocket');
40
    }
41
42 3
    return $this;
43
  }
44
45
  /**
46
   * @return string
47
   */
48 1
  public function getUnixSocket() : string {
49 1
    return $this->unixSocket;
50
  }
51
52
  /**
53
   * @param string $dbName
54
   * @return MySqlUnixSocketDsn
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...
55
   * @throws EmptyArgumentException
56
   */
57 3 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...
58 3
    $this->dbName = trim($dbName);
59
60 3
    if ($this->dbName == '') {
61 1
      throw new EmptyArgumentException('dbName');
62
    }
63
64 3
    return $this;
65
  }
66
67
  /**
68
   * @return string
69
   */
70 1
  public function getDbName() : string {
71 1
    return $this->dbName;
72
  }
73
74
  /**
75
   * @return string
76
   */
77 1
  public function toString() : string {
78 1
    return 'mysql:unix_socket=' . $this->getUnixSocket() . ';dbname=' . $this->getDbName();
79
  }
80
81
  /**
82
   * @return string
83
   */
84 1
  public function __toString() : string {
85 1
    return $this->toString();
86
  }
87
}
88