Trucchia / Romei | Pro PHP Refactoring | E-Book | www.sack.de
E-Book

E-Book, Englisch, 360 Seiten

Trucchia / Romei Pro PHP Refactoring


1. ed
ISBN: 978-1-4302-2728-1
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

E-Book, Englisch, 360 Seiten

ISBN: 978-1-4302-2728-1
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



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.

Francesco Trucchia worked some years as web engineer on small, medium and large projects for international companies. Now he is the co-founder and chief technology officer of Ideato Srl, an Italian company in the business of web software development and agile methods. He likes to develop with extreme programming (XP) methods (test-driven design, pair programming, KISS, etc.) and he has introduced these practices in Ideato with a lot of positive feedback about the software life cycle process. Francesco specializes in web engineering, web development, ITC consultant, ITC problem solving, symfony development, PHP development, project management, XP methods, and agile processes.

Trucchia / Romei Pro PHP Refactoring jetzt bestellen!

Weitere Infos & Material


1;Title Page
;1
2;Copyright Page
;2
3;Contents at a Glance;3
4;Table of Contents
;4
5;About the Authors;18
6;About the Technical Reviewer;19
7;Acknowledgments;20
8;Introduction;21
9;CHAPTER 1 Introduction
;22
9.1;Lesson Learned;23
9.1.1;Hidden Gems;23
9.1.2;You Don’t Know What You’ve Got ’til It’s Gone;23
9.2;Call of Duty;24
10;CHAPTER 2 Finding “Bad Smells” in Code
;25
10.1;Why Code Can Smell;25
10.1.1;Duplicated Code;26
10.1.2;Long Method;27
10.1.3;Large Class;30
10.1.4;Long Parameter List;32
10.1.5;Divergent Change;33
10.1.6;Shotgun Surgery;35
10.1.7;Feature Envy;35
10.1.8;Data Clamps;36
10.1.9;Primitive Obsession;37
10.1.10;Switch Statements;38
10.1.11;Lazy Class;39
10.1.12;Speculative Generality;40
10.1.13;Temporary Field;40
10.1.14;Data Class;41
10.1.15;Comments;42
10.1.16;Procedural Code;44
11;CHAPTER 3 Introduction to Refactoring
;45
11.1;The Concept: What Refactoring Is;45
11.2;The Reason: What’s the Goal of Refactoring?;45
11.2.1;Architecture and Structure, They Fade Away;46
11.2.2;Reworking Chaos into Well-Designed Code;46
11.3;An Example, at Last;47
11.3.1;Look Ma’! No Comments!;51
11.3.2;Once Is Better than Twice;53
11.3.3;Goliath Died in the End;55
12;CHAPTER 4 Principles and Rules
;67
12.1;Why Should You Do Refactoring?;67
12.1.1;Refactoring Improves the Design of Our Software;67
12.1.2;Refactoring Makes Software Easier to Understand;68
12.1.2.1;Keep It Simple and Stupid (KISS);68
12.1.2.2;Don’t Repeat Yourself;69
12.1.2.3;Test-Driven Development (TDD);69
12.1.3;Refactoring Helps You Find Bugs;69
12.1.4;Refactoring Increases Our Productivity;70
12.2;When Should We Do Refactoring?;71
12.2.1;The Rule of Three;71
12.2.2;Refactoring When You Add Functionality;72
12.2.3;Refactoring When You Need to Fix a Bug;72
12.3;When You Shouldn’t Do Refactoring;73
12.4;Some Simple Rules;73
12.4.1;Test Before Refactoring;73
12.4.2;Small and Simple Changes;74
12.4.3;Never Change Functionality;74
12.4.4;Follow the Bad Smells;74
12.4.5;Follow Refactoring Techniques Step-by-Step;75
12.5;Summary;75
13;CHAPTER 5 Test-First Development
;76
13.1;Building Value One-Way;76
13.2;Chaos in a Cage;77
13.2.1;Unit Tests;77
13.2.2;Functional Tests;77
13.3;You Don't Know What You’ve Got ’til It’s Gone;78
13.3.1;Trust Me: Communication;78
13.3.2;Listen to What You Say, and Write It Down;79
13.3.3;Pleasant Constraints;79
13.3.4;Create Trust;80
13.3.5;Test-Driven Development;80
13.4;Summary;81
14;CHAPTER 6 Refactoring Tools
;82
14.1;PHP IDE;82
14.1.1;Refactoring Activities;82
14.1.1.1;Rename;82
14.1.1.2;Move;83
14.1.1.3;Encapsulate Field;83
14.1.1.4;Override;83
14.1.1.5;Safely Remove;83
14.1.2;Cross-Platform Open-Source IDE;83
14.2;Unit Tests with PHPUnit;83
14.2.1;What Is It?;83
14.2.2;Installation;84
14.2.2.1;PEAR Installation;84
14.2.2.2;Manual Installation;84
14.2.3;How to Write Unit Tests;85
14.2.4;How to Run Tests;89
14.2.5;How to Organize Our Tests;90
14.2.6;Test Doubles;93
14.2.6.1;Stub Object;94
14.2.6.2;Mock Object;95
14.2.7;PHPUnit Conclusion;96
14.3;Functional Test with Selenium;96
14.3.1;What Is It?;96
14.3.1.1;Selenium IDE;97
14.3.1.2;Selenium RC;97
14.3.1.3;Selenium Grid;97
14.3.2;Installation;97
14.3.3;How to Record and Run Functional Tests;98
14.3.4;How to Organize Selenium Tests;100
14.3.5;Automated Test Execution with Selenium RC;101
14.3.6;Selenium Conclusion;101
14.4;The Best of Two Worlds;101
14.4.1;Selenium RC and PHPUnit;101
14.4.2;Selenium Functional Test with PHPUnit;101
14.5;Summary;103
15;CHAPTER 7 Structuring Behavior
;104
15.1;Extract Method;104
15.1.1;Motivation;104
15.1.2;Mechanics;105
15.1.3;Example: No Local Variables;105
15.1.4;Example: Using Local Variables;107
15.1.5;Example: Reassigning a Local Variable;107
15.2;Inline Method;111
15.2.1;Motivation;111
15.2.2;Mechanics;111
15.2.3;Example;112
15.3;Inline Temp;113
15.3.1;Motivation;113
15.3.2;Mechanics;113
15.3.3;Example;113
15.4;Replace Temp with Query;114
15.4.1;Motivation;114
15.4.2;Mechanics;114
15.4.3;Example;115
15.5;Introduce Explaining Variable;117
15.5.1;Motivation;117
15.5.2;Mechanics;117
15.5.3;Example;117
15.6;Split Temporary Variable;118
15.6.1;Motivation;118
15.6.2;Mechanics;119
15.6.3;Example;119
15.7;Replace Method with Method Object;121
15.7.1;Motivation;121
15.7.2;Mechanics;121
15.7.3;Example;121
15.8;Substitute Algorithm;123
15.8.1;Motivation;123
15.8.2;Mechanics;124
15.8.3;Example;124
15.9;Summary;125
16;CHAPTER 8 Changing Class Responsibilities
;126
16.1;Move Method;126
16.1.1;Motivation;126
16.1.2;Mechanics;127
16.1.3;Example;127
16.2;Move Property (or Field);131
16.2.1;Motivation;131
16.2.2;Mechanics;131
16.2.3;Example;132
16.3;Extract Class;134
16.3.1;Motivation;134
16.3.2;Mechanics;134
16.3.3;Example;135
16.4;Inline Class;140
16.4.1;Motivation;140
16.4.2;Mechanics;140
16.4.3;Example;140
16.5;Hide Delegate;143
16.5.1;Motivation;143
16.5.2;Mechanics;143
16.5.3;Example;143
16.6;Remove the Middle Man;146
16.6.1;Motivation;146
16.6.2;Mechanism;146
16.6.3;Example;147
16.7;Introduce Foreign Method;149
16.7.1;Motivation;149
16.7.2;Mechanism;150
16.7.3;Example;150
16.8;Summary;151
17;CHAPTER 9 Dealing with Data Rationalization
;152
17.1;Self-Encapsulate Field;152
17.1.1;Motivation;152
17.1.2;Mechanics;152
17.1.3;Example;153
17.2;Replace Data Value with Object;154
17.2.1;Motivation;154
17.2.2;Mechanics;154
17.2.3;Example;154
17.3;Change Value to Reference;156
17.3.1;Motivation;156
17.3.2;Mechanics;156
17.3.3;Example;157
17.4;Change Reference to Value;159
17.4.1;Motivation;159
17.4.2;Mechanics;159
17.5;Replace Array with Object;159
17.5.1;Motivation;160
17.5.2;Mechanics;160
17.5.3;Example;160
17.6;Change Unidirectional Association to Bidirectional;162
17.6.1;Motivation;162
17.6.2;Mechanics;162
17.6.3;Example;163
17.7;Change Bidirectional Association to Unidirectional;165
17.7.1;Motivation;165
17.7.2;Mechanics;165
17.7.3;Example;166
17.8;Replace Magic Number with Symbolic Constant;168
17.8.1;Motivation;168
17.8.2;Mechanics;168
17.8.3;Example;168
17.9;Encapsulate Field;169
17.9.1;Motivation;169
17.9.2;Mechanics;170
17.9.3;Example;170
17.10;Replacing Type Code with Subclasses;171
17.10.1;Motivation;171
17.10.2;Mechanics;171
17.10.3;Example;171
17.11;Replace Type Code with State/Strategy;175
17.11.1;Motivation;175
17.11.2;Mechanics;175
17.11.3;Example;175
17.12;Replace Subclass with Fields;180
17.12.1;Motivation;180
17.12.2;Mechanics;180
17.12.3;Example;181
17.13;Summary;185
18;CHAPTER 10 Reducing to Essential Conditional Executions
;186
18.1;Decompose Conditional;186
18.1.1;Motivation;186
18.1.2;Mechanics;187
18.1.3;Example;187
18.2;Consolidate Conditional Expression;189
18.2.1;Motivation;189
18.2.2;Mechanism;190
18.2.3;Example to Consolidate with ORs;190
18.2.4;Example to Consolidate with AND;191
18.3;Consolidate Duplicate Conditional Fragments;192
18.3.1;Motivation;192
18.3.2;Mechanism;192
18.3.3;Example;193
18.4;Remove Control Flag;194
18.4.1;Motivation;194
18.4.2;Mechanism;194
18.4.3;Example with Control Flag Replaced with Break;195
18.4.4;Example Replacing Control Flag with a Return Exit Point;196
18.5;Replace Nested Conditional with Guard Clauses;198
18.5.1;Motivation;198
18.5.2;Mechanism;198
18.5.3;Example;199
18.6;Replace Conditional with Polymorphism;201
18.6.1;Motivation;201
18.6.2;Mechanism;202
18.6.3;Example;202
18.7;Summary;205
19;CHAPTER 11 Simplifying Method Calls
;206
19.1;Rename Method;206
19.1.1;Motivation;206
19.1.2;Mechanics;206
19.1.3;Example;207
19.2;Add Parameter;208
19.2.1;Motivation;208
19.2.2;Mechanics;208
19.2.3;Example;209
19.2.4;Remove Parameter;210
19.2.5;Motivation;210
19.2.6;Mechanics;210
19.3;Separate Query from Modifier;211
19.3.1;Motivation;211
19.3.2;Mechanics;211
19.3.3;Example;211
19.4;Parameterize Method;213
19.4.1;Motivation;213
19.4.2;Mechanics;214
19.4.3;Example;214
19.5;Replace Parameter with Explicit Method;215
19.5.1;Motivation;215
19.5.2;Mechanics;216
19.5.3;Example;216
19.6;Preserve Whole Object;218
19.6.1;Motivation;218
19.6.2;Mechanics;218
19.6.3;Example;219
19.7;Replace Parameter with Method;220
19.7.1;Motivation;221
19.7.2;Mechanics;221
19.7.3;Example;221
19.8;Introduce Parameter Object;222
19.8.1;Motivation;222
19.8.2;Mechanics;223
19.9;Remove Setting Method;223
19.9.1;Motivation;223
19.9.2;Mechanics;223
19.9.3;Example;223
19.10;Hide Method;225
19.10.1;Motivation;225
19.10.2;Mechanics;225
19.11;Replace Constructor with Factory Method;225
19.11.1;Motivation;225
19.11.2;Mechanics;226
19.11.3;Example;226
19.12;Replace Error Code with Exception;227
19.12.1;Motivation;227
19.12.2;Mechanics;227
19.12.3;Example;227
19.13;Replace Exception with Test;229
19.13.1;Motivation;229
19.13.2;Mechanics;229
19.14;Summary;229
20;CHAPTER 12 Simplifying Generalization Relationships
;230
20.1;Pull Up Field;230
20.1.1;Motivation;230
20.1.2;Mechanism;231
20.1.3;Example;231
20.2;Pull Up Method;232
20.2.1;Motivation;232
20.2.2;Mechanism;233
20.2.3;Example;233
20.3;Pull Up Constructor Body;235
20.3.1;Motivation;235
20.3.2;Mechanism;236
20.3.3;Example;236
20.4;Push Down Method;239
20.4.1;Motivation;239
20.4.2;Mechanism;239
20.4.3;Example;239
20.5;Push Down Field;242
20.5.1;Motivation;242
20.5.2;Mechanism;242
20.5.3;Example;242
20.6;Extract Subclass;245
20.6.1;Motivation;245
20.6.2;Mechanism;245
20.6.3;Example;246
20.7;Extract Super Class;250
20.7.1;Motivation;250
20.7.2;Mechanism;250
20.7.3;Example;251
20.8;Collapse Hierarchy;254
20.8.1;Motivation;254
20.8.2;Mechanism;254
20.8.3;Example;255
20.9;Form Template Method;257
20.9.1;Motivation;257
20.9.2;Mechanism;257
20.9.3;Example;258
20.10;Replace Inheritance with Delegation;262
20.10.1;Motivation;262
20.10.2;Mechanism;263
20.10.3;Example;263
20.11;Replace Delegation with Inheritance;266
20.11.1;Motivation;266
20.11.2;Mechanism;266
20.11.3;Example;267
20.12;Summary;268
21;CHAPTER 13 Legacy Code
;269
21.1;Ugly Code;269
21.1.1;index.php;272
21.1.2;config.php;273
21.1.3;functions.php;273
21.1.4;header.php;274
21.1.5;footer.php;275
21.1.6;new.php;275
21.1.7;edit.php;276
21.1.8;_form.php;278
21.1.9;remove.php;278
21.2;Maintenance;279
21.2.1;Example: SQL injection;279
21.2.2;Example: Database Portability;280
21.3;New Features;280
21.3.1;Dynamic Layouts;280
21.3.2;Internationalization;281
21.4;Break the Cycle;281
21.5;Summary;282
22;CHAPTER 14 Regression Tests
;283
22.1;Ugly But Valuable;283
22.2;Keeping Value vs. Wasting Value;284
22.3;Putting the Chaos in a Cage;284
22.3.1;Motivation;284
22.3.2;Mechanics;285
22.3.3;Examples;285
22.3.3.1;Add a New Record;286
22.3.3.2;Edit a Record;288
22.3.3.3;Read a List of Records;289
22.3.3.4;Remove a Record;290
22.3.3.5;Validate a Record;291
22.3.3.6;Test Refactoring;292
22.3.3.7;Unify Test Cases in a Suite;293
22.4;Summary;294
23;CHAPTER 15 Refactoring with Patterns
;295
23.1;Design Patterns;295
23.1.1;What Are Design Patterns?;295
23.1.2;Why Do I Need to Use Design Patterns?;296
23.1.3;When Do I Need to Use Them?;296
23.1.4;Refactoring with Patterns;296
23.2;Transform Procedural Code into Object-Oriented Code;297
23.2.1;Motivation;297
23.2.2;Mechanism;298
23.2.3;Example;299
23.2.3.1;Working with Fixtures;299
23.2.3.2;Index Action;300
23.2.3.3;Add Action;304
23.2.3.4;Edit Action;309
23.2.3.5;Remove Action;314
23.3;Replace SQL with ORM;316
23.3.1;Motivation;316
23.3.2;Mechanism;317
23.3.3;Example;317
23.4;Separate Business Logic from View;326
23.4.1;Motivation;326
23.4.2;Mechanism;326
23.4.3;Example;327
23.4.3.1;Decorator Design Pattern;327
23.4.3.2;Template View Pattern;333
23.5;MVC Architecture;337
23.5.1;Motivation;337
23.5.2;Mechanism;337
23.5.3;Example;338
23.6;Summary;345
24;Index;346



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.