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

rotexsoft / versatile-collections / 6042672854

31 Aug 2023 09:32PM UTC coverage: 98.445% (-0.09%) from 98.532%
6042672854

push

github

rotimi
Upgraded rector to 0.18

1076 of 1093 relevant lines covered (98.44%)

28.94 hits per line

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

95.65
/src/Utils.php
1
<?php /** @noinspection PhpFullyQualifiedNameUsageInspection */
2
declare(strict_types=1);
3
namespace VersatileCollections;
4

5
use Closure;
6
use Exception;
7
use InvalidArgumentException;
8
use Throwable;
9

10
/**
11
 * Description of Utils
12
 *
13
 * @author rotimi
14
 */
15
class Utils {
16

17
    /**
18
     *
19
     * @param mixed $var
20
     */
21
    public static function gettype($var): string {
22
        
23
        return \is_object($var) ? \get_class($var) : \gettype($var);
396✔
24
    }
25

26
    public static function getClosureFromCallable(callable $callable): Closure {
27

28
        return ($callable instanceof Closure)? $callable : Closure::fromCallable($callable);
90✔
29
    }
30
    
31
    public static function bindObjectAndScopeToClosure(Closure $closure, object $newthis): Closure {
32

33
        try {
34
            $result = Closure::bind($closure, $newthis);
84✔
35
            
36
            if ($result !== null) {
84✔
37
                
38
                return $result;
84✔
39
            }
40
            
41
            throw new \Exception();
×
42
            
43
        } catch (Exception $ex) {
6✔
44
            
45
            $function = __FUNCTION__;
6✔
46
            $class = static::class;
6✔
47
            $msg = "Error [{$class}::{$function}(...)]: Could not bind \$newthis to the supplied closure"
6✔
48
                . PHP_EOL . PHP_EOL . static::getThrowableAsStr($ex);
6✔
49

50
            // The bind failed
51
            throw new InvalidArgumentException($msg, (int)$ex->getCode(), $ex);
6✔
52
        }
53
    }
54

55
    /** @noinspection DuplicatedCode */
56
    public static function getThrowableAsStr(Throwable $e, string $eol=PHP_EOL): string {
57

58
        $previous_throwable = $e; 
12✔
59
        $message = '';
12✔
60

61
        do {
62
            $message .= "Exception / Error Code: {$previous_throwable->getCode()}"
12✔
63
                . $eol . "Exception / Error Class: " . \get_class($previous_throwable)
12✔
64
                . $eol . "File: {$previous_throwable->getFile()}"
12✔
65
                . $eol . "Line: {$previous_throwable->getLine()}"
12✔
66
                . $eol . "Message: {$previous_throwable->getMessage()}" . $eol
12✔
67
                . $eol . "Trace: {$eol}{$previous_throwable->getTraceAsString()}{$eol}{$eol}";
12✔
68
                
69
            $previous_throwable = $previous_throwable->getPrevious();
12✔
70
        } while( $previous_throwable instanceof Throwable );
12✔
71
        
72
        return $message;
12✔
73
    }
74
}
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