𝔖 Scriptorium
✦   LIBER   ✦

πŸ“

Pro PHP Refactoring

✍ Scribed by Francesco Trucchia, Jacopo Romei


Publisher
Apress
Year
2010
Tongue
English
Leaves
359
Edition
1
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


Many businesses and organizations depend on older high-value PHP software that risks abandonment because it is impossible to maintain. The reasons for this may be that the software is not well designed; there is only one developer (the one who created the system) who can develop it because he didn’t use common design patterns and documentation; or the code is procedural, not object oriented. With this book, you’ll learn to identify problem code and refactor it to create more effective applications using test-driven design.


What you’ll learn


  • What refactoring is and why you need to refactor code
  • What test-driven design is and why you need to test your code
  • How to write unit and functional tests with PHPUnit and Selenium Remote Control (RC)
  • How to detect β€œbad smells” in PHP code, and refactor them using test-driven design
  • How to refactor a large procedural application affected by many bad smells

Who is this book for?


This book is for PHP developers, businesses, and developers relying on legacy PHP apps.

✦ Table of Contents


Prelim......Page 1
Contents at a Glance......Page 5
Contents......Page 6
About the Authors......Page 20
About the Technical Reviewer......Page 21
Acknowledgments......Page 22
Introduction......Page 23
Introduction......Page 25
You Don’t Know What You’ve Got ’til It’s Gone......Page 26
Call of Duty......Page 27
Why Code Can Smell......Page 29
Duplicated Code......Page 30
Long Method......Page 31
Large Class......Page 34
Long Parameter List......Page 36
Divergent Change......Page 37
Feature Envy......Page 39
Data Clamps......Page 40
Primitive Obsession......Page 41
Switch Statements......Page 42
Lazy Class......Page 43
Temporary Field......Page 44
Data Class......Page 45
Comments......Page 46
Procedural Code......Page 48
The Reason: What’s the Goal of Refactoring?......Page 49
Reworking Chaos into Well-Designed Code......Page 50
An Example, at Last......Page 51
Look Ma’! No Comments!......Page 55
Once Is Better than Twice......Page 57
Goliath Died in the End......Page 59
Refactoring Improves the Design of Our Software......Page 71
Keep It Simple and Stupid (KISS)......Page 72
Refactoring Helps You Find Bugs......Page 73
Refactoring Increases Our Productivity......Page 74
The Rule of Three......Page 75
Refactoring When You Need to Fix a Bug......Page 76
Test Before Refactoring......Page 77
Follow the Bad Smells......Page 78
Summary......Page 79
Building Value One-Way......Page 81
Functional Tests......Page 82
Trust Me: Communication......Page 83
Pleasant Constraints......Page 84
Test-Driven Development......Page 85
Summary......Page 86
Rename......Page 87
What Is It?......Page 88
Manual Installation......Page 89
How to Write Unit Tests......Page 90
How to Run Tests......Page 94
How to Organize Our Tests......Page 95
Test Doubles......Page 98
Stub Object......Page 99
Mock Object......Page 100
What Is It?......Page 101
Installation......Page 102
How to Record and Run Functional Tests......Page 103
How to Organize Selenium Tests......Page 105
Selenium Functional Test with PHPUnit......Page 106
Summary......Page 108
Motivation......Page 109
Example: No Local Variables......Page 110
Example: Reassigning a Local Variable......Page 112
Mechanics......Page 116
Example......Page 117
Example......Page 118
Mechanics......Page 119
Example......Page 120
Example......Page 122
Motivation......Page 123
Example......Page 124
Example......Page 126
Motivation......Page 128
Example......Page 129
Summary......Page 130
Motivation......Page 131
Example......Page 132
Mechanics......Page 136
Example......Page 137
Mechanics......Page 139
Example......Page 140
Example......Page 145
Example......Page 148
Mechanism......Page 151
Example......Page 152
Motivation......Page 154
Example......Page 155
Summary......Page 156
Mechanics......Page 157
Example......Page 158
Example......Page 159
Mechanics......Page 161
Example......Page 162
Replace Array with Object......Page 164
Example......Page 165
Mechanics......Page 167
Example......Page 168
Mechanics......Page 170
Example......Page 171
Example......Page 173
Motivation......Page 174
Example......Page 175
Example......Page 176
Example......Page 180
Mechanics......Page 185
Example......Page 186
Summary......Page 190
Motivation......Page 191
Example......Page 192
Motivation......Page 194
Example to Consolidate with ORs......Page 195
Example to Consolidate with AND......Page 196
Mechanism......Page 197
Example......Page 198
Mechanism......Page 199
Example with Control Flag Replaced with Break......Page 200
Example Replacing Control Flag with a Return Exit Point......Page 201
Mechanism......Page 203
Example......Page 204
Motivation......Page 206
Example......Page 207
Summary......Page 210
Mechanics......Page 211
Example......Page 212
Mechanics......Page 213
Example......Page 214
Mechanics......Page 215
Example......Page 216
Motivation......Page 218
Example......Page 219
Motivation......Page 220
Example......Page 221
Mechanics......Page 223
Example......Page 224
Replace Parameter with Method......Page 225
Example......Page 226
Motivation......Page 227
Example......Page 228
Motivation......Page 230
Example......Page 231
Example......Page 232
Summary......Page 234
Motivation......Page 235
Example......Page 236
Motivation......Page 237
Example......Page 238
Motivation......Page 240
Example......Page 241
Example......Page 244
Example......Page 247
Mechanism......Page 250
Example......Page 251
Mechanism......Page 255
Example......Page 256
Mechanism......Page 259
Example......Page 260
Mechanism......Page 262
Example......Page 263
Motivation......Page 267
Example......Page 268
Mechanism......Page 271
Example......Page 272
Summary......Page 273
Ugly Code......Page 275
index.php......Page 278
functions.php......Page 279
header.php......Page 280
new.php......Page 281
edit.php......Page 282
remove.php......Page 284
Example: SQL injection......Page 285
Dynamic Layouts......Page 286
Break the Cycle......Page 287
Summary......Page 288
Ugly But Valuable......Page 289
Motivation......Page 290
Examples......Page 291
Add a New Record......Page 292
Edit a Record......Page 294
Read a List of Records......Page 295
Remove a Record......Page 296
Validate a Record......Page 297
Test Refactoring......Page 298
Unify Test Cases in a Suite......Page 299
Summary......Page 300
What Are Design Patterns?......Page 301
Refactoring with Patterns......Page 302
Motivation......Page 303
Mechanism......Page 304
Working with Fixtures......Page 305
Index Action......Page 306
Add Action......Page 310
Edit Action......Page 315
Remove Action......Page 320
Motivation......Page 322
Example......Page 323
Mechanism......Page 332
Decorator Design Pattern......Page 333
Template View Pattern......Page 339
Mechanism......Page 343
Example......Page 344
Summary......Page 351
Β¦ C......Page 353
Β¦ E......Page 354
Β¦ H......Page 355
Β¦ P......Page 356
Β¦ R......Page 357
Β¦ S......Page 358
Β¦ W......Page 359


