Skip to content

Commit 959eab1

Browse files
committed
Method::from() sets visibility 'public'
1 parent c04ea15 commit 959eab1

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

src/PhpGenerator/Method.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ public static function from($from)
8080
$method->parameters[$param->getName()] = Parameter::from($param);
8181
}
8282
if ($from instanceof \ReflectionMethod) {
83+
$isInterface = $from->getDeclaringClass()->isInterface();
8384
$method->static = $from->isStatic();
84-
$method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : NULL);
85+
$method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : ($isInterface ? NULL : 'public'));
8586
$method->final = $from->isFinal();
86-
$method->abstract = $from->isAbstract() && !$from->getDeclaringClass()->isInterface();
87+
$method->abstract = $from->isAbstract() && !$isInterface;
8788
$method->body = $from->isAbstract() ? FALSE : '';
8889
}
8990
$method->returnReference = $from->returnsReference();

tests/PhpGenerator/ClassType.from.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class Class1 implements Interface1
1919
/**
2020
* @return Class1
2121
*/
22-
function func1()
22+
public function func1()
2323
{
2424
}
2525

@@ -53,7 +53,7 @@ class Class2 extends Class1 implements Interface2
5353
}
5454

5555

56-
final function func2()
56+
final public function func2()
5757
{
5858
}
5959

tests/PhpGenerator/ClassType.from.php7.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class anonymous
55
private $b;
66

77

8-
function a()
8+
public function a()
99
{
1010
}
1111

@@ -19,7 +19,7 @@ class anonymous
1919
class anonymous extends Class1
2020
{
2121

22-
function a()
22+
public function a()
2323
{
2424
}
2525

tests/PhpGenerator/ClassType.from.php71.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
class ClassA
22
{
33

4-
function func1(A $a, ?B $b, C $c = NULL, D $d = NULL, E $e, ?int $i = 1, ?array $arr = [])
4+
public function func1(A $a, ?B $b, C $c = NULL, D $d = NULL, E $e, ?int $i = 1, ?array $arr = [])
55
{
66
}
77

88

9-
function func2(): ?stdClass
9+
public function func2(): ?stdClass
1010
{
1111
}
1212

1313

14-
function func3(): void
14+
public function func3(): void
1515
{
1616
}
1717

tests/PhpGenerator/ClassType.from.trait.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
trait Trait1
55
{
66

7-
function func1()
7+
public function func1()
88
{
99
}
1010

@@ -22,7 +22,7 @@ trait Trait2
2222
abstract class Class1
2323
{
2424

25-
function func1()
25+
public function func1()
2626
{
2727
}
2828

tests/PhpGenerator/ClassType.inheritance.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class B extends A
77
private $f;
88

99

10-
function bar()
10+
public function bar()
1111
{
1212
}
1313

0 commit comments

Comments
 (0)