-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNoDownMethodRule.php
More file actions
49 lines (39 loc) · 1.2 KB
/
Copy pathNoDownMethodRule.php
File metadata and controls
49 lines (39 loc) · 1.2 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);
namespace PhpStanMigrationRules\Rules\Phinx;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\RuleErrorBuilder;
/**
* @extends PhinxRule<ClassMethod>
*/
final class NoDownMethodRule extends PhinxRule
{
private const string RULE_IDENTIFIER = 'phinx.schema.noDownMethod';
private const string MESSAGE =
'Forbidden: "down" method. '
. 'Why: a "down" method enables rollbacks, which can cause data loss and break forward-only migration strategies. '
. 'Fix: use the "change" method for reversible migrations, or omit the rollback path entirely.';
public function getNodeType(): string
{
return ClassMethod::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (!$this->isPhinxMigration($scope)) {
return [];
}
if ($node->name->toString() !== 'down') {
return [];
}
if (!$node->isPublic()) {
return [];
}
return [
RuleErrorBuilder::message(self::MESSAGE)
->identifier(self::RULE_IDENTIFIER)
->build(),
];
}
}