Clean Code in PHP: Expert tips and best practices to write beautiful, human-friendly, and maintainable PHP
- Length: 264 pages
- Edition: 1
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2022-10-31
- ISBN-10: 1804613878
- ISBN-13: 9781804613870
- Sales Rank: #0 (See Top 100 Books)
Practical lessons, examples, and practices from PHP experts on how to take your PHP skills to a professional level
Key Features
- Easily navigate to key clean code principles specific to PHP development with this hands-on guide
- Learn the how and why of writing clean code through practical examples
- Skip the superfluous knowledge and grasp everything that’s relevant to the real-world development environment
Book Description
PHP is a beginner-friendly language, but also one that is rife with complaints of bad code,;yet no clean code books are specific to PHP. Enter Clean Code in PHP. This book is a one-stop guide to learning the theory and best practices of clean code specific to real-world PHP app development environments.
This PHP book is cleanly split to help you navigate through coding practices and theories to understand and adopt the nuances of the clean code paradigm. In addition to covering best practices, tooling for code quality, and PHP design patterns, this book also presents tips and techniques for working on large-scale PHP apps with a team and writing effective documentation for your PHP projects.
By the end of this book, you’ll be able to write human-friendly PHP code, which will fuel your PHP career growth and set you apart from the competition.
What you will learn
- Build a solid foundation in clean coding to craft human-readable code
- Understand metrics to determine the quality of your code
- Get to grips with the basics of automated tests
- Implement continuous integration for your PHP applications
- Get an overview of software design patterns to help you write reusable code
- Gain an understanding of coding guidelines and practices for working in teams
Who this book is for
This book is for early-career PHP developers who wish to avoid writing messy code by learning how to write understandable and maintainable code that sets them apart from rest. The book assumes familiarity with PHP coding and principles, but no knowledge of advanced principles will be necessary.
Clean Code in PHP Contributors About the authors About the reviewers Preface Who this book is for What this book covers To get the most out of this book Download the example code files Download the color images Conventions used Get in touch Share Your Thoughts Part 1 – Introducing Clean Code Chapter 1: What Is Clean Code and Why Should You Care? What this book will cover Understanding what clean code is The importance of clean code in teams The importance of clean code in personal projects Summary Chapter 2: Who Gets to Decide What “Good Practices” Are? Who decides these things anyway? Best practices – where do they really come from? Design pattern principles Being context-aware Being consistent – get results quicker About source code analysis tools About testing and its multiple forms Summary Chapter 3: Code, Don’t Do Stunts Understanding code A bit of history The purpose of code Be understood, not clever A note on maintainability Using binary operators and octal, hexadecimal, and binary notations Assigning a variable and using gotos Excessively using comments Using ternary comparisons Using abbreviations Bringing micro-optimizations to your code Recoding the methods of the SPL Summary Chapter 4: It is about More Than Just Code PHP as an ecosystem Choosing the right libraries A word about semantic versioning What is semantic versioning? How to deal with semantic versioning Stability versus trends Summary Chapter 5: Optimizing Your Time and Separating Responsibilities Naming and organizational conventions Class files and interface files Executables Web assets and resources Naming classes, interfaces, and methods Naming folders Separating responsibilities Event dispatching Demystifying polymorphism – interfaces and abstract classes Interfaces Abstract classes Summary Chapter 6: PHP is Evolving – Deprecations and Revolutions Old versus new PHP Strict typing Error reporting Attributes The version 8 revolution Match syntax Named arguments Read-only classes and properties Migrating resources to proper classes Protecting your sensitive arguments from leaking Summary Part 2 – Maintaining Code Quality Chapter 7: Code Quality Tools Technical requirements Syntax checking and code styling The PHP built-in linter PHP CS Fixer: a code sniffer Static Code Analysis phpcpd – the copy and paste detector PHPMD: the PHP mess detector PHPStan – a static analyzer for PHP Psalm: A PHP static analysis linting machine IDE extensions PHP Inspections (EA Extended) Intelephense Summary Further reading Chapter 8: Code Quality Metrics Technical requirements Introducing code quality metrics Aspects of software quality Code quality metrics Gathering metrics in PHP phploc PHP Depend PhpMetrics The pros and cons of using metrics The pros The cons Summary Further reading Chapter 9: Organizing PHP Quality Tools Technical requirements Installing code quality tools using Composer Installing code quality tools using require-dev Global installation Composer scripts Installing code quality tools as phar files Keeping your phar files organized Managing phar files using Phive Adding Phive to your project Summary Chapter 10: Automated Testing Technical requirements Why you need automated tests Easier refactoring with tests Types of automated tests Unit tests Integration tests E2E tests The testing pyramid in practice About code coverage Understanding code coverage How to generate code coverage reports Using the @covers annotation What to test Summary Further reading Chapter 11: Continuous Integration Technical requirements Why you need CI The costs of a bug How to prevent bugs Introducing CI The build pipeline Stage 1: Build project Stage 2 – Code analysis Stage 3 – Tests Stage 4 – Deploy Integrating the pipeline into your workflow Building a pipeline with GitHub Actions GitHub Actions in a nutshell Stage 1 – Build project Stage 2 – Code analysis Stage 3 – Tests Stage 4 – Deploy Integrating the pipeline into your workflow Your local pipeline – Git hooks Setting up Git hooks Git hooks in practice Advanced usage Excursion – Adding CI to existing software Step by step An outlook on CD Summary Further reading Chapter 12: Working in a Team Technical requirements Coding standards Going with existing standards Coding guidelines Examples of coding guidelines Setting up guidelines Code reviews Why you should do code reviews What code reviews should cover Best practices for code reviews Ensuring code reviews are done Definition of done Code reviews conclusion Design patterns Understanding design patterns Common design patterns in PHP Anti-patterns Summary Further reading Chapter 13: Creating Effective Documentation Technical requirements Why documentation matters Why documentation is important Developer documentation Creating documentation Text documents Diagrams Documentation generators Inline documentation Annotations are no code Unreadable code Outdated comments Useless comments Wrong or useless DocBlocks TODO comments When commenting is useful Tests as documentation Summary Further reading Index Why subscribe? Other Books You May Enjoy Packt is searching for authors like you
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Clean Code in PHP: Expert tips and best practices to write beautiful, human-friendly, and maintainable PHP
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.