DirectoryLock::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of ninja-mutex.
4
 *
5
 * (C) Kamil Dziedzic <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace NinjaMutex\Lock;
11
12
/**
13
 * Lock implementor using mkdir
14
 *
15
 * @author Jan Voracek <[email protected]>
16
 */
17
class DirectoryLock extends LockAbstract
18
{
19
    protected $dirname;
20
21
    /**
22
     * @param string $dirname
23
     */
24
    public function __construct($dirname)
25
    {
26
        parent::__construct();
27
28
        $this->dirname = $dirname;
29
    }
30
31
    /**
32
     * @param  string $name
33
     * @param  bool   $blocking
34
     * @return bool
35
     */
36 32
    protected function getLock($name, $blocking)
37
    {
38 32
        return @mkdir($this->getDirectoryPath($name));
39
    }
40
41
    /**
42
     * Release lock
43
     *
44
     * @param  string $name name of lock
45
     * @return bool
46
     */
47 32
    public function releaseLock($name)
48
    {
49 32
        if (isset($this->locks[$name])) {
50 32
            rmdir($this->getDirectoryPath($name));
51 32
            unset($this->locks[$name]);
52
53 32
            return true;
54
        }
55
56 4
        return false;
57
    }
58
59
    /**
60
     * @param  string $name
61
     * @return string
62
     */
63 32
    protected function getDirectoryPath($name)
64
    {
65 32
        return $this->dirname . DIRECTORY_SEPARATOR . $name . '.lock';
66
    }
67
68
    /**
69
     * Check if lock is locked
70
     *
71
     * @param  string $name name of lock
72
     * @return bool
73
     */
74 14
    public function isLocked($name)
75
    {
76 14
        if ($this->acquireLock($name, false)) {
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a null|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
77 6
            return !$this->releaseLock($name);
78
        }
79
80 14
        return true;
81
    }
82
}
83