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

keradus / PHP-CS-Fixer / 16715846151

04 Aug 2025 06:35AM UTC coverage: 94.716% (-0.01%) from 94.728%
16715846151

push

github

web-flow
Merge branch 'master' into checkstyle

55 of 69 new or added lines in 18 files covered. (79.71%)

3 existing lines in 1 file now uncovered.

28230 of 29805 relevant lines covered (94.72%)

45.9 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
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

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

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

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

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