Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
82.35% covered (warning)
82.35%
14 / 17
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
NullLockManager
87.50% covered (warning)
87.50%
14 / 16
0.00% covered (danger)
0.00%
0 / 2
10.20
0.00% covered (danger)
0.00%
0 / 1
 doLockByType
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
4.07
 doUnlockByType
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
6.04
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 doLockByType( array $pathsByType ) {
19        foreach ( $pathsByType as $type => $paths ) {
20            foreach ( $paths as $path ) {
21                if ( isset( $this->locksHeld[$path][$type] ) ) {
22                    ++$this->locksHeld[$path][$type];
23                } else {
24                    $this->locksHeld[$path][$type] = 1;
25                }
26            }
27        }
28
29        return StatusValue::newGood();
30    }
31
32    /** @inheritDoc */
33    protected function doUnlockByType( array $pathsByType ) {
34        $status = StatusValue::newGood();
35        foreach ( $pathsByType as $type => $paths ) {
36            foreach ( $paths as $path ) {
37                if ( isset( $this->locksHeld[$path][$type] ) ) {
38                    if ( --$this->locksHeld[$path][$type] <= 0 ) {
39                        unset( $this->locksHeld[$path][$type] );
40                        if ( !$this->locksHeld[$path] ) {
41                            unset( $this->locksHeld[$path] ); // clean up
42                        }
43                    }
44                } else {
45                    $status->warning( 'lockmanager-notlocked', $path );
46                }
47            }
48        }
49
50        return $status;
51    }
52}
53/** @deprecated class alias since 1.46 */
54class_alias( NullLockManager::class, 'NullLockManager' );