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

Cecilapp / Cecil / 5059343628

pending completion
5059343628

Pull #1701

github

GitHub
Merge f0220e4a5 into 9832ed7ee
Pull Request #1701: feat: enhances timing info

10 of 10 new or added lines in 2 files covered. (100.0%)

2792 of 4132 relevant lines covered (67.57%)

0.68 hits per line

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

97.22
/src/Util.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Cecil;
15

16
class Util
17
{
18
    /**
19
     * Formats a class name.
20
     *
21
     * ie: "Cecil\Step\PostProcessHtml" become "PostProcessHtml"
22
     *
23
     * @param object $class
24
     */
25
    public static function formatClassName($class, array $options = []): string
26
    {
27
        $lowercase = false;
1✔
28
        extract($options, EXTR_IF_EXISTS);
1✔
29

30
        $className = substr(strrchr(\get_class($class), '\\'), 1);
1✔
31
        if ($lowercase) {
1✔
32
            $className = strtolower($className);
1✔
33
        }
34

35
        return $className;
1✔
36
    }
37

38
    /**
39
     * Converts an array of strings into a path.
40
     */
41
    public static function joinPath(string ...$path): string
42
    {
43
        $path = array_filter($path, function ($path) {
1✔
44
            return !empty($path) && !\is_null($path);
1✔
45
        });
1✔
46
        array_walk($path, function (&$value, $key) {
1✔
47
            $value = str_replace('\\', '/', $value);
1✔
48
            $value = rtrim($value, '/');
1✔
49
            $value = $key == 0 ? $value : ltrim($value, '/');
1✔
50
        });
1✔
51

52
        return implode('/', $path);
1✔
53
    }
54

55
    /**
56
     * Converts an array of strings into a system path.
57
     */
58
    public static function joinFile(string ...$path): string
59
    {
60
        array_walk($path, function (&$value, $key) use (&$path) {
1✔
61
            $value = str_replace(['\\', '/'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $value);
1✔
62
            $value = rtrim($value, DIRECTORY_SEPARATOR);
1✔
63
            $value = $key == 0 ? $value : ltrim($value, DIRECTORY_SEPARATOR);
1✔
64
            // unset entry with empty value
65
            if (empty($value)) {
1✔
66
                unset($path[$key]);
1✔
67
            }
68
        });
1✔
69

70
        return implode(DIRECTORY_SEPARATOR, $path);
1✔
71
    }
72

73
    /**
74
     * Converts memory size for human.
75
     */
76
    public static function convertMemory($size): string
77
    {
78
        if ($size === 0) {
1✔
79
            return '0';
×
80
        }
81
        $unit = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
1✔
82

83
        return sprintf('%s %s', round($size / pow(1024, ($i = floor(log($size, 1024)))), 2), $unit[$i]);
1✔
84
    }
85

86
    /**
87
     * Converts microtime interval for human.
88
     */
89
    public static function convertMicrotime(float $start): string
90
    {
91
        $time = microtime(true) - $start;
1✔
92
        if ($time < 1) {
1✔
93
            return sprintf('%s ms', round($time * 1000, 0));
1✔
94
        }
95

96
        return sprintf('%s s', round($time, 2));
1✔
97
    }
98

99
    /**
100
     * Loads class from the source directory, in the given subdirectory $dir.
101
     */
102
    public static function autoload(Builder $builder, string $dir): void
103
    {
104
        spl_autoload_register(function ($className) use ($builder, $dir) {
1✔
105
            $classFile = Util::joinFile($builder->getConfig()->getSourceDir(), $dir, "$className.php");
1✔
106
            if (file_exists($classFile)) {
1✔
107
                require $classFile;
1✔
108
            }
109
        });
1✔
110
    }
111
}
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