Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
12 / 15
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
NullLockManager
85.71% covered (warning)
85.71%
12 / 14
0.00% covered (danger)
0.00%
0 / 2
8.19
0.00% covered (danger)
0.00%
0 / 1
 doLock
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 doUnlock
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
5.03
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 */
6namespace Wikimedia\LockManager;
7
8use StatusValue;
9
10/**
11 * Simple lock management based on in-process reference counting.
12 *
13 * @since 1.19
14 * @ingroup LockManager
15 */
16class NullLockManager extends LockManager {
17    /** @inheritDoc */
18    protected function doLock( array $paths, $type ) {
19        foreach ( $paths as $path ) {
20            if ( isset( $this->locksHeld[$path][$type] ) ) {
21                ++$this->locksHeld[$path][$type];
22            } else {
23                $this->locksHeld[$path][$type] = 1;
24            }
25        }
26
27        return StatusValue::newGood();
28    }
29
30    /** @inheritDoc */
31    protected function doUnlock( array $paths, $type ) {
32        $status = StatusValue::newGood();
33
34        foreach ( $paths as $path ) {
35            if ( isset( $this->locksHeld[$path][$type] ) ) {
36                if ( --$this->locksHeld[$path][$type] <= 0 ) {
37                    unset( $this->locksHeld[$path][$type] );
38                    if ( !$this->locksHeld[$path] ) {
39                        unset( $this->locksHeld[$path] ); // clean up
40                    }
41                }
42            } else {
43                $status->warning( 'lockmanager-notlocked', $path );
44            }
45        }
46
47        return $status;
48    }
49}
50/** @deprecated class alias since 1.46 */
51class_alias( NullLockManager::class, 'NullLockManager' );