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

keradus / PHP-CS-Fixer / 16715837382

04 Aug 2025 06:34AM UTC coverage: 94.728% (+0.01%) from 94.716%
16715837382

push

github

keradus
chore: switch to official checkstyle.xsd

28212 of 29782 relevant lines covered (94.73%)

45.91 hits per line

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

94.44
/src/Error/SourceExceptionFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz RumiƄski <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer\Error;
16

17
/**
18
 * @readonly
19
 *
20
 * @internal
21
 */
22
final class SourceExceptionFactory
23
{
24
    /**
25
     * @param array{class: class-string<\Throwable>, message: string, code: int, file: string, line: int} $error
26
     */
27
    public static function fromArray(array $error): \Throwable
28
    {
29
        $exceptionClass = $error['class'];
3✔
30

31
        try {
32
            $exception = new $exceptionClass($error['message'], $error['code']);
3✔
33

34
            if (
35
                $exception->getMessage() !== $error['message']
2✔
36
                || $exception->getCode() !== $error['code']
2✔
37
            ) {
38
                throw new \RuntimeException('Failed to create exception from array. Message and code are not the same.');
2✔
39
            }
40
        } catch (\Throwable $e) {
1✔
41
            $exception = new \RuntimeException(
1✔
42
                \sprintf('[%s] %s', $exceptionClass, $error['message']),
1✔
43
                $error['code']
1✔
44
            );
1✔
45
        }
46

47
        try {
48
            $exceptionReflection = new \ReflectionClass($exception);
3✔
49
            foreach (['file', 'line'] as $property) {
3✔
50
                $propertyReflection = $exceptionReflection->getProperty($property);
3✔
51
                $propertyReflection->setAccessible(true);
3✔
52
                $propertyReflection->setValue($exception, $error[$property]);
3✔
53
                $propertyReflection->setAccessible(false);
3✔
54
            }
55
        } catch (\Throwable $reflectionException) {
×
56
            // Ignore if we were not able to set file/line properties. In most cases it should be fine,
57
            // we just need to make sure nothing is broken when we recreate errors from raw data passed from worker.
58
        }
59

60
        return $exception;
3✔
61
    }
62
}
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