Skip to content

Commit 9cb7660

Browse files
author
Dominik Liebler
committed
remove Interface-Suffix
1 parent 27bd89d commit 9cb7660

File tree

9 files changed

+47
-47
lines changed

9 files changed

+47
-47
lines changed

Behavioral/Visitor/Group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function getName(): string
2020
return sprintf('Group: %s', $this->name);
2121
}
2222

23-
public function accept(RoleVisitorInterface $visitor)
23+
public function accept(RoleVisitor $visitor)
2424
{
2525
$visitor->visitGroup($this);
2626
}

Behavioral/Visitor/README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ Code
2525

2626
You can also find this code on `GitHub`_
2727

28-
RoleVisitorInterface.php
28+
RoleVisitor.php
2929

30-
.. literalinclude:: RoleVisitorInterface.php
30+
.. literalinclude:: RoleVisitor.php
3131
:language: php
3232
:linenos:
3333

34-
RoleVisitor.php
34+
RecordingVisitor.php
3535

36-
.. literalinclude:: RoleVisitor.php
36+
.. literalinclude:: RecordingVisitor.php
3737
:language: php
3838
:linenos:
3939

@@ -65,4 +65,4 @@ Tests/VisitorTest.php
6565
:linenos:
6666

6767
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Visitor
68-
.. __: http://en.wikipedia.org/wiki/Visitor_pattern
68+
.. __: http://en.wikipedia.org/wiki/Visitor_pattern
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace DesignPatterns\Behavioral\Visitor;
5+
6+
class RecordingVisitor implements RoleVisitor
7+
{
8+
/**
9+
* @var Role[]
10+
*/
11+
private $visited = [];
12+
13+
public function visitGroup(Group $role)
14+
{
15+
$this->visited[] = $role;
16+
}
17+
18+
public function visitUser(User $role)
19+
{
20+
$this->visited[] = $role;
21+
}
22+
23+
/**
24+
* @return Role[]
25+
*/
26+
public function getVisited(): array
27+
{
28+
return $this->visited;
29+
}
30+
}

Behavioral/Visitor/Role.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
interface Role
77
{
8-
public function accept(RoleVisitorInterface $visitor);
8+
public function accept(RoleVisitor $visitor);
99
}

Behavioral/Visitor/RoleVisitor.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,13 @@
33

44
namespace DesignPatterns\Behavioral\Visitor;
55

6-
class RoleVisitor implements RoleVisitorInterface
6+
/**
7+
* Note: the visitor must not choose itself which method to
8+
* invoke, it is the Visitee that make this decision
9+
*/
10+
interface RoleVisitor
711
{
8-
/**
9-
* @var Role[]
10-
*/
11-
private $visited = [];
12+
public function visitUser(User $role);
1213

13-
public function visitGroup(Group $role)
14-
{
15-
$this->visited[] = $role;
16-
}
17-
18-
public function visitUser(User $role)
19-
{
20-
$this->visited[] = $role;
21-
}
22-
23-
/**
24-
* @return Role[]
25-
*/
26-
public function getVisited(): array
27-
{
28-
return $this->visited;
29-
}
14+
public function visitGroup(Group $role);
3015
}

Behavioral/Visitor/RoleVisitorInterface.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

Behavioral/Visitor/Tests/VisitorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
class VisitorTest extends TestCase
1010
{
1111
/**
12-
* @var Visitor\RoleVisitor
12+
* @var Visitor\RecordingVisitor
1313
*/
1414
private $visitor;
1515

1616
protected function setUp(): void
1717
{
18-
$this->visitor = new Visitor\RoleVisitor();
18+
$this->visitor = new Visitor\RecordingVisitor();
1919
}
2020

2121
public function provideRoles()

Behavioral/Visitor/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function getName(): string
2020
return sprintf('User %s', $this->name);
2121
}
2222

23-
public function accept(RoleVisitorInterface $visitor)
23+
public function accept(RoleVisitor $visitor)
2424
{
2525
$visitor->visitUser($this);
2626
}

Behavioral/Visitor/uml/uml.png

45.2 KB
Loading

0 commit comments

Comments
 (0)