Completed
Push — feature/0.7.0 ( 7f3169...e2f9cf )
by Ryuichi
03:03
created

Logger::setOutputter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
namespace WebStream\Log;
3
4
use WebStream\Module\Utility\LoggerUtils;
5
use WebStream\Module\Container;
6
use WebStream\Exception\Extend\LoggerException;
7
8
/**
9
 * Loggerクラス
10
 * @author Ryuichi Tanaka
11
 * @since 2012/01/16
12
 * @version 0.7
13
 */
14
class Logger
15
{
16
    use LoggerUtils;
17
18
    /**
19
     * @var Logger ロガー
20
     */
21
    private static $logger;
22
23
    /**
24
     * @var LoggerFormatter ロガーフォーマッタ
25
     */
26
    private static $formatter;
27
28
    /**
29
     * @var Container ログ設定コンテナ
30
     */
31
    private static $config;
32
33
    /**
34
     * @var Container ログ設定コンテナ
35
     */
36
    private $logConfig;
37
38
    /**
39
     * @var array<IOutputter> Outputterリスト
40
     */
41
    private $outputters;
42
43
    /**
44
     * コンストラクタ
45
     * @param Container ログ設定コンテナ
46
     */
47
    private function __construct(Container $logConfig)
48
    {
49
        $this->logConfig = $logConfig;
50
        $this->outputters = [];
51
    }
52
53
    /**
54
     * ログ設定を返却する
55
     * @return Container ログ設定
56
     */
57
    public function getConfig()
58
    {
59
        return $this->logConfig;
60
    }
61
62
    /**
63
     * デストラクタ
64
     */
65
    public function __destruct()
66
    {
67
        $this->directWrite();
68
    }
69
70
    /**
71
     * 遅延書き出しを有効にする
72
     */
73
    public static function enableLazyWrite()
74
    {
75
        self::$logger->lazyWrite();
76
    }
77
78
    /**
79
     * 即時書き出しを有効にする
80
     */
81
    public static function enableDirectWrite()
82
    {
83
        self::$logger->directWrite();
84
    }
85
86
    /**
87
     * インスタンスを返却する
88
     * @return WebStream\Module\Logger ロガーインスタンス
89
     */
90
    public static function getInstance()
91
    {
92
        return self::$logger;
93
    }
94
95
    /**
96
     * Loggerを初期化する
97
     * @param Container ログ設定コンテナ
98
     */
99
    public static function init(Container $config)
100
    {
101
        self::$config = $config;
102
        self::$logger = new Logger($config);
103
        self::$formatter = new LoggerFormatter($config);
104
    }
105
106
    /**
107
     * Loggerを終了する
108
     */
109
    public static function finalize()
110
    {
111
        self::$config = null;
112
        self::$logger = null;
113
        self::$formatter = null;
114
    }
115
116
    /**
117
     * Loggerが初期化済みかどうかチェックする
118
     * @param bool 初期化済みならtrue
119
     */
120
    public static function isInitialized()
121
    {
122
        return self::$logger !== null;
123
    }
124
125
    /**
126
     * Loggerメソッドの呼び出しを受ける
127
     * @param string メソッド名(ログレベル文字列)
128
     * @param array 引数
129
     */
130
    public static function __callStatic($level, $arguments)
131
    {
132
        if (self::$logger === null || self::$formatter === null) {
133
            if (self::$config !== null) {
134
                self::init(self::$config);
135
            } else {
136
                throw new LoggerException("Logger is not initialized.");
137
            }
138
        }
139
140
        call_user_func_array([self::$logger, "write"], array_merge([$level], $arguments));
141
    }
142
143
    /**
144
     * Outputterを設定する
145
     * @param array<IOutputter> $outputters Outputterリスト
146
     */
147
    public function setOutputter(array $outputters)
148
    {
149
        foreach ($outputters as $outputter) {
150
            if (!$outputter instanceof \WebStream\Log\Outputter\IOutputter) {
151
                throw new LoggerException("Log outputter must implement WebStream\Log\Outputter\IOutputter.");
152
            }
153
        }
154
        $this->outputters = $outputters;
155
    }
156
157
    /**
158
     * タイムスタンプを取得する
159
     * @return string タイムスタンプ
160
     */
161
    private function getTimeStamp()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
162
    {
163
        date_default_timezone_set('Asia/Tokyo');
164
        $msec = sprintf("%2d", floatval(microtime()) * 100);
165
166
        return strftime("%Y-%m-%d %H:%M:%S") . "," . $msec;
167
    }
168
169
    /**
170
     * ログを書き出す
171
     * @param string ログレベル文字列
172
     * @param string 出力文字列
173
     * @param array<mixed> 埋め込み値リスト
174
     */
175
    public function write($level, $msg, $context = null)
176
    {
177
        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...
178
            return;
179
        }
180
181
        if (is_array($context) && count($context) > 0) {
182
            // sprintfと同様の展開
183
            // [a-zA-Z0-9_-\.] 以外もキーには指定可能だが仕様としてこれ以外は不可とする
184
            preg_match_all('/\{\s*([a-zA-Z0-9._-]+)\s*?\}/', $msg, $matches);
185
            foreach ($matches[1] as $index => $value) {
186
                if (array_key_exists($value, $context)) {
187
                    $matches[1][$index] = $context[$value];
188
                } else {
189
                    unset($matches[0][$index]);
190
                }
191
            }
192
            $msg = str_replace($matches[0], $matches[1], $msg);
193
        }
194
195
        $this->rotate();
196
        try {
197
            if (count($this->outputters) > 0) {
198
                foreach ($this->outputters as $outputter) {
199
                    $outputter->write(self::$formatter->getFormattedMessage($msg, $level));
200
                }
201
            } else {
202
                error_log(self::$formatter->getFormattedMessage($msg, $level), 3, $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...
203
            }
204
        } catch (LoggerException $e) {
205
            throw $e;
206
        } catch (\Exception $e) {
207
            throw new LoggerException($e);
208
        }
209
    }
210
211
    /**
212
     * ログステータスファイルに書きこむ
213
     */
214
    private function writeStatus()
215
    {
216
        file_put_contents($this->logConfig->statusPath, intval(preg_replace('/^.*\s/', '', microtime())));
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...
217
    }
218
219
    /**
220
     * ログステータスファイルを読み込む
221
     * @return int UnixTime
222
     */
223
    private function readStatus()
224
    {
225
        $handle = fopen($this->logConfig->statusPath, "r");
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...
226
        $size = filesize($this->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...
227
        $content = fread($handle, $size);
228
        fclose($handle);
229
        if (!preg_match('/^\d{10}$/', $content)) {
230
            throw new LoggerException("Invalid log state file contents: " . $content);
231
        }
232
233
        return intval($content);
234
    }
235
236
    /**
237
     * ステータスファイルを作成する
238
     */
239
    private function createstatusPath()
240
    {
241
        // ステータスファイルがない場合は書きだす
242
        if (!is_file($this->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...
243
            $this->writeStatus();
244
        }
245
    }
246
247
    /**
248
     * ログファイルをアーカイブする
249
     * stream.log -> stream.(作成日時)-(現在日時).log
250
     * @param string ログファイルパス
251
     */
252
    private function rotate()
253
    {
254
        // ログファイルがない場合はローテートしない
255
        if (!realpath($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...
256
            return;
257
        }
258
        // ログローテート実行
259
        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...
260
            $this->rotateByCycle();
261
        } 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...
262
            $this->rotateBySize();
263
        }
264
    }
265
266
    /**
267
     * ローテートを実行する
268
     * @param integer 作成日時のUnixTime
269
     * @param integer 現在日時のUnixTime
270
     */
271
    private function runRotate($from, $to)
272
    {
273
        $from_date = date("YmdHis", $from);
274
        $to_date = date("YmdHis", $to);
275
        $archive_path = null;
0 ignored issues
show
Unused Code introduced by
$archive_path 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...
276
        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...
277
            $archive_path = "$matches[1].${from_date}-${to_date}.$matches[2]";
278
            // mvを実行
279
            rename($this->logConfig->logPath, $archive_path);
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...
280
            // ステータスファイルを削除
281
            unlink($this->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...
282
        }
283
    }
284
285
    /**
286
     * 時間単位でローテートする
287
     * stream.log -> stream.(作成日時)-(現在日時).log
288
     */
289 View Code Duplication
    private function rotateByCycle()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
290
    {
291
        $this->createstatusPath();
292
        $now = intval(preg_replace('/^.*\s/', '', microtime()));
293
        $createdAt = $this->readStatus($this->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...
Unused Code introduced by
The call to Logger::readStatus() has too many arguments starting with $this->logConfig->statusPath.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
294
295
        // ローテート周期を過ぎている場合はログファイルをアーカイブする
296
        $hour = intval(floor(($now - $createdAt) / 3600));
297
        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...
298
            $this->runRotate($createdAt, $now);
299
        }
300
    }
301
302
    /**
303
     * サイズ単位でローテートする
304
     * stream.log -> stream.(作成日時)-(現在日時).log
305
     */
306 View Code Duplication
    private function rotateBySize()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
307
    {
308
        $this->createstatusPath();
309
        $now = intval(preg_replace('/^.*\s/', '', microtime()));
310
        $createdAt = $this->readStatus();
311
312
        $size_kb = (int) floor(filesize($this->logConfig->logPath) / 1024);
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...
313
        // 指定したサイズより大きければローテート
314
        if ($size_kb >= $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...
315
            $this->runRotate($createdAt, $now);
316
        }
317
    }
318
319
    /**
320
     * ログ出力パスを返却する
321
     * @return string ログ出力パス
322
     */
323
    public function getLogPath()
324
    {
325
        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...
326
    }
327
328
    /**
329
     * ログローテートサイクルを返却する
330
     * @return string ログ出力パス
331
     */
332
    public function getLogRotateCycle()
333
    {
334
        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...
335
    }
336
337
    /**
338
     * ログローテートサイズを返却する
339
     * @return string ログ出力パス
340
     */
341
    public function getLogRotateSize()
342
    {
343
        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...
344
    }
345
346
    /**
347
     * 遅延書き出しを有効にする
348
     */
349
    public function lazyWrite()
350
    {
351
        foreach ($this->outputters as $outputter) {
352
            if ($outputter instanceof \WebStream\Log\Outputter\ILazyWriter) {
353
                $outputter->enableLazyWrite();
354
            }
355
        }
356
    }
357
358
    /**
359
     * 即時書き出しを有効にする
360
     */
361
    public function directWrite()
362
    {
363
        foreach ($this->outputters as $outputter) {
364
            if ($outputter instanceof \WebStream\Log\Outputter\ILazyWriter) {
365
                $outputter->enableDirectWrite();
366
            }
367
        }
368
    }
369
}
370