This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 258883 - [PHP7] Formatting for anonymous classes
Summary: [PHP7] Formatting for anonymous classes
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 8.2
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-18 06:09 UTC by junichi11
Modified: 2016-04-20 01:49 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
patch (99.01 KB, patch)
2016-04-18 06:09 UTC, junichi11
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description junichi11 2016-04-18 06:09:21 UTC
Created attachment 159298 [details]
patch

I just attach a patch now. I'll add a comment later.

Thanks.
Comment 1 junichi11 2016-04-18 14:43:42 UTC
- I added some options(brace placement, paren) (see [1]).
- I didn't add indent tokens if anonymous classes are used in the ReturnStatement and Assignment nodes.

// no indent tokens
$instance = new class {
    public function test() {
    }
});

// indent tokens are added
$instance = new class {
            public function test() {
            }
        });

- In case of Function/MethodInvocation, perhaps, they should be added if the wrapping option for Method Call is "Always".

// no indent tokens
test(new class {
    public function test() {
    }
},
$a,
$b);

// indent tokens are added
test(new class {
            public function test() {
            }
        },
        $a,
        $b);

- When "0" is set to the Before Class End option(Blank Lines), it may not be available in normal classes (related to the issue 255313).
I fixed it only if anonymous classes are used.

- We cannot format like the following if multiple interfaces are used and the wrapping option is enabled:

// expected
$instance = new class extends Foo implements
    Interface1,
    Interface2
{

};

// actual
$instance = new class extends Foo implements Interface1,
    Interface2
{

};
or
$instance = new class extends Foo implements
Interface1,
    Interface2
{

};

So, it should be fixed.

[1] https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md#8-anonymous-classes

Thanks.
Comment 2 junichi11 2016-04-18 14:46:03 UTC
Tomas, Could you please review it when you can make time?

Thanks.
Comment 3 Tomas Mysik 2016-04-19 08:51:46 UTC
Will do it ASAP. Thanks a lot, Junichi!
Comment 4 Tomas Mysik 2016-04-19 09:00:37 UTC
(In reply to junichi11 from comment #1)
> // no indent tokens
> $instance = new class {
>     public function test() {
>     }
> });

I prefer this case.

> // indent tokens are added
> test(new class {
>             public function test() {
>             }
>         },
>         $a,
>         $b);

I prefer this case.

> // actual
> $instance = new class extends Foo implements Interface1,
>     Interface2
> {
> 
> };

This case is totally OK for me.

Junichi, great job as always! Thank you a lot, really!
Comment 5 Tomas Mysik 2016-04-19 09:44:57 UTC
Patch applied, thanks a lot for it, Junichi!

http://hg.netbeans.org/web-main/rev/9b24600eb951
Comment 6 Quality Engineering 2016-04-20 01:49:24 UTC
Integrated into 'main-silver', will be available in build *201604200001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/9b24600eb951
User: Tomas Mysik <tmysik@netbeans.org>
Log: #258883 - [PHP7] Formatting for anonymous classes

Patch contributed by junichi11@netbeans.org.