πŸ“œ SIMILAR VOLUMES


Pro PHP Refactoring
✍ Francesco Trucchia, Jacopo Romei (auth.), Michelle Lowman, Clay Andres, Steve An πŸ“‚ Library πŸ“… 2010 πŸ› Apress 🌐 English

<p>Many businesses and organizations depend on older high-value PHP software that risks abandonment because it is impossible to maintain. The reasons for this may be that the software is not well designed; there is only one developer (the one who created the system) who can develop it because he did

Pro PHP Refactoring
✍ Francesco Trucchia, Jacopo Romei (auth.), Michelle Lowman, Clay Andres, Steve An πŸ“‚ Library πŸ“… 2010 πŸ› Apress 🌐 English
Pro PHP Refactoring
✍ Francesco Trucchia, Jacopo Romei πŸ“‚ Library πŸ“… 2010 πŸ› Apress 🌐 English
Pro PHP Security (Pro)
✍ Chris Snyder πŸ“‚ Library πŸ“… 2005 🌐 English

PHP is the world’s most popular open source web scripting language, installed on almost 17 million domains worldwide (www.php.net/usage.php). It is loved by beginners and embraced by advanced users. This book offers developers a complete guide to taking both defensive and proactive security approach

Pro PHP-GTK
✍ Scott Mattocks πŸ“‚ Library πŸ“… 2006 🌐 English

PHP is arguably the world's most popular language for building dynamic web sites. Yet the language is also becoming known for its system administration and client-side application development capabilities. The latter feature continues to mature rapidly, and is accomplished using the PHP-GTK extensio