Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
82.35% |
14 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| NullLockManager | |
87.50% |
14 / 16 |
|
0.00% |
0 / 2 |
10.20 | |
0.00% |
0 / 1 |
| doLockByType | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
4.07 | |||
| doUnlockByType | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
6.04 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | namespace Wikimedia\LockManager; |
| 7 | |
| 8 | use StatusValue; |
| 9 | |
| 10 | /** |
| 11 | * Simple lock management based on in-process reference counting. |
| 12 | * |
| 13 | * @since 1.19 |
| 14 | * @ingroup LockManager |
| 15 | */ |
| 16 | class 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 */ |
| 54 | class_alias( NullLockManager::class, 'NullLockManager' ); |