Completed
Push — feature/0.7.0 ( ad3584...17fb54 )
by Ryuichi
02:59
created

Logger::createStatusFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
namespace WebStream\Log;
3
4
use WebStream\DI\Injector;
5
use WebStream\IO\File;
6
use WebStream\IO\FileInputStream;
7
use WebStream\IO\Reader\FileReader;
8
use WebStream\IO\Writer\SimpleFileWriter;
9
use WebStream\Module\Utility\LoggerUtils;
10
use WebStream\Module\Container;
11
use WebStream\Exception\Extend\IOException;
12
use WebStream\Exception\Extend\LoggerException;
13
14
/**
15
 * Loggerクラス
16
 * @author Ryuichi Tanaka
17
 * @since 2012/01/16
18
 * @version 0.7
19
 */
20
class Logger
21
{
22
    use Injector, LoggerUtils;
23
24
    /**
25
     * @var Logger ロガー
26
     */
27
    private static $logger;
28
29
    /**
30
     * @var LoggerFormatter ロガーフォーマッタ
31
     */
32
    private static $formatter;
33
34
    /**
35
     * @var Container ログ設定コンテナ
36
     */
37
    private static $config;
38
39
    /**
40
     * @var Container ログ設定コンテナ
41
     */
42
    private $logConfig;
43
44
    /**
45
     * @var array<IOutputter> Outputterリスト
46
     */
47
    private $outputters;
48
49
    /**
50
     * @var Container IOコンテナ
51
     */
52
    private $ioContainer;
53
54
    /**
55
     * @var File ログファイル
56
     */
57
    private $logFile;
58
59
    /**
60
     * @var File ステータスファイル
61
     */
62
    private $statusFile;
63
64
    /**
65
     * コンストラクタ
66
     * @param Container ログ設定コンテナ
67
     */
68
    private function __construct(Container $logConfig)
69
    {
70
        $this->logConfig = $logConfig;
71
        $this->outputters = [];
72
73
        $logFile = new File($logConfig->logPath);
0 ignored issues
show
Documentation introduced by
The property logPath does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
74
        $statusFile = new File($logConfig->statusPath);
0 ignored issues
show
Documentation introduced by
The property statusPath does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
75
76
        $this->ioContainer = new Container();
77
78
        $this->ioContainer->statusReader = function () use ($statusFile) {
0 ignored issues
show
Documentation introduced by
The property statusReader does not exist on object<WebStream\Module\Container>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
79
            return new FileReader($statusFile);
80
        };
81
        $this->ioContainer->statusWriter = function () use ($statusFile) {
0 ignored issues
show
Documentation introduced by
The property statusWriter does not exist on object<WebStream\Module\Container>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
82
            return new SimpleFileWriter($statusFile->getFilePath());
83
        };
84
        $this->ioContainer->logWriter = function () use ($logFile) {
0 ignored issues
show
Documentation introduced by
The property logWriter does not exist on object<WebStream\Module\Container>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
85
            return new SimpleFileWriter($logFile->getFilePath());
86
        };
87
88
        $this->logFile = $logFile;
89
        $this->statusFile = $statusFile;
90
    }
91
92
    /**
93
     * デストラクタ
94
     */
95
    public function __destruct()
96
    {
97
        $this->directWrite();
98
    }
99
100
    /**
101
     * ログ設定を返却する
102
     * @return Container ログ設定
103
     */
104
    public function getConfig()
105
    {
106
        return $this->logConfig;
107
    }
108
109
    /**
110
     * 遅延書き出しを有効にする
111
     */
112
    public static function enableLazyWrite()
113
    {
114
        self::$logger->lazyWrite();
115
    }
116
117
    /**
118
     * 即時書き出しを有効にする
119
     */
120
    public static function enableDirectWrite()
121
    {
122
        self::$logger->directWrite();
123
    }
124
125
    /**
126
     * インスタンスを返却する
127
     * @return WebStream\Module\Logger ロガーインスタンス
128
     */
129
    public static function getInstance()
130
    {
131
        return self::$logger;
132
    }
133
134
    /**
135
     * Loggerを初期化する
136
     * @param Container ログ設定コンテナ
137
     */
138
    public static function init(Container $config)
139
    {
140
        self::$config = $config;
141
        self::$logger = new Logger($config);
142
        self::$formatter = new LoggerFormatter($config);
143
    }
144
145
    /**
146
     * Loggerを終了する
147
     */
148
    public static function finalize()
149
    {
150
        self::$config = null;
151
        self::$logger = null;
152
        self::$formatter = null;
153
    }
154
155
    /**
156
     * Loggerが初期化済みかどうかチェックする
157
     * @param bool 初期化済みならtrue
158
     */
159
    public static function isInitialized()
160
    {
161
        return self::$logger !== null;
162
    }
163
164
    /**
165
     * Loggerメソッドの呼び出しを受ける
166
     * @param string メソッド名(ログレベル文字列)
167
     * @param array 引数
168
     */
169
    public static function __callStatic($level, $arguments)
170
    {
171
        if (self::$logger === null || self::$formatter === null) {
172
            if (self::$config !== null) {
173
                self::init(self::$config);
174
            } else {
175
                throw new LoggerException("Logger is not initialized.");
176
            }
177
        }
178
179
        call_user_func_array([self::$logger, "write"], array_merge([$level], $arguments));
180
    }
181
182
    /**
183
     * Outputterを設定する
184
     * @param array<IOutputter> $outputters Outputterリスト
185
     */
186
    public function setOutputter(array $outputters)
187
    {
188
        foreach ($outputters as $outputter) {
189
            if (!$outputter instanceof \WebStream\Log\Outputter\IOutputter) {
190
                throw new LoggerException("Log outputter must implement WebStream\Log\Outputter\IOutputter.");
191
            }
192
        }
193
        $this->outputters = $outputters;
194
    }
195
196
    /**
197
     * タイムスタンプを取得する
198
     * @return string タイムスタンプ
199
     */
200
    private function getTimeStamp()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
201
    {
202
        date_default_timezone_set('Asia/Tokyo');
203
        $msec = sprintf("%2d", floatval(microtime()) * 100);
204
205
        return strftime("%Y-%m-%d %H:%M:%S") . "," . $msec;
206
    }
207
208
    /**
209
     * ログを書き出す
210
     * @param string ログレベル文字列
211
     * @param string 出力文字列
212
     * @param array<mixed> 埋め込み値リスト
213
     */
214
    public function write($level, $msg, $context = null)
215
    {
216
        if ($this->logConfig->logLevel > $this->toLogLevelValue($level)) {
0 ignored issues
show
Documentation introduced by
The property logLevel does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
217
            return;
218
        }
219
220
        if (is_array($context) && count($context) > 0) {
221
            // sprintfと同様の展開
222
            // [a-zA-Z0-9_-\.] 以外もキーには指定可能だが仕様としてこれ以外は不可とする
223
            preg_match_all('/\{\s*([a-zA-Z0-9._-]+)\s*?\}/', $msg, $matches);
224
            foreach ($matches[1] as $index => $value) {
225
                if (array_key_exists($value, $context)) {
226
                    $matches[1][$index] = $context[$value];
227
                } else {
228
                    unset($matches[0][$index]);
229
                }
230
            }
231
            $msg = str_replace($matches[0], $matches[1], $msg);
232
        }
233
234
        // ログローテート処理
235
        $this->rotate();
236
237
        try {
238
            if (count($this->outputters) > 0) {
239
                foreach ($this->outputters as $outputter) {
240
                    $outputter->write(self::$formatter->getFormattedMessage($msg, $level));
241
                }
242
            } else {
243
                $this->ioContainer->logWriter->write(self::$formatter->getFormattedMessage($msg, $level) . PHP_EOL);
0 ignored issues
show
Documentation introduced by
The property logWriter does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
244
            }
245
        } catch (LoggerException $e) {
246
            throw $e;
247
        } catch (IOException $e) {
248
            throw new LoggerException($e);
249
        }
250
    }
251
252
    /**
253
     * ログファイルをアーカイブする
254
     * stream.log -> stream.(作成日時)-(現在日時).log
255
     * @param string ログファイルパス
256
     */
257
    private function rotate()
258
    {
259
        // ログファイルがない場合はローテートしない
260
        if (!$this->logFile->exists()) {
261
            return;
262
        }
263
264
        // ログローテート実行
265
        if ($this->logConfig->rotateCycle !== null) {
0 ignored issues
show
Documentation introduced by
The property rotateCycle does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
266
            $this->rotateByCycle();
267
        } elseif ($this->logConfig->rotateSize !== null) {
0 ignored issues
show
Documentation introduced by
The property rotateSize does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
268
            $this->rotateBySize();
269
        }
270
    }
271
272
    /**
273
     * ログステータスファイルに書きこむ
274
     * @throws IOException
275
     */
276
    private function writeStatus()
277
    {
278
        $this->ioContainer->statusWriter->write(intval(preg_replace('/^.*\s/', '', microtime())));
0 ignored issues
show
Documentation introduced by
The property statusWriter does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
279
    }
280
281
    /**
282
     * ログステータスファイルを読み込む
283
     * @return int UnixTime
284
     * @throws LoggerException
285
     */
286
    private function readStatus()
287
    {
288
        $content = $this->ioContainer->statusReader->read();
0 ignored issues
show
Documentation introduced by
The property statusReader does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
289
        if (!preg_match('/^\d{10}$/', $content)) {
290
            throw new LoggerException("Invalid log state file contents: " . $content);
291
        }
292
293
        return intval($content);
294
    }
295
296
    /**
297
     * ステータスファイルを作成する
298
     */
299
    private function createStatusFile()
300
    {
301
        // ステータスファイルがない場合は書きだす
302
        if (!$this->statusFile->exists()) {
303
            $this->writeStatus();
304
        }
305
    }
306
307
    /**
308
     * ローテートを実行する
309
     * @param integer 作成日時のUnixTime
310
     * @param integer 現在日時のUnixTime
311
     */
312
    private function runRotate($from, $to)
313
    {
314
        $fromDate = date("YmdHis", $from);
315
        $toDate = date("YmdHis", $to);
316
        $archivePath = null;
0 ignored issues
show
Unused Code introduced by
$archivePath is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
317
        if (preg_match('/(.*)\.(.+)/', $this->logConfig->logPath, $matches)) {
0 ignored issues
show
Documentation introduced by
The property logPath does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
318
            $archivePath = "$matches[1].${fromDate}-${toDate}.$matches[2]";
319
            // mvを実行
320
            $this->logFile->renameTo($archivePath);
321
            // ステータスファイルを削除
322
            $this->statusFile->delete();
323
        }
324
    }
325
326
    /**
327
     * 時間単位でローテートする
328
     * stream.log -> stream.(作成日時)-(現在日時).log
329
     */
330
    private function rotateByCycle()
331
    {
332
        $this->createStatusFile();
333
        $now = intval(preg_replace('/^.*\s/', '', microtime()));
334
        $createdAt = $this->readStatus();
335
336
        $hour = intval(floor(($now - $createdAt) / 3600));
337
        if ($hour >= $this->logConfig->rotateCycle) {
0 ignored issues
show
Documentation introduced by
The property rotateCycle does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
338
            $this->runRotate($createdAt, $now);
339
        }
340
    }
341
342
    /**
343
     * サイズ単位でローテートする
344
     * stream.log -> stream.(作成日時)-(現在日時).log
345
     */
346
    private function rotateBySize()
347
    {
348
        $this->createStatusFile();
349
        $now = intval(preg_replace('/^.*\s/', '', microtime()));
350
        $createdAt = $this->readStatus();
351
352
        $sizeKb = (int) floor($this->logFile->size() / 1024);
353
        // 指定したサイズより大きければローテート
354
        if ($sizeKb >= $this->logConfig->rotateSize) {
0 ignored issues
show
Documentation introduced by
The property rotateSize does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
355
            $this->runRotate($createdAt, $now);
356
        }
357
    }
358
359
    /**
360
     * ログ出力パスを返却する
361
     * @return string ログ出力パス
362
     */
363
    public function getLogPath()
364
    {
365
        return $this->logConfig->logPath;
0 ignored issues
show
Documentation introduced by
The property logPath does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
366
    }
367
368
    /**
369
     * ログローテートサイクルを返却する
370
     * @return string ログ出力パス
371
     */
372
    public function getLogRotateCycle()
373
    {
374
        return $this->logConfig->rotateCycle;
0 ignored issues
show
Documentation introduced by
The property rotateCycle does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
375
    }
376
377
    /**
378
     * ログローテートサイズを返却する
379
     * @return string ログ出力パス
380
     */
381
    public function getLogRotateSize()
382
    {
383
        return $this->logConfig->rotateSize;
0 ignored issues
show
Documentation introduced by
The property rotateSize does not exist on object<WebStream\Module\Container>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
384
    }
385
386
    /**
387
     * 遅延書き出しを有効にする
388
     */
389
    public function lazyWrite()
390
    {
391
        foreach ($this->outputters as $outputter) {
392
            if ($outputter instanceof \WebStream\Log\Outputter\ILazyWriter) {
393
                $outputter->enableLazyWrite();
394
            }
395
        }
396
    }
397
398
    /**
399
     * 即時書き出しを有効にする
400
     */
401
    public function directWrite()
402
    {
403
        foreach ($this->outputters as $outputter) {
404
            if ($outputter instanceof \WebStream\Log\Outputter\ILazyWriter) {
405
                $outputter->enableDirectWrite();
406
            }
407
        }
408
    }
409
}
410