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

The-oGlow / ezlogging / 20849603425

09 Jan 2026 10:53AM UTC coverage: 81.0% (+0.2%) from 80.84%
20849603425

push

github

ollily
#1: add  / tested

16 of 19 new or added lines in 1 file covered. (84.21%)

324 of 400 relevant lines covered (81.0%)

12.52 hits per line

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

84.21
/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\ConsoleLogger;
17
use Monolog\Formatter\EasyGoingFormatter;
18
use Monolog\Handler\ErrorLogHandler;
19
use Monolog\Logger;
20
use Monolog\Processor\PaddingProcessor;
21
use Psr\Log\LoggerInterface;
22

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

27
    public const  ERR_CODE_DEFAULT = 1;
28

29
    private const ERR_CODE_MAX = 254;
30

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

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

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

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

59
        return self::$logger;
4✔
60
    }
61

62
    /**
63
     * @param int    $errorCode
64
     * @param string $errorMessage
65
     * @param bool   $unitTest     TRUE=don't call exit(), it's an unit test (Default: FALSE)
66
     *
67
     * @return int errorcode
68
     *
69
     * @SuppressWarnings("PHPMD.ExitExpression")
70
     */
71
    public static function stop(int $errorCode = self::ERR_CODE_DEFAULT, string $errorMessage = '', bool $unitTest = false): int
4✔
72
    {
73
        if ($errorCode < self::ERR_CODE_DEFAULT || $errorCode > self::ERR_CODE_MAX) {
4✔
74
            $errorCode = self::ERR_CODE_DEFAULT;
3✔
75
        }
76
        if (empty($errorMessage)) {
4✔
77
            $errorMessage = self::ERR_MSG_DEFAULT;
3✔
78
        }
79
        self::getLogger()->emergency($errorMessage, [$errorCode]);
4✔
80
        if (!$unitTest) {
4✔
NEW
81
            exit($errorCode);
×
82
        } else {
83
            return $errorCode;
4✔
84
        }
85
    }
86
}
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