Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
DisposerBase
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
1 / 1
 __destruct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 empty
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 throwIfDisposed
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 disposeImpl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isDisposed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 dispose
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
LocalEmptyDisposer
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core;
6
7use PeServer\Core\Throws\ObjectDisposedException;
8
9/**
10 * 解放処理用基底クラス。
11 */
12abstract class DisposerBase implements IDisposable
13{
14    #region variable
15
16    /** 解放済みか。 */
17    private bool $isDisposed = false;
18
19    #endregion
20
21    final public function __destruct()
22    {
23        $this->dispose();
24    }
25
26    #region function
27
28    /**
29     * 何もしない解放処理オブジェクトを生成。
30     */
31    public static function empty(): IDisposable
32    {
33        return new LocalEmptyDisposer();
34    }
35
36    /**
37     * 解放済みの場合、例外を投げる。
38     *
39     * @return void
40     * @throws ObjectDisposedException
41     */
42    final protected function throwIfDisposed(): void
43    {
44        if ($this->isDisposed()) {
45            throw new ObjectDisposedException();
46        }
47    }
48
49    /**
50     * 解放処理内部実装。
51     *
52     * 継承先で継承元を呼び出すこと。
53     *
54     * @return void
55     */
56    protected function disposeImpl(): void
57    {
58        //NOP
59    }
60
61    #endregion
62
63    #region IDisposable
64
65    public function isDisposed(): bool
66    {
67        return $this->isDisposed;
68    }
69
70    final public function dispose(): void
71    {
72        if ($this->isDisposed()) {
73            return;
74        }
75
76        $this->disposeImpl();
77
78        $this->isDisposed = true;
79    }
80
81    #endregion
82}
83
84//phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
85final class LocalEmptyDisposer extends DisposerBase
86{
87    //NOP
88}