Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
LuaStandaloneInterpreterFunction
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 6
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 __clone
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __wakeup
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __destruct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 incrementRefCount
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 decrementRefCount
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace MediaWiki\Extension\Scribunto\Engines\LuaStandalone;
4
5class LuaStandaloneInterpreterFunction {
6    /** @var bool[] */
7    public static $anyChunksDestroyed = [];
8    /** @var int[][] */
9    public static $activeChunkIds = [];
10
11    /**
12     * @var int
13     */
14    public $interpreterId;
15
16    /**
17     * @var int
18     */
19    public $id;
20
21    /**
22     * @param int $interpreterId
23     * @param int $id
24     */
25    public function __construct( $interpreterId, $id ) {
26        $this->interpreterId = $interpreterId;
27        $this->id = $id;
28        $this->incrementRefCount();
29    }
30
31    public function __clone() {
32        $this->incrementRefCount();
33    }
34
35    public function __wakeup() {
36        $this->incrementRefCount();
37    }
38
39    public function __destruct() {
40        $this->decrementRefCount();
41    }
42
43    private function incrementRefCount() {
44        if ( !isset( self::$activeChunkIds[$this->interpreterId] ) ) {
45            self::$activeChunkIds[$this->interpreterId] = [ $this->id => 1 ];
46        } elseif ( !isset( self::$activeChunkIds[$this->interpreterId][$this->id] ) ) {
47            self::$activeChunkIds[$this->interpreterId][$this->id] = 1;
48        } else {
49            self::$activeChunkIds[$this->interpreterId][$this->id]++;
50        }
51    }
52
53    private function decrementRefCount() {
54        if ( isset( self::$activeChunkIds[$this->interpreterId][$this->id] ) ) {
55            if ( --self::$activeChunkIds[$this->interpreterId][$this->id] <= 0 ) {
56                unset( self::$activeChunkIds[$this->interpreterId][$this->id] );
57                self::$anyChunksDestroyed[$this->interpreterId] = true;
58            }
59        } else {
60            self::$anyChunksDestroyed[$this->interpreterId] = true;
61        }
62    }
63}
64
65// Alias exists due to serialization of class name into MWServer.lua
66class_alias( LuaStandaloneInterpreterFunction::class, 'Scribunto_LuaStandaloneInterpreterFunction' );