Conversation
|
Code Climate has analyzed commit a034c02 and detected 0 issues on this pull request. View more on Code Climate. |
| // need to reduce the file size | ||
| $file = file($this->filename); | ||
| $file = array_splice($file, ceil(count($file) * $this->reduceRatio)); | ||
| $reduceLen= ($this->maxFileSize< (int)ini_get('memory_limit')*1024?$this->maxFileSize:(int)ini_get('memory_limit')*1024)*$this->reduceRatio; |
There was a problem hiding this comment.
For readability it might be better to change this from the shorthand if else to the full controll structure:
if ($this->maxFileSize < (int)ini_get('memory_limit') * 1024) {
$reduceLength = ($this->maxFileSize) * $this->reduceRatio;
} else {
$reduceLength = ((int)ini_get('memory_limit') * 1024) * $this->reduceRatio;
}
There was a problem hiding this comment.
A variable for (int)ini_get('memory_limit') * 1024 wouldn't also be out of place here
| $file = array_splice($file, ceil(count($file) * $this->reduceRatio)); | ||
| $reduceLen= ($this->maxFileSize< (int)ini_get('memory_limit')*1024?$this->maxFileSize:(int)ini_get('memory_limit')*1024)*$this->reduceRatio; | ||
| $size = filesize($this->filename)-$reduceLen; | ||
| $log =file_get_contents($this->filename, false, null, $size, $reduceLen ); |
There was a problem hiding this comment.
Try to be consistent with spacing. For example always surround = with spaces (eg. $log = file_get_contents(...)
There was a problem hiding this comment.
Also please omit the whitespace after the last argument (in this case $reduceLen)
| foreach ($file as $line) { | ||
| @fwrite($this->filehandle, $line); | ||
| foreach ($log as $line) { | ||
| @fwrite($this->filehandle, $line.PHP_EOL); |
There was a problem hiding this comment.
As per the PSR-2 standard, please surround the concatenation sign (.) with spaces.
$line . PHP_EOL
| $file = file($this->filename); | ||
| $file = array_splice($file, ceil(count($file) * $this->reduceRatio)); | ||
| $reduceLen= ($this->maxFileSize< (int)ini_get('memory_limit')*1024?$this->maxFileSize:(int)ini_get('memory_limit')*1024)*$this->reduceRatio; | ||
| $size = filesize($this->filename)-$reduceLen; |
There was a problem hiding this comment.
Please surround mathematical operators (+, -, *, /, %) with spaces
|
@ihar-aleksiaichuk Could you also add a comment on how to test the added functionality? |
|
You should probably cover this case with a unit test |
memory limit
reading file