add parameter technique, 189–190
algorithm, substituting, 104–105
AND logical operator, 172
architectural design patterns, 277–278
architecture, 26
arrays
associative, 17
replacing with objects, 140–143
associative arrays, 17
attribute groups, rewriting, 16
attributes
classes with too many, 10
context of, 20
Autoload Package, 74
AutoloaderTest class, 74
Back, Kent, 5
bar() method, 76
behavior design patterns, 278
bidirectional association
changing to unidirectional, 146–148
changing unidirectional to, 143–146
big refactoring, 24
breaks, replacing control flags with, 176–177
business logic, separating from view, 308–318
change bidirectional association to unidirectional technique, 146–148
change reference to value technique, 140
change unidirectional association to bidirectional technique, 143–145
change value to referencen technique, 137–140
class hierarchy, collapsing, 235–238
class responsibilities, changing, 107–132
extract class technique, 115–120
hide delegate technique, 124–127
inline class technique, 121–123
introduce foreign method technique, 130–132
move method technique, 107–112
move property technique, 112–115
remove the middle man technique, 127–130
classes
data, 21
extracting, 10–11, 13–16, 37, 115–120
extracting subclasses from, 226–231
extracting super class, 231–234
inline class, 15, 19–20, 121–123
modifying many, for single change, 15
removing unnecessary, 19
small, 115
two-way references between, 143–148
CLI environment, 288
code
readability of, 48
speculative, 20
type. See type code
code comments, 7, 22–24, 33–34, 98
code duplication, 6–7, 17, 34–36, 51, 194, 213
collapse hierarchy technique, 20, 235–238
collection, encapsulation of, 21
communication, automated tests and, 59–61
competition design patterns, 278
complexity, 26
complicatedness, 26
ComponentSuite class, 73
conditional expressions, 31
nested, replacing with guard clauses, 179–182
replacing with polymorphism, 182–186
conditional logical operators, 172
consolidate conditional expression technique, 170–175
consolidate duplicate conditional fragments, 173–174
constants, replacing magic numbers with, 149–150
constructors
replacing with factory methods, 206–207
Continuous Integration Systems, 82
control flags, removing, 175–179
creational design patterns, 278
cross-platform open-source IDEs, 64
customer requirements, 251
customer-developer relationship, 60
data classes, 21
@dataProvider, 69
change bidirectional association to unidirectional, 146–148
change reference objects to value objects, 140
change unidirectional association to bidirectional, 143–146
change value to reference, 137–140
replace arrays with objects, 140,–143
replace data value with object, 135–137
replace magic numbers with constants, 149–150
replace subclasses with fields, 161–165
replace type code with state/strategy, 156–161
replace type code with subclasses, 151–155
self-encapsulate field, 133–134
data types, 17
data value, replacing with object, 17, 135–137
database portability, 262
while refactoring, 289
decompose conditional technique, 167–170
decomposition conditional, 7
Decorator Design pattern, 278, 308–315
delegates
delegation
replace with inheritance, 243–249
depended-on components (DOCs), 74
design overhead, 15
architectural, 277
object-oriented, 277
reasons to use, 278
refactoring with, 278
when to use, 278
documentation, 60
don't repeat yourself (DRY), 49
duplicated code, 6, 7, 17, 34–36, 194, 213
EditTest, 294
encapsulate field technique, 21, 64, 150–151
encapsulation, 124
error code, replacing with exception, 208–210
exceptions
replacing error code with, 208–210
replacing with test, 210
testing, 70
ExceptionTest class, 74
exit point, replacing control flag with, 177–179
@expectedException, 70
explicit methods, replacing parameters with, 196–199
external methods, 15
extract class technique, 10–11, 13–16, 115–120
extract method technique, 6–10, 15–16, 85–92
extract subclass technique, 10–11, 226–231
extract super class technique, 231–234, 275
feature creep, 1
feedback, 60
fields
moving to super class, 211–213
replacing subclasses with, 161–165
files, safely removing, 64
fixtures, working with, 281
flow conditionals, 7
foreign methods, introducing, 130–132
Fowler, Martin, 5
automated, 82
organizing, 81
functions, 192
getter classes, 21
getter methods, 64, 133–137, 146–149, 151, 325
global variables, 12
graphical user interface (GUI), separating from business logic, 308–318
guard clauses, replacing nested conditionals with, 179–182
header() function, 290, 309–310, 314
hide delegate technique, 124–127
hide method technique, 206
hierarchy, collapsing, 19, 235–238
HP4 language, 1
index.php script, 282, 310, 326
index() method, 282, 284, 286, 296, 300, 303, 305, 314, 316, 321
collapse hierarchy, 19
replace delegation with, 247–249
replace with delegation, 243–247
inline class technique, 15, 19–20, 121–123
integrated development environments (IDEs), 63–64
automation of refactoring activities using, 63–64
cross-platform open-source, 64
integration tests, 40
internationalization, 263
introduce explaining variable technique, 98–99
introduce foreign method technique, 130–132
introduce NullObject technique, 18–20
introduce parameter object technique, 203–204
Iterator interface, 69
JUnit 3.8.1, 64
keep it simple stupid (KISS), 48
legacy application (example), 251–254
_form.php, 260
config.php, 255
database portability, 262
footer.php, 257
list() construct, 90
local variables, 86
logical operators, 172
loops, 7
magic numbers, replacing with constants, 149–150
method calls, simplifying, 187–210
hide method, 206
introduce parameter object, 203–204
preserve whole object, 199–201
replace constructor with factory method, 206–208
replace error code with exception, 208–210
replace exception with test, 210
remove setting method, 204–205
replace parameter with explicit method, 196–198
replace parameter with method, 201–203
separate query from modifier, 192–194
method objects, replacing methods with, 102–104
methodology design patterns, 278
methods
external, 15
extracting, 6–10, 15–16, 85–92
hiding, 206
length of, 85
moving to super class, 213–216
polymorphic, 191
replacing parameters with explicit, 12, 196–199, 201
replacing with method object, 102–104
short, 85
Model View Controller (MVC) architecture, 277–278, 319–327
modifiers, separating query from, 192–193
move, 64
move method technique, 6, 9, 15–16, 107–112
move property (field) technique, 15, 112–115
nested conditionals, replacing with guard clauses, 179–182
NetBeans, 64
NullObject, introducing, 18–20
object relational mapping (ORM), 298–307
object-oriented code, transforming procedural code into, 279–298
object-oriented patterns, 277
object-oriented programming, conditional logic and, 167
objects
passing whole, as parameter, 199–203
replacing arrays with, 140–143
opportunity cost, 2
OR logical operator, 172
override methods, 64
page controller pattern, 254
parameter objects, 12–13, 16, 22, 203–204
parameterize method technique, 194–196
parameters
passing whole object as, 199–203
replacing with explicit methods, 196–199
replacing with methods, 12, 201
patterns. See design patterns
PEAR distribution system, 65
PHP 5, migration from PHP 4 to, 279
PHP Development Tools (PDT), 64
PHPDocumentor, 32
PHPUnit, 58
integrated with Selenium, 82–84
test doubles, 75
PHPUnit_Extensions_SeleniumTestCase class, 82
PHPUnit_Framework_TestCase class, 66, 74–75
PHPUnit_Framework_TestSuite class, 72
polymorphic methods, 191
polymorphism, 18–19, 41–42, 167, 182–186
preserve whole object technique, 22, 199–201
private access modifer, 95
procedural applications, regression testing, 266–274
procedural code, 24
transforming into object-oriented code, 279–298
procedural programming, conditional logic and, 167
pull up constructor body technique, 216–219
pull up field technique, 211–213
pull up method technique, 213–216
push down field technique, 223–226
push down method technique, 220–222
quality assurance teams, 61
queries, separating from modifiers, 192–193
refactoring
concept of, 25
reasons for, 47
design improvement, 47
software understandability, 48–49
risks of, 60
steps in process of, 54
testing before, 53
when debugging, 52
when not to do, 53
Refactoring (Fowler), 5
refactoring techniques, 6–7, 55
big refactoring, 24
change bidirectional association to unidirectional, 146–146
replace conditional with polymorphism, 182–186
change reference to value, 140
change unidirectional association to bidirectional, 143–145
change value to reference, 137–140
collapse hierarchy, 19–20, 235–238
consolidate conditional expression, 170–175
for data classes, 21
decompose conditional, 7, 167–170
encapsulate collection, 21
encapsulate field, 21, 64, 150–151
extract class, 10–11, 13–16, 115–120
extract method, 6–10, 15–16, 85–92
extract subclass, 10–11, 20–21, 226–231
extract super class, 231–234, 275
hide method, 206
implementing MVC architecture, 319–327
Inline class, 15, 19–20, 121–123
introduce explaining variable, 98–99
introduce foreign method, 130–132
introduce parameter object, 16, 203–204
for long parameter lists, 12–13
move method, 6, 9, 15–16, 107–112
move property (field), 15, 112–115
preserve whole object, 16, 22, 199–201
for procedural code, 24
pull up constructor body, 216–219
remove setting method, 21, 204–205
remove the middle man, 127–130
for removing speculative code, 20
replace arrays with objects, 140–143
replace constructor with factory method, 206–207
replace data value with object, 135–137
replace delegation with inheritance, 247–249
replace error code with exception, 208–210
replace exception with test, 210
replace inheritance with delegation, 243–247
replace magic number with constant, 149–150
replace method with method object, 102–104
replace parameter with explicit method, 196–199
replace parameter with method, 201
replace subclass with fields, 161–166
replace temp with query, 95–98
replace type code with state/strategy, 156–160
replace type code with subclasses, 151–155
self-encapsulate field, 133–134
separate business logic from view, 308–318
separate query from modifier, 192–193
split temporary variable, 99–102
substitute algorithm, 6, 104–105
reference objects, 137
changing value objects to, 137–140
changing to value objects, 140
remove control flag technique, 175–179
remove parameter technique, 20, 191–192
remove setting method technique, 21, 204–205
remove the middle man technique, 127–130
rename, 63
rename method technique, 20, 187–189
render() method, 13, 312–314, 323–324
replace conditional with polymorphism technique, 182–185
replace constructor with factory method technique, 139, 206–207
replace data value with object technique, 135–137
replace delegation with inheritance technique, 247–248
replace error code with exception technique, 208–209
replace exception with test technique, 210
replace inheritance with delegation technique, 243–246
replace nested conditional with guard clause technique, 179–181
replace parameter with explicit method technique, 196–198
replace parameter with method technique, 201–202
replace SQL with ORM technqiues, 298–307
replace subclass with fields technique, 161–166
replace temp with query method technique, 95–98
REQUEST_METHOD, 288
return exit point, replacing control flag with, 177–179
return on investment (ROI), 2
Savant3 template engine library, 315
second law of thermodynamics, 26
Selenium
functional testing using, 77–82
integration with PHPUnit, 82–84
organizing tests, 81
recording and running functional tests, 79–81
Selenium Grid, 78
Selenium Remote Control (RC), 78, 82
self-encapsulate field technique, 133–134
separate business logic from view technique, 308–318
separate query from modifer technique, 192–193
$_SERVER variable, 288
setter classes, 21
single responsibility principle, 99
small classes, 115
Smarty template engine, 308
software
adding functionality to, 52
functionality of, 54
rewriting, 5
techniques for making changes to, 60
improvement of design, with refactoring, 47
after initial release, 60
automatic tests and process of, 58–60
software development teams, 61
speculative code, 20
split temporary variable technique, 99–102
SQL, replace with ORM, 298–307
SQL injection, 261
state object, replacing type code with, 156–161
structural design patterns, 278
structure, 26
structured data type, 17
subclasses
extracting, 10–11, 20–21, 226–231
replacing type code with, 151–155
replacing with fields, 161–165
substitute algorithm technique, 6, 104–105
super class constructors, 216–219
super classes
system under test (SUT), 74
tearDown() method, 69
template engine, 308
template pattern, 238
Template View design pattern, 278, 308, 315–318
temporary fields, 20
introducing, as explaining variable, 98–99
@test annotation, 66
test-driven development (TDD), 49, 61–62
tets/testing
before refactoring, 53
functional tests, 58–61, 77–84
integration tests, 40
replacing exceptions with, 210
unit tests, 39, 58–59, 64–77, 267, 282
trust, 61
type code
replacing with class, 17
replacing with state/strategy pattern, 17, 156–161
replacing with subclasses, 17, 151–155
unidirectional association
changing bidirectional to, 146–148
changing to bidirectional, 143–146
unit tests, 39, 58–59, 267, 282
value objects, 137
changing reference values to, 140
changing to reference values, 137–140
variables
global, 12
3.137.181.66