Skip to content

Commit ea2a912

Browse files
Refactor
1 parent 60fe3d7 commit ea2a912

File tree

8 files changed

+40
-31
lines changed

8 files changed

+40
-31
lines changed

src/Node/File.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ private function newMethod(string $className, Method $method, string $link): arr
636636
{
637637
$methodData = [
638638
'methodName' => $method->name(),
639-
'visibility' => $method->visibility(),
639+
'visibility' => $method->visibility()->value,
640640
'signature' => $method->signature(),
641641
'startLine' => $method->startLine(),
642642
'endLine' => $method->endLine(),

src/StaticAnalysis/CodeUnitFindingVisitor.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,17 @@ private function type(ComplexType|Identifier|Name $type): string
237237
return $type->toString();
238238
}
239239

240-
/**
241-
* @return 'private'|'protected'|'public'
242-
*/
243-
private function visibility(ClassMethod $node): string
240+
private function visibility(ClassMethod $node): Visibility
244241
{
245242
if ($node->isPrivate()) {
246-
return 'private';
243+
return Visibility::Private;
247244
}
248245

249246
if ($node->isProtected()) {
250-
return 'protected';
247+
return Visibility::Protected;
251248
}
252249

253-
return 'public';
250+
return Visibility::Public;
254251
}
255252

256253
private function processInterface(Interface_ $node): void

src/StaticAnalysis/Value/Method.php

+8-16
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@
2828
* @var non-negative-int
2929
*/
3030
private int $endLine;
31-
32-
/**
33-
* @var 'private'|'protected'|'public'
34-
*/
35-
private string $visibility;
31+
private Visibility $visibility;
3632

3733
/**
3834
* @var non-empty-string
@@ -45,14 +41,13 @@
4541
private int $cyclomaticComplexity;
4642

4743
/**
48-
* @param non-empty-string $name
49-
* @param non-negative-int $startLine
50-
* @param non-negative-int $endLine
51-
* @param non-empty-string $signature
52-
* @param 'private'|'protected'|'public' $visibility
53-
* @param positive-int $cyclomaticComplexity
44+
* @param non-empty-string $name
45+
* @param non-negative-int $startLine
46+
* @param non-negative-int $endLine
47+
* @param non-empty-string $signature
48+
* @param positive-int $cyclomaticComplexity
5449
*/
55-
public function __construct(string $name, int $startLine, int $endLine, string $signature, string $visibility, int $cyclomaticComplexity)
50+
public function __construct(string $name, int $startLine, int $endLine, string $signature, Visibility $visibility, int $cyclomaticComplexity)
5651
{
5752
$this->name = $name;
5853
$this->startLine = $startLine;
@@ -94,10 +89,7 @@ public function signature(): string
9489
return $this->signature;
9590
}
9691

97-
/**
98-
* @return 'private'|'protected'|'public'
99-
*/
100-
public function visibility(): string
92+
public function visibility(): Visibility
10193
{
10294
return $this->visibility;
10395
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;
11+
12+
/**
13+
* @internal This enumeration is not covered by the backward compatibility promise for phpunit/php-code-coverage
14+
*/
15+
enum Visibility: string
16+
{
17+
case Public = 'public';
18+
case Protected = 'protected';
19+
case Private = 'private';
20+
}

tests/tests/StaticAnalysis/CodeUnitFindingVisitorTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testDoesNotFindAnonymousClass(): void
5252

5353
$this->assertSame('method', $method->name());
5454
$this->assertSame('method(): string', $method->signature());
55-
$this->assertSame('public', $method->visibility());
55+
$this->assertSame(Visibility::Public, $method->visibility());
5656
$this->assertSame(6, $method->startLine());
5757
$this->assertSame(16, $method->endLine());
5858
$this->assertSame(1, $method->cyclomaticComplexity());
@@ -200,7 +200,7 @@ public function testDetailsAboutExtendedClassesImplementedInterfacesAndUsedTrait
200200
$this->assertSame('four', $method->name());
201201
$this->assertSame(21, $method->startLine());
202202
$this->assertSame(23, $method->endLine());
203-
$this->assertSame('public', $method->visibility());
203+
$this->assertSame(Visibility::Public, $method->visibility());
204204
$this->assertSame('four(): void', $method->signature());
205205
$this->assertSame(1, $method->cyclomaticComplexity());
206206

@@ -233,7 +233,7 @@ public function testDetailsAboutExtendedClassesImplementedInterfacesAndUsedTrait
233233
$this->assertSame('five', $method->name());
234234
$this->assertSame(28, $method->startLine());
235235
$this->assertSame(30, $method->endLine());
236-
$this->assertSame('public', $method->visibility());
236+
$this->assertSame(Visibility::Public, $method->visibility());
237237
$this->assertSame('five(A $a, B $b): void', $method->signature());
238238
$this->assertSame(1, $method->cyclomaticComplexity());
239239

tests/tests/StaticAnalysis/Value/ClassTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testMayUseTraits(): void
7979

8080
public function testMayHaveMethods(): void
8181
{
82-
$methods = [new Method('', 0, 0, '', '', 0)];
82+
$methods = [new Method('', 0, 0, '', Visibility::Public, 0)];
8383

8484
$this->assertSame($methods, $this->class(methods: $methods)->methods());
8585
}

tests/tests/StaticAnalysis/Value/MethodTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testHasSignature(): void
3939

4040
public function testHasVisibility(): void
4141
{
42-
$this->assertSame('public', $this->method()->visibility());
42+
$this->assertSame(Visibility::Public, $this->method()->visibility());
4343
}
4444

4545
public function testHasCyclomaticComplexity(): void
@@ -54,7 +54,7 @@ private function method(): Method
5454
1,
5555
2,
5656
'the-signature',
57-
'public',
57+
Visibility::Public,
5858
3,
5959
);
6060
}

tests/tests/StaticAnalysis/Value/TraitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testHasEndLine(): void
4444

4545
public function testMayHaveMethods(): void
4646
{
47-
$methods = [new Method('', 0, 0, '', '', 0)];
47+
$methods = [new Method('', 0, 0, '', Visibility::Public, 0)];
4848

4949
$this->assertSame($methods, $this->trait(methods: $methods)->methods());
5050
}

0 commit comments

Comments
 (0)