![]() When a method accesses the data of another object more than its own data, that is a sign of a Feature Envy. ![]() PhpStorm suggests some candidate blocks to extract to a new method. If a method’s overall score is poor, then it’s likely a good idea to split it into simpler, more manageable parts. This inspection calculates four different metrics for methods: cyclomatic complexity, nesting depth, number of variables used, and total number of lines. If the original class is too big, it might need a few more iterations of refactorings. PhpStorm suggests extracting methods to a new class in this case. These inspections detect bloated classes based on three metrics: TCC (Tight Class Cohesion), a measure of class cohesiveness WMC (Weighted Method Count), the sum of cyclomatic complexities for all methods in the class and ATFD (Access To Foreign Data), the number of fields from another class accessed in this class. Let’s see three of them in action and look at how to combine them with PhpStorm refactorings. Clicking the gutter icon will invoke the suggested refactoring. They are disabled by default, but even in this disabled state, you’ll see an additional gutter icon near the code detected by these inspections (instead of having it underlined in the editor). This group includes inspections that can help find good candidates for refactoring. We’ve added a new group of inspections in the PHP section of Settings/Preferences | Editor | Inspections. PhpStorm will now evaluate parts of conditions to identify any redundant ones. ![]() Redundant conditions in logical expressions PhpStorm will highlight such constants and suggest replacing the name of the entity with the one where the constant is defined. But doing so could make the code a bit confusing, as the constant is defined in some other place. To access this constant, you can use any subclass or subinterface as an entry point. Let’s say there is a hierarchy of classes and interfaces and there is a constant defined in the top base class. Use constant from a class where it is defined If you type a non-existent method call inside a class, you can quickly create it by pressing Alt+Enter and selecting Add method:įor consistency, we have added a similar quick-fix to create a new function. When you’re designing code quickly, it can be convenient to make method stub calls and create the implementation later, once you are able to see the big picture. Use Alt+Enter to move the common part outside of the switch. If the cases of a switch block contain some repeated code, PhpStorm will suggest pulling it up. Press Alt+Enter to perform the transformation. ![]() This inspection highlights expressions that can be replaced with the null safe operator from PHP 8. So here are some of the new inspections coming in the 2021.2 release. We also add quick-fixes to free you from boring routine tasks and help you focus on what’s important in your coding. Like other EAP builds, this build is free to use but it will expire 30 days after the build date.Įvery PhpStorm release comes with many new inspections to help prevent possible bugs at an early stage while you’re in the editor and the code has not yet been committed. The fourth build of the PhpStorm 2021.2 Early Access Program comes with a set of new inspections and quick-fixes for PHP, including a whole new group of Refactoring Opportunities inspections.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |