Locker::isLocked()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace GroundSix\Locker;
5
6
class Locker
7
{
8
    /** @var LockerDriver $driver */
9
    private $driver;
10
11
    /**
12
     * Creates a new Locker instance
13
     *
14
     * @param LockerDriver $driver The instance of the LockerDriver to use to check the state of locked pages
15
     */
16
    public function __construct(LockerDriver $driver)
17
    {
18
        $this->driver = $driver;
19
    }
20
21
    /**
22
     * Is the specified URL locked?
23
     *
24
     * @param string $url The URL to check the lock status for
25
     * @return bool true if locked, otherwise false
26
     */
27
    public function isLocked(string $url): bool
28
    {
29
        $status = $this->driver->getURLStatus($url);
30
        return $status->isLocked();
31
    }
32
33
    /**
34
     * Gets the full status of a page
35
     *
36
     * @param string $url
37
     * @return Status
38
     */
39
    public function getURLStatus(string $url): Status
40
    {
41
        return $this->driver->getURLStatus($url);
42
    }
43
44
    /**
45
     * Locks the given URL for a specified amount of time
46
     *
47
     * @param string $url The URL to lock
48
     * @param string $lockedBy The identifier of the user locking the page
49
     * @param int $lockFor The amount of seconds to lock the page for
50
     */
51
    public function lock(string $url, string $lockedBy, int $lockFor): void
52
    {
53
        $this->driver->lockURL($url, $lockedBy, $lockFor);
54
    }
55
56
    /**
57
     * Unlocks the given URL
58
     *
59
     * @param string $url The URL to unlock
60
     */
61
    public function unlock(string $url): void
62
    {
63
        $this->driver->unlockURL($url);
64
    }
65
}
66