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

SqliteDsn::__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 SQLiteDsn
11
 *
12
 * @package Yep\Dsn
13
 * @author  Martin Zeman (Zemistr) <[email protected]>
14
 *
15
 * PDO_SQLITE
16
 * sqlite::memory:
17
 * sqlite:/opt/databases/mydb.sq3
18
 */
19
class SqliteDsn implements IDsn {
20
  /** @var string */
21
  protected $path;
22
23 4
  public function __construct(string $path = ':memory:') {
24 4
    $this->setPath($path);
25 4
  }
26
27
  /**
28
   * @param string $path
29
   * @return SqliteDsn
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...
30
   * @throws EmptyArgumentException
31
   */
32 4 View Code Duplication
  public function setPath(string $path) : 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...
33 4
    $this->path = trim($path);
34
35 4
    if ($this->path === '') {
36 2
      throw new EmptyArgumentException('path');
37
    }
38
39 4
    return $this;
40
  }
41
42
  /**
43
   * @return string
44
   */
45 2
  public function getPath() : string {
46 2
    return $this->path;
47
  }
48
49
  /**
50
   * @return string
51
   */
52 1
  public function toString() : string {
53 1
    return 'sqlite:' . $this->getPath();
54
  }
55
56
  /**
57
   * @return string
58
   */
59 2
  public function __toString() : string {
60 2
    return $this->toString();
61
  }
62
}
63