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

The-oGlow / ezlogging / 21788760591

07 Feb 2026 11:36PM UTC coverage: 81.481% (+0.5%) from 81.0%
21788760591

push

github

ollily
#1: add  / tested

45 of 54 new or added lines in 10 files covered. (83.33%)

52 existing lines in 4 files now uncovered.

374 of 459 relevant lines covered (81.48%)

12.03 hits per line

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

86.36
/src/Tools/StopNow.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of ezlogging
7
 *
8
 * (c) 2025 Oliver Glowa, coding.glowa.com
9
 *
10
 * This source file is subject to the Apache-2.0 license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13

14
namespace ollily\Tools;
15

16
use Monolog\Formatter\EasyGoingFormatter;
17
use Monolog\Handler\ErrorLogHandler;
18
use Monolog\Logger;
19
use Monolog\Processor\PaddingProcessor;
20
use Psr\Log\LoggerInterface;
21

22
class StopNow
23
{
24
    public const  ERR_MSG_DEFAULT = 'Undefined reason to stop now!';
25

26
    public const  ERR_CODE_DEFAULT = 1;
27

28
    private const ERR_CODE_MAX = 254;
29

30
    /** @var LoggerInterface */
31
    private static $logger;
32

UNCOV
33
    private function __construct()
×
34
    {
UNCOV
35
        self::init();
×
36
    }
37

38
    private static function init(): void
11✔
39
    {
40
        /**
41
         * @psalm-suppress  DocblockTypeContradiction
42
         * @phpstan-ignore  function.impossibleType
43
         *  */
44
        if (is_null(self::$logger)) {
11✔
45
            $handler = new ErrorLogHandler();
1✔
46
            $handler->setFormatter(new EasyGoingFormatter());
1✔
47
            self::$logger = new Logger(StopNow::class, [$handler], [new PaddingProcessor()]);
1✔
48
        }
49
    }
50

51
    /**
52
     * @return LoggerInterface
53
     */
54
    private static function getLogger(): LoggerInterface
11✔
55
    {
56
        self::init();
11✔
57

58
        return self::$logger;
11✔
59
    }
60

61
    /**
62
     * @param \Throwable $throwable
63
     * @param bool       $unitTest  TRUE=don't call exit(), it's an unit test (Default: FALSE)
64
     *
65
     * @return int errorcode
66
     *
67
     * @SuppressWarnings("PHPMD.ExitExpression")
68
     */
69
    public static function stopException(\Throwable $throwable, bool $unitTest = false): int
7✔
70
    {
71
        $errMsg = sprintf('{%s} - %s', get_class($throwable), $throwable->getMessage());
7✔
72

73
        /** @psalm-suppress PossiblyInvalidArgument */
74
        return static::stop($throwable->getCode(), $errMsg, $unitTest);
7✔
75
    }
76

77
    /**
78
     * @param int    $errorCode
79
     * @param string $errorMessage
80
     * @param bool   $unitTest     TRUE=don't call exit(), it's an unit test (Default: FALSE)
81
     *
82
     * @return int errorcode
83
     *
84
     * @SuppressWarnings("PHPMD.ExitExpression")
85
     */
86
    public static function stop(int $errorCode = self::ERR_CODE_DEFAULT, string $errorMessage = '', bool $unitTest = false): int
11✔
87
    {
88
        if ($errorCode < self::ERR_CODE_DEFAULT || $errorCode > self::ERR_CODE_MAX) {
11✔
89
            $errorCode = self::ERR_CODE_DEFAULT;
8✔
90
        }
91
        if (empty($errorMessage)) {
11✔
92
            $errorMessage = self::ERR_MSG_DEFAULT;
3✔
93
        }
94
        self::getLogger()->emergency($errorMessage, [$errorCode]);
11✔
95
        if (!$unitTest) {
11✔
UNCOV
96
            die($errorCode);
×
97
        } else {
98
            return $errorCode;
11✔
99
        }
100
    }
101
}
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

© 2026 Coveralls, Inc