From the course: Refactoring with GitHub Copilot
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Simplifying functionality - Github Copilot Tutorial
From the course: Refactoring with GitHub Copilot
Simplifying functionality
As a codebase grows, it becomes more complex. Much of your refactoring will be to simplify the functionality. What this simplification looks like can vary greatly based on business logic. Here are two example PHP classes, obviously incomplete: author and blog post. Note the comment on line 82 that indicates this method is too interested in the author class properties. In PHP 8 and below, I could change the property to be private. In 8.1, I could make them read-only. Both of those are helpful language constructs, but they don't solve the root issue. Even if I were to wrap these properties in a method to return the value, I wouldn't have solved the issue of the blog class method doing too much with the author information. I'm going to show two ways to simplify this. First, I can move the logic to a new method in the author class. We'll call it formatted author. And it figured out that that's what I wanted to do. And then I can call that on line 87. Thanks, Copilot. That solves what was…