0

In JetBrains IDEs there's an option called refactoring witch allow you to easily refactor your code. One of the things it can do is extract some part of your code inside a new file.

For example, when I'm using Angular and I want to make a new component I can select the part of my code that needs to be in the component and tell WebStorm to extract it in a new component which WebStorm will do, it will also add the required code for it to work.

<div class="toto">
    <span class="tata">
        tutu
    </span>
</div>

->

<div class="toto">
    <app-titi></app-titi>
</div>

+

<span class="tata">
    tutu
</span>
import {Component} from '@angular/core';

@Component({
    selector: 'app-titi',
    standalone: true,
    imports: [],
    templateUrl: './titi.component.html',
    styleUrl: './titi.component.css'
})
export class TitiComponent {

}

The thing is when I'm coding in PHP there's no option to easily extract the code I've selected in a new file so I always have to cut it, create the file, paste my code and then call the new file from the position I cut it which doesn't take to much time but is annoying.

<body>
    <form action="index.php" method="get">
        <label>
            <strong>Toto </strong>
            <input name="toto" type="text">
        </label>
    </form>
</body>

->

<body>
    <?php require "toto.php"; ?>
</body>

+

<form action="index.php" method="get">
    <label>
        <strong>Toto </strong>
        <input name="toto" type="text">
    </label>
</form>

I would like to create my own extract template using JetBrains debugging feature but I don't know how to or where to do it.

I've tried looking on Google, StackOverflow, search in my IDE and looked on the JetBrains' docs but I didn't found anything.

2
  • 1) "I would like to create my own extract template using JetBrains debugging feature" It needs to be coded as a plugin AFAIK
    – LazyOne
    Commented Jan 30 at 12:46
  • 2) "The thing is when I'm coding in PHP there's no option to easily extract the code I've selected in a new file" Which code? Provide specific examples, please. Because it CAN refactor the PHP code (introduce constant, field, own method etc)
    – LazyOne
    Commented Jan 30 at 12:47

0