NetBeans allows you to define either global or project specific code formatting options. To apply the following rules globaly navigate to Tools > Options > Editor > Formatting and select PHP language. To define project specific rules right click on your project and go to Properties > Formatting and check the `Use project specific options` and of course select PHP language.

Because the default rules of NetBeans 7.3 are really close to Lithium's coding standarts, we don't need to change many options. Let's begin...


netbeans_lithium_formatting.jpgTabs and Indents

  • Expand Tabs to Spaces: Uncheck
  • Number of Spaces per Indent: 4
  • Tab Size: 4
  • Right Margin: 120
  • Line Wrap: Off
  • Continuation Indentation: 0
  • Array Declaration Indentation: 4

Blank Lines

  • After Function: 0
  • After Open PHP Tag: 0
  • Before Close PHP Tag: 1

With the above settings we will get almost perfect code formatting for lithium framework but there are some hiccups. The most annoying is the double identation for keyword break in switch blocks and the chained object calls because we set the continuation indenation: 0 to match other more frequent parts of code in lithium. Check page two for a proper diff.

switch ($action) {
	case 'move':
			//Move
		break;

	case 'delete':
		//Delete
		break;
}

$object->call()
->callThis()
->andAndThat();

Comments

  1. Chris #1   Chris | Jun 15, 2013 at 21:51

    I changed my formatting for my Lithium projects today, if you have any suggestion to improve the ruleset, please be my guest.

    Maybe it will be better to start a github repo to maintain this...

Leave a Comment
It will not be published.