From 2b1de13391b93179c640cf14e82838c41f004e7c Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Thu, 22 Sep 2016 15:28:46 +0200 Subject: [PATCH] PHP7 Delegation --- More/Delegation/JuniorDeveloper.php | 2 +- More/Delegation/README.rst | 6 ------ More/Delegation/TeamLead.php | 19 +++++++------------ More/Delegation/Tests/DelegationTest.php | 4 +--- More/Delegation/Usage.php | 9 --------- 5 files changed, 9 insertions(+), 31 deletions(-) delete mode 100644 More/Delegation/Usage.php diff --git a/More/Delegation/JuniorDeveloper.php b/More/Delegation/JuniorDeveloper.php index 64e2ff6..dbaa30a 100644 --- a/More/Delegation/JuniorDeveloper.php +++ b/More/Delegation/JuniorDeveloper.php @@ -4,7 +4,7 @@ namespace DesignPatterns\More\Delegation; class JuniorDeveloper { - public function writeBadCode() + public function writeBadCode(): string { return 'Some junior developer generated code...'; } diff --git a/More/Delegation/README.rst b/More/Delegation/README.rst index 69306ad..d2e1b0a 100644 --- a/More/Delegation/README.rst +++ b/More/Delegation/README.rst @@ -23,12 +23,6 @@ Code You can also find these code on `GitHub`_ -Usage.php - -.. literalinclude:: Usage.php - :language: php - :linenos: - TeamLead.php .. literalinclude:: TeamLead.php diff --git a/More/Delegation/TeamLead.php b/More/Delegation/TeamLead.php index b617d54..67d9bdf 100644 --- a/More/Delegation/TeamLead.php +++ b/More/Delegation/TeamLead.php @@ -4,26 +4,21 @@ namespace DesignPatterns\More\Delegation; class TeamLead { - /** @var JuniorDeveloper */ - protected $slave; + /** + * @var JuniorDeveloper + */ + private $junior; /** - * Give junior developer into teamlead submission. - * * @param JuniorDeveloper $junior */ public function __construct(JuniorDeveloper $junior) { - $this->slave = $junior; + $this->junior = $junior; } - /** - * TeamLead drink coffee, junior work. - * - * @return mixed - */ - public function writeCode() + public function writeCode(): string { - return $this->slave->writeBadCode(); + return $this->junior->writeBadCode(); } } diff --git a/More/Delegation/Tests/DelegationTest.php b/More/Delegation/Tests/DelegationTest.php index 7d0a33b..8660ef7 100644 --- a/More/Delegation/Tests/DelegationTest.php +++ b/More/Delegation/Tests/DelegationTest.php @@ -4,15 +4,13 @@ namespace DesignPatterns\More\Delegation\Tests; use DesignPatterns\More\Delegation; -/** - * DelegationTest tests the delegation pattern. - */ class DelegationTest extends \PHPUnit_Framework_TestCase { public function testHowTeamLeadWriteCode() { $junior = new Delegation\JuniorDeveloper(); $teamLead = new Delegation\TeamLead($junior); + $this->assertEquals($junior->writeBadCode(), $teamLead->writeCode()); } } diff --git a/More/Delegation/Usage.php b/More/Delegation/Usage.php deleted file mode 100644 index a1d9837..0000000 --- a/More/Delegation/Usage.php +++ /dev/null @@ -1,9 +0,0 @@ -writeCode();