| Conditions | 8 |
| Paths | 7 |
| Total Lines | 32 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 46 | public static function count(string $file, bool $countEmpty = false): ?int |
||
| 47 | { |
||
| 48 | if (!file_exists($file)) { |
||
| 49 | return null; |
||
| 50 | } |
||
| 51 | |||
| 52 | $lines = 0; |
||
| 53 | $handle = fopen($file, 'r'); |
||
| 54 | while (!feof($handle)) { |
||
| 55 | $line = fgets($handle, 8192); |
||
| 56 | |||
| 57 | if (false === $line) { |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | |||
| 61 | $lastChar = mb_strlen((string) $line) - 1; |
||
| 62 | |||
| 63 | if ($lastChar == 0) { |
||
| 64 | if ($countEmpty) { |
||
| 65 | ++$lines; |
||
| 66 | } |
||
| 67 | continue; |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($line[$lastChar] == "\n" || $line[$lastChar] == "\r") { |
||
| 71 | ++$lines; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | fclose($handle); |
||
| 76 | |||
| 77 | return $lines; |
||
| 78 | } |
||
| 94 |