Home Page Icon
Home Page
Table of Contents for
Cover Page
Close
Cover Page
by Jacopo Romei, Francesco Trucchia
Pro PHP Refactoring
Cover Page
Title Page
Copyright
Contents at a Glance
Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
CHAPTER 1: Introduction
Lesson Learned
Hidden Gems
You Don't Know What You've Got 'til It's Gone
Call of Duty
CHAPTER 2: Finding “Bad Smells” in Code
Why Code Can Smell
Duplicated Code
Long Method
Large Class
Long Parameter List
Divergent Change
Shotgun Surgery
Feature Envy
Data Clamps
Primitive Obsession
Switch Statements
Lazy Class
Speculative Generality
Temporary Field
Data Class
Comments
Procedural Code
CHAPTER 3: Introduction to Refactoring
The Concept: What Refactoring Is
The Reason: What's the Goal of Refactoring?
Architecture and Structure, They Fade Away
Reworking Chaos into Well-Designed Code
An Example, at Last
Look Ma'! No Comments!
Once Is Better than Twice
Goliath Died in the End
CHAPTER 4: Principles and Rules
Why Should You Do Refactoring?
Refactoring Improves the Design of Our Software
Refactoring Makes Software Easier to Understand
Refactoring Helps You Find Bugs
Refactoring Increases Our Productivity
When Should We Do Refactoring?
The Rule of Three
Refactoring When You Add Functionality
Refactoring When You Need to Fix a Bug
When You Shouldn't Do Refactoring
Some Simple Rules
Test Before Refactoring
Small and Simple Changes
Never Change Functionality
Follow the Bad Smells
Follow Refactoring Techniques Step-by-Step
Summary
CHAPTER 5: Test-First Development
Building Value One-Way
Chaos in a Cage
Unit Tests
Functional Tests
You Don't Know What You've Got 'til It's Gone
Trust Me: Communication
Listen to What You Say, and Write It Down
Pleasant Constraints
Create Trust
Test-Driven Development
Summary
CHAPTER 6: Refactoring Tools
PHP IDE
Refactoring Activities
Cross-Platform Open-Source IDE
Unit Tests with PHPUnit
What Is It?
Installation
How to Write Unit Tests
How to Run Tests
How to Organize Our Tests
Test Doubles
PHPUnit Conclusion
Functional Test with Selenium
What Is It?
Installation
How to Record and Run Functional Tests
How to Organize Selenium Tests
Automated Test Execution with Selenium RC
Selenium Conclusion
The Best of Two Worlds
Selenium RC and PHPUnit
Selenium Functional Test with PHPUnit
Summary
CHAPTER 7: Structuring Behavior
Extract Method
Motivation
Mechanics
Example: No Local Variables
Example: Using Local Variables
Example: Reassigning a Local Variable
Inline Method
Motivation
Mechanics
Example
Inline Temp
Motivation
Mechanics
Example
Replace Temp with Query
Motivation
Mechanics
Example
Introduce Explaining Variable
Motivation
Mechanics
Example
Split Temporary Variable
Motivation
Mechanics
Example
Replace Method with Method Object
Motivation
Mechanics
Example
Substitute Algorithm
Motivation
Mechanics
Example
Summary
CHAPTER 8: Changing Class Responsibilities
Move Method
Motivation
Mechanics
Example
Move Property (or Field)
Motivation
Mechanics
Example
Extract Class
Motivation
Mechanics
Example
Inline Class
Motivation
Mechanics
Example
Hide Delegate
Motivation
Mechanics
Example
Remove the Middle Man
Motivation
Mechanism
Example
Introduce Foreign Method
Motivation
Mechanism
Example
Summary
CHAPTER 9: Dealing with Data Rationalization
Self-Encapsulate Field
Motivation
Mechanics
Example
Replace Data Value with Object
Motivation
Mechanics
Example
Change Value to Reference
Motivation
Mechanics
Example
Change Reference to Value
Motivation
Mechanics
Replace Array with Object
Motivation
Mechanics
Example
Change Unidirectional Association to Bidirectional
Motivation
Mechanics
Example
Change Bidirectional Association to Unidirectional
Motivation
Mechanics
Example
Replace Magic Number with Symbolic Constant
Motivation
Mechanics
Example
Encapsulate Field
Motivation
Mechanics
Example
Replacing Type Code with Subclasses
Motivation
Mechanics
Example
Replace Type Code with State/Strategy
Motivation
Mechanics
Example
Replace Subclass with Fields
Motivation
Mechanics
Example
Summary
CHAPTER 10: Reducing to Essential Conditional Executions
Decompose Conditional
Motivation
Mechanics
Example
Consolidate Conditional Expression
Motivation
Mechanism
Example to Consolidate with ORs
Example to Consolidate with AND
Consolidate Duplicate Conditional Fragments
Motivation
Mechanism
Example
Remove Control Flag
Motivation
Mechanism
Example with Control Flag Replaced with Break
Example Replacing Control Flag with a Return Exit Point
Replace Nested Conditional with Guard Clauses
Motivation
Mechanism
Example
Replace Conditional with Polymorphism
Motivation
Mechanism
Example
Summary
CHAPTER 11: Simplifying Method Calls
Rename Method
Motivation
Mechanics
Example
Add Parameter
Motivation
Mechanics
Example
Remove Parameter
Motivation
Mechanics
Separate Query from Modifier
Motivation
Mechanics
Example
Parameterize Method
Motivation
Mechanics
Example
Replace Parameter with Explicit Method
Motivation
Mechanics
Example
Preserve Whole Object
Motivation
Mechanics
Example
Replace Parameter with Method
Motivation
Mechanics
Example
Introduce Parameter Object
Motivation
Mechanics
Remove Setting Method
Motivation
Mechanics
Example
Hide Method
Motivation
Mechanics
Replace Constructor with Factory Method
Motivation
Mechanics
Example
Replace Error Code with Exception
Motivation
Mechanics
Example
Replace Exception with Test
Motivation
Mechanics
Summary
CHAPTER 12: Simplifying Generalization Relationships
Pull Up Field
Motivation
Mechanism
Example
Pull Up Method
Motivation
Mechanism
Example
Pull Up Constructor Body
Motivation
Mechanism
Example
Push Down Method
Motivation
Mechanism
Example
Push Down Field
Motivation
Mechanism
Example
Extract Subclass
Motivation
Mechanism
Example
Extract Super Class
Motivation
Mechanism
Example
Collapse Hierarchy
Motivation
Mechanism
Example
Form Template Method
Motivation
Mechanism
Example
Replace Inheritance with Delegation
Motivation
Mechanism
Example
Replace Delegation with Inheritance
Motivation
Mechanism
Example
Summary
CHAPTER 13: Legacy Code
Ugly Code
Maintenance
Example: SQL injection
Example: Database Portability
New Features
Dynamic Layouts
Internationalization
Break the Cycle
Summary
CHAPTER 14: Regression Tests
Ugly But Valuable
Keeping Value vs. Wasting Value
Putting the Chaos in a Cage
Motivation
Mechanics
Examples
Summary
CHAPTER 15: Refactoring with Patterns
Design Patterns
What Are Design Patterns?
Why Do I Need to Use Design Patterns?
When Do I Need to Use Them?
Refactoring with Patterns
Transform Procedural Code into Object-Oriented Code
Motivation
Mechanism
Example
Replace SQL with ORM
Motivation
Mechanism
Example
Separate Business Logic from View
Motivation
Mechanism
Example
MVC Architecture
Motivation
Mechanism
Example
Summary
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Title Page
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset