git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: "Javier Spagnoletti via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Sixt <j6t@kdbg.org>,
	Javier Spagnoletti <phansys@gmail.com>,
	Javier Spagnoletti <phansys@gmail.com>
Subject: [PATCH v3] userdiff: php: Add "final" and "abstract" to the list of function modifiers
Date: Wed, 07 Oct 2020 18:07:49 +0000	[thread overview]
Message-ID: <pull.864.v3.git.git.1602094069865.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.864.v2.git.git.1602041898670.gitgitgadget@gmail.com>

From: Javier Spagnoletti <phansys@gmail.com>

PHP allows some function modifiers that are not recognized in our current hunk header pattern

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

Some context about the PHP semantics:

In PHP a class can be declared as abstract and final, while methods can be declared as final,
static and abstract, along with its visibility (public, protected and private).
Regarding classes, an abstract class can not be declared as final.
For the methods, from a strict syntax perspective, the order of the modifiers is irrelevant.

For more information, see:

* https://www.php.net/manual/en/language.oop5.abstract.php#example-213;
* https://www.php.net/manual/en/language.oop5.final.php#language.oop5.traits.static.ex1.

This commit adds "final" and "abstract" to the list of function modifiers.

Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
---
    userdiff: php: Add "final" and "abstract" to the list of function
    modifiers
    
    PHP allows some function modifiers that are not recognized in our
    current hunk header pattern
    
       final public function foo() { }
       abstract protected function bar() { }
    
    Some context about the PHP semantics:
    
    In PHP a class can be declared as abstract and final, while methods can
    be declared as final, static and abstract, along with its visibility
    (public, protected and private). Regarding classes, an abstract class
    can not be declared as final. For the methods, from a strict syntax
    perspective, the order of the modifiers is irrelevant.
    
    For more information, see:
    
     * https://www.php.net/manual/en/language.oop5.abstract.php#example-213;
     * https://www.php.net/manual/en/language.oop5.final.php#language.oop5.traits.static.ex1
       .
    
    This commit adds "final" and "abstract" to the list of function
    modifiers.
    
    Signed-off-by: Javier Spagnoletti phansys@gmail.com [phansys@gmail.com]

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-864%2Fphansys%2Fuserdiff_php-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-864/phansys/userdiff_php-v3
Pull-Request: https://github.com/git/git/pull/864

Range-diff vs v2:

 1:  4cb59950ff ! 1:  43acd70aba Improve diff pattern for PHP files
     @@ Metadata
      Author: Javier Spagnoletti <phansys@gmail.com>
      
       ## Commit message ##
     -    Improve diff pattern for PHP files
     +    userdiff: php: Add "final" and "abstract" to the list of function modifiers
      
          PHP allows some function modifiers that are not recognized in our current hunk header pattern
      
                 final public function foo() { }
                 abstract protected function bar() { }
      
     -    Add "final" and "abstract" to the list of function modifiers.
     +    Some context about the PHP semantics:
     +
     +    In PHP a class can be declared as abstract and final, while methods can be declared as final,
     +    static and abstract, along with its visibility (public, protected and private).
     +    Regarding classes, an abstract class can not be declared as final.
     +    For the methods, from a strict syntax perspective, the order of the modifiers is irrelevant.
     +
     +    For more information, see:
     +
     +    * https://www.php.net/manual/en/language.oop5.abstract.php#example-213;
     +    * https://www.php.net/manual/en/language.oop5.final.php#language.oop5.traits.static.ex1.
     +
     +    This commit adds "final" and "abstract" to the list of function modifiers.
      
          Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
      


 t/t4018/php-abstract-method | 7 +++++++
 t/t4018/php-final-method    | 7 +++++++
 userdiff.c                  | 2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 t/t4018/php-abstract-method
 create mode 100644 t/t4018/php-final-method

diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method
new file mode 100644
index 0000000000..ce215df75a
--- /dev/null
+++ b/t/t4018/php-abstract-method
@@ -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
index 0000000000..537fb8ad9a
--- /dev/null
+++ b/t/t4018/php-final-method
@@ -0,0 +1,7 @@
+class Klass
+{
+    final public function RIGHT(): string
+    {
+        return 'ChangeMe';
+    }
+}
diff --git a/userdiff.c b/userdiff.c
index 1df884ef0b..a99d84a7e3 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -143,7 +143,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_]*"

base-commit: 47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc
-- 
gitgitgadget

      parent reply	other threads:[~2020-10-07 18:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06 10:37 [PATCH] Improve diff pattern for PHP files Javier Spagnoletti via GitGitGadget
2020-10-06 18:27 ` Johannes Sixt
2020-10-06 18:55   ` Junio C Hamano
2020-10-07  3:38 ` [PATCH v2] " Javier Spagnoletti via GitGitGadget
2020-10-07  6:12   ` Junio C Hamano
2020-10-07 18:47     ` Junio C Hamano
2020-10-07 18:07   ` Javier Spagnoletti via GitGitGadget [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.864.v3.git.git.1602094069865.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=phansys@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).