diff --git a/src/NodeManipulator/ClassInsertManipulator.php b/src/NodeManipulator/ClassInsertManipulator.php index c56b859fefc..7328d93050a 100644 --- a/src/NodeManipulator/ClassInsertManipulator.php +++ b/src/NodeManipulator/ClassInsertManipulator.php @@ -59,7 +59,7 @@ public function addPropertyToClass(Class_ $class, string $name, ?Type $type): vo */ private function insertBefore(array $stmts, Stmt $stmt, int $key): array { - array_splice($stmts, $key, 0, [$stmt]); + array_splice($stmts, max(0, $key - 1), 0, [$stmt]); return $stmts; }