Skip to content

Commit 7715206

Browse files
author
Dominik Liebler
committed
Merge pull request DesignPatternsPHP#180 from brettsantore/sniff
Cleaning up CodeSniffer errors and warnings
2 parents 58f0fc6 + 139c2c1 commit 7715206

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

Behavioral/Memento/Caretaker.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ public function runCustomLogic()
4646

4747
return $originator->getStateAsMemento()->getState();
4848
}
49-
5049
}

Behavioral/Memento/Tests/MementoTest.php

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,45 @@ public function testUsageExample()
1818
$caretaker = new Caretaker();
1919

2020
$character = new \stdClass();
21-
$character->name = "Gandalf"; // new object
22-
$originator->setState($character); // connect Originator to character object
23-
24-
$character->name = "Gandalf the Grey"; // work on the object
25-
$character->race = "Maia"; // still change something
26-
$snapshot = $originator->getStateAsMemento(); // time to save state
27-
$caretaker->saveToHistory($snapshot); // put state to log
21+
// new object
22+
$character->name = "Gandalf";
23+
// connect Originator to character object
24+
$originator->setState($character);
25+
26+
// work on the object
27+
$character->name = "Gandalf the Grey";
28+
// still change something
29+
$character->race = "Maia";
30+
// time to save state
31+
$snapshot = $originator->getStateAsMemento();
32+
// put state to log
33+
$caretaker->saveToHistory($snapshot);
2834

29-
$character->name = "Sauron"; // change something
30-
$character->race = "Ainur"; // and again
31-
$this->assertAttributeEquals($character, "state", $originator); // state inside the Originator was equally changed
35+
// change something
36+
$character->name = "Sauron";
37+
// and again
38+
$character->race = "Ainur";
39+
// state inside the Originator was equally changed
40+
$this->assertAttributeEquals($character, "state", $originator);
3241

33-
$snapshot = $originator->getStateAsMemento(); // time to save another state
34-
$caretaker->saveToHistory($snapshot); // put state to log
42+
// time to save another state
43+
$snapshot = $originator->getStateAsMemento();
44+
// put state to log
45+
$caretaker->saveToHistory($snapshot);
3546

3647
$rollback = $caretaker->getFromHistory(0);
37-
$originator->restoreFromMemento($rollback); // return to first state
38-
$character = $rollback->getState(); // use character from old state
39-
40-
$this->assertEquals("Gandalf the Grey", $character->name); // yes, that what we need
41-
$character->name = "Gandalf the White"; // make new changes
42-
43-
$this->assertAttributeEquals($character, "state", $originator); // and Originator linked to actual object again
48+
// return to first state
49+
$originator->restoreFromMemento($rollback);
50+
// use character from old state
51+
$character = $rollback->getState();
52+
53+
// yes, that what we need
54+
$this->assertEquals("Gandalf the Grey", $character->name);
55+
// make new changes
56+
$character->name = "Gandalf the White";
57+
58+
// and Originator linked to actual object again
59+
$this->assertAttributeEquals($character, "state", $originator);
4460
}
4561

4662
public function testStringState()
@@ -88,14 +104,18 @@ public function testCanChangeActualState()
88104
$snapshot = $originator->getStateAsMemento();
89105
$second_state = $snapshot->getState();
90106

91-
$first_state->first_property = 1; // still actual
92-
$second_state->second_property = 2; // just history
107+
// still actual
108+
$first_state->first_property = 1;
109+
// just history
110+
$second_state->second_property = 2;
93111
$this->assertAttributeEquals($first_state, "state", $originator);
94112
$this->assertAttributeNotEquals($second_state, "state", $originator);
95113

96114
$originator->restoreFromMemento($snapshot);
97-
$first_state->first_property = 11; // now it lost state
98-
$second_state->second_property = 22; // must be actual
115+
// now it lost state
116+
$first_state->first_property = 11;
117+
// must be actual
118+
$second_state->second_property = 22;
99119
$this->assertAttributeEquals($second_state, "state", $originator);
100120
$this->assertAttributeNotEquals($first_state, "state", $originator);
101121
}

0 commit comments

Comments
 (0)