package de.espend.idea.laravel.config;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ConfigFileUtil
{
    private static final Pattern configFilePattern = Pattern.compile(".*/config/([\\w-/]+).php$");

    public static ConfigFileMatchResult matchConfigFile(Project project, VirtualFile virtualFile) {
        String path = virtualFile.getPath();
        String projectPath = project.getBaseDir().getPath();

        if(path.startsWith(projectPath)) {
            path = path.substring(projectPath.length());
        }

        Matcher m = configFilePattern.matcher(path);

        // config/app.php
        // config/testing/app.php
        if(m.matches()) {
            return new ConfigFileMatchResult(true, m.group(1).replace('/', '.'));
        } else {
            return new ConfigFileMatchResult(false, "");
        }
    }

    public static class ConfigFileMatchResult
    {
        private boolean matches;

        private String keyPrefix;

        ConfigFileMatchResult(boolean matches, @NotNull String keyPrefix) {
            this.matches = matches;
            this.keyPrefix = keyPrefix;
        }

        public boolean matches() {
            return matches;
        }

        @NotNull
        public String getKeyPrefix() {
            return keyPrefix;
        }
    }
}

@@ -78,16 +78,66 @@
 roject;%0A
+import com.intellij.openapi.util.text.StringUtil;%0A
 import c
@@ -515,53 +515,8 @@
 ) %7B%0A
-        String path = virtualFile.getPath();%0A
     
@@ -572,25 +572,24 @@
 Path();%0A
-%0A
         
 if(path.
@@ -584,109 +584,79 @@
     
-if(path.startsWith(projectPath)) %7B%0A            path = path.substring(projectPath.length());%0A        %7D
+String path = StringUtil.trimStart(virtualFile.getPath(), projectPath);
 %0A%0A  

Replace 'substring' with 'trimStart' from the OpenAPI utils