Passed
Push — master ( b674ac...2bc77e )
by Kirill
04:21
created

Exception::withLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Attributes package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Attributes\Internal;
13
14
/**
15
 * @internal Exception is an internal library class, please do not use it in your code.
16
 * @psalm-internal Spiral\Attributes
17
 */
18
class Exception
19
{
20
    /**
21
     * @param \Throwable $e
22
     * @param string $file
23
     * @param int $line
24
     * @return \Throwable
25
     * @throws \ReflectionException
26
     */
27
    public static function withLocation(\Throwable $e, string $file, int $line): \Throwable
28
    {
29
        $fileProperty = new \ReflectionProperty($e, 'file');
30
        $fileProperty->setAccessible(true);
31
        $fileProperty->setValue($e, $file);
32
33
        $lineProperty = new \ReflectionProperty($e, 'line');
34
        $lineProperty->setAccessible(true);
35
        $lineProperty->setValue($e, $line);
36
37
        return $e;
38
    }
39
}