Skip to content

Commit

Permalink
Add makeReadonly() to param builder
Browse files Browse the repository at this point in the history
(cherry picked from commit 11e2dcd)
  • Loading branch information
nikic committed May 19, 2023
1 parent 36a6dcd commit b68fb76
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/PhpParser/Builder/Param.php
Expand Up @@ -84,7 +84,7 @@ public function makeVariadic() {
}

/**
* Makes the parameter public.
* Makes the (promoted) parameter public.
*
* @return $this The builder instance (for fluid interface)
*/
Expand All @@ -95,7 +95,7 @@ public function makePublic() {
}

/**
* Makes the parameter protected.
* Makes the (promoted) parameter protected.
*
* @return $this The builder instance (for fluid interface)
*/
Expand All @@ -106,7 +106,7 @@ public function makeProtected() {
}

/**
* Makes the parameter private.
* Makes the (promoted) parameter private.
*
* @return $this The builder instance (for fluid interface)
*/
Expand All @@ -116,6 +116,17 @@ public function makePrivate() {
return $this;
}

/**
* Makes the (promoted) parameter readonly.
*
* @return $this The builder instance (for fluid interface)
*/
public function makeReadonly() {
$this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::READONLY);

return $this;
}

/**
* Adds an attribute group.
*
Expand Down
12 changes: 12 additions & 0 deletions test/PhpParser/Builder/ParamTest.php
Expand Up @@ -241,6 +241,18 @@ public function testMakePrivate() {
);
}

public function testMakeReadonly() {
$node = $this->createParamBuilder('test')
->makeReadonly()
->getNode()
;

$this->assertEquals(
new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::READONLY),
$node
);
}

public function testAddAttribute() {
$attribute = new Attribute(
new Name('Attr'),
Expand Down

0 comments on commit b68fb76

Please sign in to comment.