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

keradus / PHP-CS-Fixer / 17279562118

27 Aug 2025 09:47PM UTC coverage: 94.693%. Remained the same
17279562118

push

github

keradus
CS

28316 of 29903 relevant lines covered (94.69%)

45.61 hits per line

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

85.0
/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
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
23
 */
24
final class SourceExceptionFactory
25
{
26
    /**
27
     * @param array{class: class-string<\Throwable>, message: string, code: int, file: string, line: int} $error
28
     */
29
    public static function fromArray(array $error): \Throwable
30
    {
31
        $exceptionClass = $error['class'];
3✔
32

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

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

49
        try {
50
            $exceptionReflection = new \ReflectionClass($exception);
3✔
51
            foreach (['file', 'line'] as $property) {
3✔
52
                $propertyReflection = $exceptionReflection->getProperty($property);
3✔
53

54
                if (\PHP_VERSION_ID < 8_01_00) {
3✔
55
                    $propertyReflection->setAccessible(true);
×
56
                }
57

58
                $propertyReflection->setValue($exception, $error[$property]);
3✔
59

60
                if (\PHP_VERSION_ID < 8_01_00) {
3✔
61
                    $propertyReflection->setAccessible(false);
×
62
                }
63
            }
64
        } catch (\Throwable $reflectionException) {
×
65
            // Ignore if we were not able to set file/line properties. In most cases it should be fine,
66
            // we just need to make sure nothing is broken when we recreate errors from raw data passed from worker.
67
        }
68

69
        return $exception;
3✔
70
    }
71
}
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