Reader small image

You're reading from  Clean Code in PHP

Product typeBook
Published inOct 2022
PublisherPackt
ISBN-139781804613870
Edition1st Edition
Tools
Right arrow
Authors (2):
Carsten Windler
Carsten Windler
author image
Carsten Windler

Carsten Windler is a Lead PHP engineer at Plan A.
Read more about Carsten Windler

Alexandre Daubois
Alexandre Daubois
author image
Alexandre Daubois

Alexandre Daubois is a Symfony Developer at SensioLabs, the company that created Symfony.
Read more about Alexandre Daubois

View More author details
Right arrow

Preface

PHP has evolved over several decades from a simple scripting language for creating HTML pages to a feature-rich language with an extensive ecosystem. Because the vast majority of websites are still powered by PHP, it is one of the cornerstones of the internet.

While still beginner-friendly, it can be used to implement everything from small websites to enterprise applications used worldwide. However, the low entry barriers of PHP sometimes lead to code that is difficult to understand and impossible to maintain.

With this book, we want to introduce you to the world of Clean Code. You will learn a lot about the theory and also, how to apply the knowledge you learned in the real world. You will learn which tools will support you on this journey and which best practices you should use to be able to implement Clean Code successfully in your team.

Who this book is for

This book is aimed at early career PHP developers who want to understand the foundations of high-quality PHP code, and seasoned PHP developers who wish to update themselves on the latest best practices.

What this book covers

Chapter 1, What Is Clean Code and Why Should You Care?, introduces the main subject of the book.

Chapter 2, Who Gets to Decide What "Good Practices" Are?, explains how those “rules” are decided.

Chapter 3, Code, Don’t Do Stunts, shows why you should consider being pragmatic rather than trying to show off skills.

Chapter 4, It Is About More Than Just Code, explains why a clean code perimeter is greater than just writing source code.

Chapter 5, Optimizing Your Time and Separating Responsibilities, explains how to become more productive by creating new habits.

Chapter 6, PHP Is Evolving – Deprecations and Revolutions, provides a quick overview of the most awaited features introduced in PHP, helping to write clean code.

Chapter 7, Code Quality Tools, teaches you about tools that will help you write clean, maintainable code.

Chapter 8, Code Quality Metrics, looks at all the metrics you need to know to assess your code quality.

Chapter 9, Organizing PHP Quality Tools, shows you how to keep your tools organized.

Chapter 10, Automated Testing, introduces you to automated testing and explains why you should do it.

Chapter 11, Continuous Integration, explores how to maintain code quality consistently and over time.

Chapter 12, Working in a Team, introduces you to the best practices for working in a team of developers.

Chapter 13, Creating Effective Documentation, demonstrates how to create useful and living documentation.

To get the most out of this book

You will need PHP 8.0 or above installed on your computer. All code samples have been tested using PHP 8.1 on Linux and macOS. With little adjustments, they should work on Windows too, depending on your setup.

Software/hardware covered in the book

Operating system requirements

PHP 8.0 and above

Linux, macOS, or Windows

To follow all chapters, you will also need to install Composer. You will find more information about it in Chapter 9, Organizing PHP Quality Tools, or at https://getcomposer.org.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Clean-Code-in-PHP. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/b08Jl.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “So, we will naturally create a service like UserRemover, which will perform these two tasks in a row.”

A block of code is set as follows:

<?php
class Example 
{
    public function doSomething() bool
    {
        return true;
    }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

{
  ...
  "scripts": {
      "analyse": [
          "tools/vendor/bin/php-cs-fixer fix src",
          "tools/vendor/bin/phpstan analyse --level 1 src"
        ],
        "post-update-cmd": "composer update -d tools",
        "post-install-cmd": "composer update -d tools"
    }
}

Any command-line input or output is written as follows:

$ php phploc src

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Hovering the mouse pointer over TestClass will show a popup window with an explanation saying Undefined type TestClass.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Clean Code in PHP, we’d love to hear your thoughts! Please click here to go straight to the Amazon review pagefor this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Clean Code in PHP
Published in: Oct 2022Publisher: PacktISBN-13: 9781804613870
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime

Authors (2)

author image
Carsten Windler

Carsten Windler is a Lead PHP engineer at Plan A.
Read more about Carsten Windler

author image
Alexandre Daubois

Alexandre Daubois is a Symfony Developer at SensioLabs, the company that created Symfony.
Read more about Alexandre Daubois