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

SwiftlyPHP / dependency / a18d15cd-ec6e-492f-9f4b-dcb03b5b3387

11 Sep 2023 01:24PM UTC coverage: 66.213%. Remained the same
a18d15cd-ec6e-492f-9f4b-dcb03b5b3387

push

circleci

clvarley
Fixed incorrect message separator

2 of 2 new or added lines in 1 file covered. (100.0%)

243 of 367 relevant lines covered (66.21%)

4.4 hits per line

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

0.0
/src/Exception/ServiceInstantiationException.php
1
<?php
2

3
namespace Swiftly\Dependency\Exception;
4

5
use Swiftly\Dependency\Exception\NestedServiceException;
6
use RuntimeException;
7
use Exception;
8

9
use function sprintf;
10
use function str_repeat;
11
use function implode;
12

13
/**
14
 * Exception used to indicate an error occured while instantiating a service
15
 *
16
 * @api
17
 */
18
final class ServiceInstantiationException extends RuntimeException
19
{
20
    /**
21
     * Indicate an error occured while creating this service
22
     *
23
     * @param non-empty-string $service Service name
24
     * @param Exception $reason         Failure reason
25
     */
26
    public function __construct(string $service, Exception $reason)
27
    {
28
        parent::__construct(
×
29
            sprintf(
×
30
                "Encountered an error while resolving service '%s':\n%s",
×
31
                $service,
×
32
                self::unwrapReason($reason)
×
33
            ),
×
34
            0,
×
35
            $reason
×
36
        );
×
37
    }
38

39
    /**
40
     * Unwrap the exception stack and generate a readable string
41
     * 
42
     * @param Exception $reason Top-most reason
43
     * @return string           Reason message
44
     */
45
    private static function unwrapReason(Exception $reason): string
46
    {
47
        $depth = 1;
×
48
        $messages = [];
×
49

50
        do {
51
            if ($reason instanceof NestedServiceException) {
×
52
                $depth++;
×
53
                continue;
×
54
            }
55

56
            $messages[] = str_repeat("\t", $depth) . $reason->getMessage();
×
57
        } while (($reason = $reason->getPrevious()) !== null);
×
58

59
        return implode("\n", $messages);
×
60
    }
61
}
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