forked from guanguans/rector-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectorErrorException.php
More file actions
49 lines (44 loc) · 1.62 KB
/
RectorErrorException.php
File metadata and controls
49 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
/**
* Copyright (c) 2025-2026 guanguans<ityaozm@gmail.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/guanguans/rector-rules
*/
namespace Guanguans\RectorRules\Exception;
use Guanguans\RectorRules\Contract\ThrowableContract;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;
use PhpParser\Error;
use Rector\Rector\AbstractRector;
/**
* @see \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException
*/
final class RectorErrorException extends Error implements ThrowableContract
{
/**
* @throws \ReflectionException
*/
public function __construct(AbstractRector $rector, string $message, array $attributes = [])
{
parent::__construct(
\sprintf(
'[%s:%s%s] %s',
(new \ReflectionObject($rector))->getShortName(),
(string) Str::of((fn (): string => $this->getFile()->getFilePath())->bindTo($rector, $rector)()) // @phpstan-ignore method.nonObject
// ->chopStart(getcwd().\DIRECTORY_SEPARATOR)
// ->replaceStart(getcwd().\DIRECTORY_SEPARATOR, '')
->whenStartsWith(
$cmd = getcwd().\DIRECTORY_SEPARATOR,
static fn (Stringable $stringable): Stringable => $stringable->replaceFirst($cmd, '')
),
isset($attributes['startLine']) ? ":{$attributes['startLine']}" : '',
$message
),
$attributes
);
}
}