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

The-oGlow / ezlogging / 19987910145

06 Dec 2025 11:34AM UTC coverage: 80.965% (-3.3%) from 84.295%
19987910145

push

github

web-flow
Merge pull request #12 from The-oGlow/develop

Develop

40 of 66 new or added lines in 2 files covered. (60.61%)

2 existing lines in 1 file now uncovered.

302 of 373 relevant lines covered (80.97%)

12.84 hits per line

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

86.36
/src/Tools/EnvironmentVariableTrait.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 Composer\Factory;
17

18
trait EnvironmentVariableTrait
19
{
20
    /**
21
     * @param string $homeVariable
22
     *
23
     * @return string
24
     */
25
    final public static function getHome(string $homeVariable = 'HOME'): string
3✔
26
    {
27
        $home = getenv($homeVariable);
3✔
28
        /** @psalm-suppress RiskyTruthyFalsyComparison */
29
        if ($homeVariable == 'HOME' && empty($home)) {
3✔
30
            // we are on windows?
NEW
31
            $home = getenv('USERPROFILE');
×
32
        }
33
        if (is_bool($home)) {
3✔
34
            $home = '';
2✔
35
        }
36

37
        return $home;
3✔
38
    }
39

40
    /**
41
     * @return string
42
     */
43
    final public static function getProjectRoot(): string
1✔
44
    {
45
        $projectRoot = self::getComposerFilePath();
1✔
46
        if (empty($projectRoot)) {
1✔
NEW
47
            $projectRoot = self::getProjectRootFallback();
×
48
        }
49

50
        return (string)realpath($projectRoot);
1✔
51
    }
52

53
    /**
54
     * @return string
55
     */
56
    private static function getComposerFilePath(): string
2✔
57
    {
58
        $composerFile = Factory::getComposerFile();
2✔
59
        $composerPath = (string)realpath(dirname($composerFile));
2✔
60
        if ('.' == $composerPath) {
2✔
NEW
61
            $composerPath = '';
×
62
        }
63

64
        return $composerPath;
2✔
65
    }
66

67
    /**
68
     * @param int $folderOffset
69
     *
70
     * @return string
71
     */
72
    private static function getProjectRootFallback(int $folderOffset = 2): string
1✔
73
    {
74
        $rootClazz = new \ReflectionClass(EnvironmentVariableTrait::class);
1✔
75
        $rootPath  = dirname((string)realpath((string)$rootClazz->getFileName()));
1✔
76

77
        return (string)realpath($rootPath . str_repeat(DIRECTORY_SEPARATOR . '..', $folderOffset));
1✔
78
    }
79
}
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