Developing a BC Break Scan Class
Explore how to develop a BreakScan class for detecting potential backward compatibility breaks during PHP 8 migrations. Understand class infrastructure setup, methods to scan functions and magic methods, and how to build a calling program to analyze multiple files and report scan results comprehensively.
The BreakScan class is oriented toward a single file. In this class, we define methods that utilize the various break scan configuration just covered. If we need to scan multiple files, the calling program produces a list of files and passes them to BreakScan one at a time.
The BreakScan class can be broken down into two main parts: methods that define infrastructure and methods that define how to conduct given scans. The latter is primarily dictated by the structure of the configuration file. For each configuration file section, we’ll need a BreakScan class method.
Let’s have a look at the infrastructural methods first.
Defining BreakScan class infrastructural methods
In this section, we’ll have a look at the initial part of the BreakScan class. We also cover methods that perform infrastructure-related activities:
Let’s get into the code.
Lines 2–5: First, we set up the class infrastructure, placing it in the current directory.
Lines 14–24: Next, we define a set of class constants to render messages indicating the nature of any given post-scan failure.
Lines 25–28: We also define a set of constants that represent configuration array keys. We do this to maintain consistency between key definitions in the configuration file and calling program.
Lines 30–33: We then initialize key properties representing the configuration, the contents of the file to be scanned, and any messages.
Lines 37–47: The
__construct()method accepts our break scan configuration file as an argument, and cycles through all of the keys to ensure they exist.Lines 56–66: We then define a method that reads the contents of the file to be scanned. ...