• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

contributte / logging / #186

pending completion
#186

push

github

f3l1x
Composer: allow codesniffer

107 of 251 relevant lines covered (42.63%)

0.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.61
/src/AbstractLogger.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Logging;
4

5
use DirectoryIterator;
6
use Throwable;
7

8
/**
9
 * AbstractTracyLogger based on official Tracy\Logger (@copyright David Grudl)
10
 */
11
abstract class AbstractLogger implements ILogger
12
{
13

14
        /** @var string */
15
        protected $directory;
16

17
        public function __construct(string $directory)
18
        {
19
                $this->directory = $directory;
1✔
20
        }
1✔
21

22
        public function setDirectory(string $directory): void
23
        {
24
                $this->directory = $directory;
×
25
        }
×
26

27
        protected function getExceptionFile(Throwable $exception): string
28
        {
29
                $data = [];
1✔
30

31
                while ($exception) {
1✔
32
                        $data[] = [
1✔
33
                                $exception->getMessage(),
1✔
34
                                $exception->getCode(),
1✔
35
                                $exception->getFile(),
1✔
36
                                $exception->getLine(),
1✔
37
                                array_map(function ($item): array {
1✔
38
                                        unset($item['args']);
1✔
39

40
                                        return $item;
1✔
41
                                }, $exception->getTrace()),
1✔
42
                        ];
43
                        $exception = $exception->getPrevious();
1✔
44
                }
45

46
                $hash = substr(md5(serialize($data)), 0, 10);
1✔
47

48
                foreach (new DirectoryIterator($this->directory) as $file) {
1✔
49
                        if ($file->isDot()) {
1✔
50
                                continue;
1✔
51
                        }
52

53
                        if ((bool) strpos($file->getBasename(), $hash)) {
×
54
                                return $file->getPathname();
×
55
                        }
56
                }
57

58
                return $this->directory . '/exception--' . @date('Y-m-d--H-i') . '--' . $hash . '.html'; // @ timezone may not be set
1✔
59
        }
60

61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc