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 250667 - Wrong formatting on Anonymous functions and functions callbacks
Summary: Wrong formatting on Anonymous functions and functions callbacks
Status: VERIFIED WORKSFORME
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 8.0.2
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-24 16:50 UTC by pzor
Modified: 2016-06-14 08:08 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
The problem described above. Bad formatting. (123.62 KB, image/png)
2015-02-24 16:50 UTC, pzor
Details
CakePHP file with the formatting issue. (1.92 KB, application/octet-stream)
2016-06-10 15:18 UTC, mcoury
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pzor 2015-02-24 16:50:11 UTC
Created attachment 152186 [details]
The problem described above. Bad formatting.

It would seem there are very similar problems to this, but I am using Yii2 framework, and in my most complicated Models, The Netbeans Formatter keeps getting it wrong and my last } is now almost to the absolute right.

Here is a code example:

$cartDiscounts = \common\models\Discounts::find()->innerJoinWith(['discountsConditions' => function($q) {
                        $q->andOnCondition(['applied_type' => 'cart'])->andOnCondition('NOW() BETWEEN date_from AND date_to');
                    }])->all();

This is how it looks, if I format it.
I wouldn't mind if the next line, went back to being aligned with $cartDiscounts, but it's not, and in a Model class, there are many relations like this.

I have attached a screenshot, for example
Comment 1 mcoury 2016-04-11 18:09:33 UTC
The issue affects CakePHP 3 code, so it will affect more users as CakePHP 3 usage becomes more prevalent.

An example:

    $query->contain([
      'Locations' => function ($q) {
        return $q->select(['location', 'sublocation']);
      },
          'Armors' => function ($q) {
        return $q->select(['armor', 'type']);
      },
          'Materials' => function ($q) {
        return $q->select(['material', 'manufacture', 'option']);
      }
        ]);
        $query->where([
          'Characterprotections.character_id' => $character_id,
          'Characterprotections.active' => true
        ]);
        $armorinfo = $query->all()->toArray();

should look like:

    $query->contain([
      'Locations' => function ($q) {
        return $q->select(['location', 'sublocation']);
      },
      'Armors' => function ($q) {
        return $q->select(['armor', 'type']);
      },
      'Materials' => function ($q) {
        return $q->select(['material', 'manufacture', 'option']);
      }
  ]);
  $query->where([
    'Characterprotections.character_id' => $character_id,
    'Characterprotections.active' => true
  ]);
  $armorinfo = $query->all()->toArray();

I don't think it's a defect (I'm using version 8.1), more like a feature request, but it makes the format function (which is otherwise awesome and I use it extensively) pretty much useless for CakePHP 3.
Comment 2 Tomas Mysik 2016-06-10 08:47:08 UTC
I tried the sample from comment #1 and it works for me. If the problem still exists, please provide a sample file.

Thanks.

Product Version: NetBeans IDE Dev (Build 20160610-49331e2a0591)
Java: 1.8.0_91; Java HotSpot(TM) 64-Bit Server VM 25.91-b14
Runtime: Java(TM) SE Runtime Environment 1.8.0_91-b14
System: Linux version 4.2.0-38-generic running on amd64; UTF-8; cs_CZ (nb)
Comment 3 mcoury 2016-06-10 15:18:07 UTC
Created attachment 160031 [details]
CakePHP file with the formatting issue.

This is for https://netbeans.org/bugzilla/show_bug.cgi?id=250667, comment #3
Comment 4 mcoury 2016-06-10 15:22:29 UTC
Tomas,

Thank you for looking in to the issue.

I've done a full uninstall/reinstall of NetBeans IDE (PHP) 8.1 to make sure I didn't have any custom configuration/plugins/modules and I still have the same formatting issue.

My configuration is:


Product Version: NetBeans IDE 8.1 (Build 201510222201)
Updates: NetBeans IDE is updated to version NetBeans 8.1 Patch 1
Java: 1.8.0_60; Java HotSpot(TM) 64-Bit Server VM 25.60-b23
Runtime: Java(TM) SE Runtime Environment 1.8.0_60-b27
System: Windows 8.1 version 6.3 running on amd64; Cp1252; en_US (nb)
User directory: C:\Users\Michael\AppData\Roaming\NetBeans\8.1
Cache directory: C:\Users\Michael\AppData\Local\NetBeans\Cache\8.1

I attached a sample file to comment #3.  (Sorry, I didn't know that my comment from the main area wouldn't got with the file along with the file comments.)

I've been really happy with the NetBeans IDE, and I appreciate all you folks do to make it so useful!

Michael
Comment 5 Tomas Mysik 2016-06-13 06:00:28 UTC
(In reply to Tomas Mysik from comment #2)
> Product Version: NetBeans IDE Dev (Build 20160610-49331e2a0591)
> Java: 1.8.0_91; Java HotSpot(TM) 64-Bit Server VM 25.91-b14
> Runtime: Java(TM) SE Runtime Environment 1.8.0_91-b14
> System: Linux version 4.2.0-38-generic running on amd64; UTF-8; cs_CZ (nb)

I used dev build - please, try it [1] and let us know.

Thanks.
[1] http://bits.netbeans.org/download/trunk/nightly/latest/
Comment 6 mcoury 2016-06-13 20:15:44 UTC
It's beautiful!

Thanks again for getting this working.  It makes my coding life a -lot- easier...

M
Comment 7 Tomas Mysik 2016-06-14 08:08:24 UTC
Thanks for letting us know.
Comment 8 Tomas Mysik 2016-06-14 08:08:58 UTC
Adding Junichi to CC, he very likely fixed this issue. Thank you!