Password::getPassword()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PhPsst.
4
 *
5
 * @copyright Copyright (c) 2016 Felix Sandström
6
 * @license   MIT
7
 */
8
9
namespace PhPsst;
10
11
/**
12
 * @author Felix Sandström <http://github.com/felixsand>
13
 */
14
class Password
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $id;
20
21
    /**
22
     * @var int
23
     */
24
    protected $ttl;
25
26
    /**
27
     * @var int
28
     */
29
    protected $views;
30
31
    /**
32
     * @var string
33
     */
34
    protected $password;
35
36 4
    public function __construct(string $id, string $password, int $ttl, int $views)
37
    {
38 4
        $this->id = $id;
39 4
        $this->password = $password;
40 4
        $this->ttl = $ttl;
41 4
        $this->views = $views;
42
    }
43
44 1
    public function getId(): string
45
    {
46 1
        return $this->id;
47
    }
48
49 1
    public function getPassword(): string
50
    {
51 1
        return $this->password;
52
    }
53
54 1
    public function getTtl(): int
55
    {
56 1
        return $this->ttl;
57
    }
58
59 1
    public function getViews(): int
60
    {
61 1
        return $this->views;
62
    }
63
64 2
    public function decreaseViews(): void
65
    {
66 2
        if (($this->views - 1) >= 0) {
67 2
            $this->views--;
68
        } else {
69 1
            throw new \LogicException('Passwords with negative views should be deleted');
70
        }
71
    }
72
73 1
    public function getJson(): string
74
    {
75 1
        return json_encode([
76 1
            'id' => $this->getId(),
77 1
            'password' => $this->getPassword(),
78 1
            'ttl' => $this->getTtl(),
79 1
            'views' => $this->getViews(),
80
        ]);
81
    }
82
}
83