junichi11 opened a new pull request #2704:
URL: https://github.com/apache/netbeans/pull/2704


   https://issues.apache.org/jira/browse/NETBEANS-4443
   
   https://wiki.php.net/rfc/named_params
   
   #### Part 1
   
   - Fix the parser
   - Add the `NamedArgument`
   - Fix the `PHP80UnhandledError`
   - Add unit tests for the parser
   - Add `IncorrectNamedArgumentsHintError` to handle incorrect usage
   
   ##### PHP 8.0
   
   
![nb-php80-named-arguments-syntax](https://user-images.githubusercontent.com/738383/105450040-f80ada80-5cbc-11eb-8aa9-256bd77f58a9.png)
   
   ##### PHP 7.4
   
   
![nb-php80-named-arguments-syntax-php74](https://user-images.githubusercontent.com/738383/105450063-0bb64100-5cbd-11eb-8b22-1861a92100bc.png)
   
   ##### Incorrect Named Arguments
   Duplicate names:
   
   
![nb-php80-incorrect-named-arguments-duplicate-names](https://user-images.githubusercontent.com/738383/105450177-4a4bfb80-5cbd-11eb-9ccb-bc367dda7eaf.png)
   
   
![nb-php80-incorrect-named-arguments-duplicate-names-in-attribute-arg-list](https://user-images.githubusercontent.com/738383/105450150-3a341c00-5cbd-11eb-84bb-a2b61bb56421.png)
   
   Positional arguments after named arguments
   
   
![nb-php80-incorrect-named-arguments-positional-after-named](https://user-images.githubusercontent.com/738383/105450299-7ebfb780-5cbd-11eb-8a8e-03c109ad9a3e.png)
   
   
![nb-php80-incorrect-named-arguments-positional-after-named-in-attribute-arg-list](https://user-images.githubusercontent.com/738383/105450309-81baa800-5cbd-11eb-9834-53b39e90c6d6.png)
   
   Combine named arguments and argument unpacking
   
   
![nb-php80-incorrect-named-arguments-named-and-unpack](https://user-images.githubusercontent.com/738383/105450243-6bace780-5cbd-11eb-901d-2c18e85fca05.png)
   
   #### Part 2
   
   - Fix the formatting feature (Don't add spaces before ":")
   - Add unit tests for the formatting feature
   
   Example code:
   ```php
   array_fill(   start_index  : 0, count   : 100, value:50);
   array_fill(
       value:50,    
      count   : 100, 
      start_index     :0
     );
   
   class ParentClass {
   
       public function __construct(
               public int $foo,
               public string $bar = "",
       ) {
       }
   
   }
   
   class ExampleClass extends ParentClass {
   
   public function __construct(
           public string $test1,
           public ?int $test2 = null,
   ) {
       parent::__construct(foo: $test1);
   }
   
   public function test(int $test1, string|int $test2 = "") {}
   
   public static function staticTest(ExampleClass $exampleClass, int $test) {}
   }
   
   $instance = new ExampleClass($test1, test2: $test2);
   $instance->test(test1:$test2);
   ExampleClass::staticTest(  exampleClass  : $instance, test  : $test2);
   ExampleClass::staticTest(
           exampleClass  : $instance,
           test  : $test2,
   );
   $array_fill = "array_fill";
   $array_fill(   start_index   : 0, count : 100, value            : 50);
   $array_fill(
           start_index   : 0,
           count : 100,
           value            : 50
       );
   
   test(test(1, 2, 3), test3:test(1, 2, 3), test2   : test(1, test2   : 2, 
test3   : [1, 2, 3]));
   test(
           test(1, 2, 3),
           test3:test(1, 2, 3),
           test2   : test(1, test2   : 2, test3   : [1, 2, 3])
           );
   
   reservedKeyWord(   array         : []);
   reservedKeyWord(
           array         : []
     );
   
   test(  1,   2,   test3    :    $test1   === 0 ? 0:1);
   test(
   1,
   2,
   test3    :    $test1   === 0 ? 0:1
   );
   
   ```
   
   Formatted:
   
   ```php
   array_fill(start_index: 0, count: 100, value: 50);
   array_fill(
           value: 50,
           count: 100,
           start_index: 0
   );
   
   class ParentClass {
   
       public function __construct(
               public int $foo,
               public string $bar = "",
       ) {
           
       }
   
   }
   
   class ExampleClass extends ParentClass {
   
       public function __construct(
               public string $test1,
               public ?int $test2 = null,
       ) {
           parent::__construct(foo: $test1);
       }
   
       public function test(int $test1, string|int $test2 = "") {
           
       }
   
       public static function staticTest(ExampleClass $exampleClass, int $test) 
{
           
       }
   
   }
   
   $instance = new ExampleClass($test1, test2: $test2);
   $instance->test(test1: $test2);
   ExampleClass::staticTest(exampleClass: $instance, test: $test2);
   ExampleClass::staticTest(
           exampleClass: $instance,
           test: $test2,
   );
   $array_fill = "array_fill";
   $array_fill(start_index: 0, count: 100, value: 50);
   $array_fill(
           start_index: 0,
           count: 100,
           value: 50
   );
   
   test(test(1, 2, 3), test3: test(1, 2, 3), test2: test(1, test2: 2, test3: 
[1, 2, 3]));
   test(
           test(1, 2, 3),
           test3: test(1, 2, 3),
           test2: test(1, test2: 2, test3: [1, 2, 3])
   );
   
   reservedKeyWord(array: []);
   reservedKeyWord(
           array: []
   );
   
   test(1, 2, test3: $test1 === 0 ? 0 : 1);
   test(
           1,
           2,
           test3: $test1 === 0 ? 0 : 1
   );
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to