]> git.ipfire.org Git - thirdparty/git.git/commitdiff
userdiff: PHP: catch "abstract" and "final" functions
authorJavier Spagnoletti <phansys@gmail.com>
Wed, 7 Oct 2020 03:38:18 +0000 (03:38 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Oct 2020 15:45:43 +0000 (08:45 -0700)
PHP permits functions to be defined like

       final public function foo() { }
       abstract protected function bar() { }

but our hunk header pattern does not recognize these decorations.
Add "final" and "abstract" to the list of function modifiers.

Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4018/php-abstract-method [new file with mode: 0644]
t/t4018/php-final-method [new file with mode: 0644]
userdiff.c

diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method
new file mode 100644 (file)
index 0000000..ce215df
--- /dev/null
@@ -0,0 +1,7 @@
+abstract class Klass
+{
+    abstract public function RIGHT(): ?string
+    {
+        return 'ChangeMe';
+    }
+}
diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method
new file mode 100644 (file)
index 0000000..537fb8a
--- /dev/null
@@ -0,0 +1,7 @@
+class Klass
+{
+    final public function RIGHT(): string
+    {
+        return 'ChangeMe';
+    }
+}
index fde02f225b2b9ed17a8246913c3bddfa6483c98b..4e2b55a5e0aff10e85d7bb5c25a738f5b63ab16a 100644 (file)
@@ -147,7 +147,7 @@ PATTERNS("perl",
         "|=~|!~"
         "|<<|<>|<=>|>>"),
 PATTERNS("php",
-        "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
+        "^[\t ]*(((public|protected|private|static|abstract|final)[\t ]+)*function.*)$\n"
         "^[\t ]*((((final|abstract)[\t ]+)?class|interface|trait).*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"