Skip to content

Commit 2b1de13

Browse files
author
Dominik Liebler
committed
PHP7 Delegation
1 parent df6fadf commit 2b1de13

File tree

5 files changed

+9
-31
lines changed

5 files changed

+9
-31
lines changed

More/Delegation/JuniorDeveloper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class JuniorDeveloper
66
{
7-
public function writeBadCode()
7+
public function writeBadCode(): string
88
{
99
return 'Some junior developer generated code...';
1010
}

More/Delegation/README.rst

-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ Code
2323

2424
You can also find these code on `GitHub`_
2525

26-
Usage.php
27-
28-
.. literalinclude:: Usage.php
29-
:language: php
30-
:linenos:
31-
3226
TeamLead.php
3327

3428
.. literalinclude:: TeamLead.php

More/Delegation/TeamLead.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@
44

55
class TeamLead
66
{
7-
/** @var JuniorDeveloper */
8-
protected $slave;
7+
/**
8+
* @var JuniorDeveloper
9+
*/
10+
private $junior;
911

1012
/**
11-
* Give junior developer into teamlead submission.
12-
*
1313
* @param JuniorDeveloper $junior
1414
*/
1515
public function __construct(JuniorDeveloper $junior)
1616
{
17-
$this->slave = $junior;
17+
$this->junior = $junior;
1818
}
1919

20-
/**
21-
* TeamLead drink coffee, junior work.
22-
*
23-
* @return mixed
24-
*/
25-
public function writeCode()
20+
public function writeCode(): string
2621
{
27-
return $this->slave->writeBadCode();
22+
return $this->junior->writeBadCode();
2823
}
2924
}

More/Delegation/Tests/DelegationTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
use DesignPatterns\More\Delegation;
66

7-
/**
8-
* DelegationTest tests the delegation pattern.
9-
*/
107
class DelegationTest extends \PHPUnit_Framework_TestCase
118
{
129
public function testHowTeamLeadWriteCode()
1310
{
1411
$junior = new Delegation\JuniorDeveloper();
1512
$teamLead = new Delegation\TeamLead($junior);
13+
1614
$this->assertEquals($junior->writeBadCode(), $teamLead->writeCode());
1715
}
1816
}

More/Delegation/Usage.php

-9
This file was deleted.

0 commit comments

Comments
 (0)