<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=RussellEngland</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=RussellEngland"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/Special:Contributions/RussellEngland"/>
	<updated>2026-06-12T10:32:50Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Javascript_Modules&amp;diff=49599</id>
		<title>Javascript Modules</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Javascript_Modules&amp;diff=49599"/>
		<updated>2016-03-06T08:28:33Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* Running grunt */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.9}}&lt;br /&gt;
&lt;br /&gt;
= Javascript Modules =&lt;br /&gt;
&lt;br /&gt;
== What is a Javascript module and why do I care? ==&lt;br /&gt;
&lt;br /&gt;
A Javascript module is nothing more than a collection of Javascript code that can be used (reliably) from other pieces of Javascript. &lt;br /&gt;
&lt;br /&gt;
== Why should I package my code as a module? ==&lt;br /&gt;
&lt;br /&gt;
By packaging your code as a module you break your code up into smaller reusable pieces. This is good because:&lt;br /&gt;
&lt;br /&gt;
a) Each smaller piece is simpler to understand / debug&lt;br /&gt;
&lt;br /&gt;
b) Each smaller piece is simpler to test&lt;br /&gt;
&lt;br /&gt;
c) You can re-use common code instead of duplicating it&lt;br /&gt;
&lt;br /&gt;
= How do I write a Javascript module in Moodle? =&lt;br /&gt;
&lt;br /&gt;
Since version 2.9, Moodle supports Javascript modules written using the Asynchronous Module Definition ([https://github.com/amdjs/amdjs-api/wiki/AMD AMD]) API. This is a standard API for creating Javascript modules and you will find many useful third party libraries that are already using this format. &lt;br /&gt;
&lt;br /&gt;
To edit or create an AMD module in Moodle you need to do a couple of things. &lt;br /&gt;
&lt;br /&gt;
== Install grunt ==&lt;br /&gt;
&lt;br /&gt;
The AMD modules in Moodle must be processed by some build tools before they will be visible to your web browser. We use &amp;quot;[http://gruntjs.com/ grunt]&amp;quot; as a build tool to wrap our different processes. Grunt is a build tool written in Javascript that runs in the &amp;quot;[http://nodejs.org/ nodejs]&amp;quot; environment.&lt;br /&gt;
&lt;br /&gt;
This means you first have to &#039;&#039;&#039;install nodejs&#039;&#039;&#039; - and its package manager [https://www.npmjs.com/ npm]. The details of how to install those packages will vary by operating system, but on Linux it&#039;s probably similar to &amp;quot;sudo apt-get install nodejs npm&amp;quot;. There are downloadable packages for other operating systems here: http://nodejs.org/download/.&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can &#039;&#039;&#039;run the command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 npm install&lt;br /&gt;
 npm install -g grunt-cli&lt;br /&gt;
&lt;br /&gt;
from the top of the Moodle directory to install all of the required tools. (You may need extra permissions to use the -g option.)&lt;br /&gt;
&lt;br /&gt;
== Running grunt ==&lt;br /&gt;
&lt;br /&gt;
See [[Grunt#Running_grunt]] for more details of specific grunt commands which can be used.&lt;br /&gt;
&lt;br /&gt;
If you get the error message&lt;br /&gt;
&lt;br /&gt;
 /usr/bin/env: node: No such file or directory&lt;br /&gt;
&lt;br /&gt;
Then see the thread https://github.com/nodejs/node-v0.x-archive/issues/3911&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 14.04 this fixed it for me:&lt;br /&gt;
&lt;br /&gt;
 sudo ln -fs /usr/bin/nodejs /usr/local/bin/node&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;Hello World&amp;quot; I am a Javascript Module ==&lt;br /&gt;
Lets now create a simple Javascript module so we can see how to lay things out. &lt;br /&gt;
&lt;br /&gt;
Each Javascript module is contained in a single source file in the &amp;lt;componentdir&amp;gt;/amd/src folder. The final name of the module is taken from the file name and the component name. E.g. block_overview/amd/src/helloworld.js would be a module named &amp;quot;block_overview/helloworld&amp;quot;. the name of the module is important when you want to call it from somewhere else in the code. &lt;br /&gt;
&lt;br /&gt;
After running grunt - the minified Javascript files are stored in the &amp;lt;componentdir&amp;gt;/amd/build folder. The javascript files are renamed to show that they are minified (helloworld.js becomes helloworld.min.js). &lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to add the built files (the ones in amd/build) to your git commits, or in production no-one will see your changes. &lt;br /&gt;
&lt;br /&gt;
Lets create a simple module now:&lt;br /&gt;
&lt;br /&gt;
blocks/overview/amd/src/helloworld.js&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
// Standard license block omitted.&lt;br /&gt;
/*&lt;br /&gt;
 * @package    block_overview&lt;br /&gt;
 * @copyright  2015 Someone cool&lt;br /&gt;
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
 /**&lt;br /&gt;
  * @module block_overview/helloworld&lt;br /&gt;
  */&lt;br /&gt;
define([&#039;jquery&#039;], function($) {&lt;br /&gt;
&lt;br /&gt;
     /** &lt;br /&gt;
      * Give me blue.&lt;br /&gt;
      * @access private&lt;br /&gt;
      * @return {string}&lt;br /&gt;
      */&lt;br /&gt;
     var makeItBlue = function() {&lt;br /&gt;
          // We can use our jquery dependency here.&lt;br /&gt;
          return $(&#039;.blue&#039;).show();&lt;br /&gt;
     };&lt;br /&gt;
      &lt;br /&gt;
    /**&lt;br /&gt;
     * @constructor&lt;br /&gt;
     * @alias module:block_overview/helloworld&lt;br /&gt;
     */&lt;br /&gt;
    var greeting = function() {&lt;br /&gt;
        /** @access private */&lt;br /&gt;
        var privateThoughts = &#039;I like the colour blue&#039;;&lt;br /&gt;
        &lt;br /&gt;
        /** @access public */&lt;br /&gt;
        this.publicThoughts = &#039;I like the colour orange&#039;;&lt;br /&gt;
&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * A formal greeting.&lt;br /&gt;
     * @access public&lt;br /&gt;
     * @return {string}&lt;br /&gt;
     */&lt;br /&gt;
    greeting.prototype.formal = function() {&lt;br /&gt;
        return &#039;How do you do?&#039;;&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * An informal greeting.&lt;br /&gt;
     * @access public&lt;br /&gt;
     * @return {string}&lt;br /&gt;
     */&lt;br /&gt;
    greeting.prototype.informal = function() {&lt;br /&gt;
        return &#039;Wassup!&#039;;&lt;br /&gt;
    };&lt;br /&gt;
    return greeting;&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The most interesting line above is:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
define([&#039;jquery&#039;], function($) {&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All AMD modules must call &amp;quot;define()&amp;quot; as the first and only global scoped piece of code. This ensures the javascript code contains no global variables and will not conflict with any other loaded module. The name of the module does not need to be specified because it is determined from the filename and component (but it can be listed in a comment for JSDoc as shown here). &lt;br /&gt;
&lt;br /&gt;
The first argument to &amp;quot;define&amp;quot; is the list of dependencies for the module. This argument must be passed as an array, even if there is only one. In this example &amp;quot;jquery&amp;quot; is a dependency. &amp;quot;jquery&amp;quot; is shipped as a core module is available to all AMD modules. &lt;br /&gt;
&lt;br /&gt;
The second argument to &amp;quot;define&amp;quot; is the function that defines the module. This function will receive as arguments, each of the requested dependencies in the same order they were requested. In this example we receive JQuery as an argument and we name the variable &amp;quot;$&amp;quot; (it&#039;s a JQuery thing). We can then access JQuery normally through the $ variable which is in scope for any code in our module. &lt;br /&gt;
&lt;br /&gt;
The rest of the code in this example is a standard way to define a Javascript module with public/private variables and methods. There are many ways to do this, this is only one.&lt;br /&gt;
&lt;br /&gt;
It is important that we are returning &#039;greeting&#039;. If there is no return then your module will be declared as undefined.&lt;br /&gt;
&lt;br /&gt;
== Loading modules dynamically ==&lt;br /&gt;
What do you do if you don&#039;t know in advance which modules will be required? Stuffing all possible required modules in the define call is one solution, but it&#039;s ugly and it only works for code that is in an AMD module (what about inline code in the page?). AMD lets you load a dependency any time you like. &lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// Load a new dependency.&lt;br /&gt;
require([&#039;mod_wiki/timer&#039;], function(timer) {&lt;br /&gt;
   // timer is available to do my bidding.&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Including an external javascript/jquery library ==&lt;br /&gt;
If you want to include a javascript / jquery library downloaded from the internet you can do so as follows:&lt;br /&gt;
&lt;br /&gt;
If the library is in AMD format and has a define:&lt;br /&gt;
e.g. i want to include the jquery final countdown timer on my page ( hilios.github.io/jQuery.countdown/ )&lt;br /&gt;
* download the module in both normal and minified versions&lt;br /&gt;
* place the modules in your moodle install e.g. your custom theme dir, or plugin dir&lt;br /&gt;
* /theme/mytheme/amd/src/jquery.countdown.js&lt;br /&gt;
&lt;br /&gt;
you can now include the module and initialise it (there are multiple ways to do this)&lt;br /&gt;
php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// 1. Create your own amd module and initialise it:&lt;br /&gt;
$this-&amp;gt;page-&amp;gt;requires-&amp;gt;js_call_amd(&#039;theme_mytheme/countdowntimer&#039;, &#039;initialise&#039;, $params);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
javascript:&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
//1. put this code in theme/mytheme/amd/src/countdowntimer.js&lt;br /&gt;
define([&#039;jquery&#039;, &#039;theme_mytheme/jquery.countdown&#039;], function($) {&lt;br /&gt;
    return {&lt;br /&gt;
        initialise: function ($params) {&lt;br /&gt;
           $(&#039;#clock&#039;).countdown(&#039;2020/10/10&#039;, function(event) {&lt;br /&gt;
             $(this).html(event.strftime(&#039;%D days %H:%M:%S&#039;));&lt;br /&gt;
           });&lt;br /&gt;
        }&lt;br /&gt;
    };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. put the javascript into a mustache template&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
// /theme/mytheme/templates/countdowntimer.mustache&lt;br /&gt;
&amp;lt;span id=&amp;quot;clock&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
{{#js}}&lt;br /&gt;
require([&#039;jquery&#039;, &#039;theme_mytheme/jquery.countdown&#039;], function($) {&lt;br /&gt;
           $(&#039;#clock&#039;).countdown(&#039;2020/10/10&#039;, function(event) {&lt;br /&gt;
             $(this).html(event.strftime(&#039;%D days %H:%M:%S&#039;));&lt;br /&gt;
           });&lt;br /&gt;
});&lt;br /&gt;
{{/js}}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. call the javascript directly from php -- although who would want to put javascript into php? ergh..&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$PAGE-&amp;gt;requires-&amp;gt;js_amd_inline(&#039;&lt;br /&gt;
require([&#039;theme_mytheme/jquery.countdown&#039;], function(min) {&lt;br /&gt;
           $(&#039;#clock&#039;).countdown(&#039;2020/10/10&#039;, function(event) {&lt;br /&gt;
             $(this).html(event.strftime(&#039;%D days %H:%M:%S&#039;));&lt;br /&gt;
           });&lt;br /&gt;
});&lt;br /&gt;
&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Embedding AMD code in a page ==&lt;br /&gt;
So you have created lots of cool Javascript modules. Great. How do we actually call them? Any javascript code that calls an AMD module must execute AFTER the requirejs module loader has finished loading. We have provided a function &amp;quot;js_call_amd&amp;quot; that will call a single function from an AMD module with parameters.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$PAGE-&amp;gt;requires-&amp;gt;js_call_amd($modulename, $functionname, $params);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
that will &amp;quot;do the right thing&amp;quot; with your block of AMD code and execute it at the end of the page, after our AMD module loader has loaded. &lt;br /&gt;
Notes:&lt;br /&gt;
* the $modulename is the &#039;componentname/modulename&#039; discussed above&lt;br /&gt;
* the $functionname is the name of a public function exposed by the amd module. &lt;br /&gt;
* the $params is an array of params passed as arguments to the function. These should be simple types that can be handled by json_encode (no recursive arrays, or complex classes please). &lt;br /&gt;
* if the size of the params array is too large (&amp;gt; 1Kb), this will produce a developer warning. Do not attempt to pass large amounts of data through this function, it will pollute the page size. A preferred approach is to pass css selectors for DOM elements that contain data-attributes for any required data, or fetch data via ajax in the background.&lt;br /&gt;
&lt;br /&gt;
AMD / JS code can also be embedded on a page via mustache templates&lt;br /&gt;
see here: https://docs.moodle.org/dev/Templates#What_if_a_template_contains_javascript.3F&lt;br /&gt;
&lt;br /&gt;
== But I have a mega JS file I don&#039;t want loaded on every page? ==&lt;br /&gt;
Loading all JS files at once and stuffing them in the browser cache is the right choice for MOST js files, there are probably some exceptions. For these files, you can rename the javascript file to end with the suffix &amp;quot;-lazy.js&amp;quot; which indicates that the module will not be loaded by default, it will be requested the first time it is used. There is no difference in usage for lazy loaded modules, the require() call looks exactly the same, it&#039;s just that the module name will also have the &amp;quot;-lazy&amp;quot; suffix.&lt;br /&gt;
&lt;br /&gt;
[[Category:AJAX]]&lt;br /&gt;
[[Category:Javascript]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Data_manipulation_API&amp;diff=42295</id>
		<title>Data manipulation API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Data_manipulation_API&amp;diff=42295"/>
		<updated>2013-09-09T14:14:58Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* SQL compatibility functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle_2.0}}This page describes the functions available to access data in the Moodle database. You should &#039;&#039;&#039;exclusively&#039;&#039;&#039; use these functions in order to retrieve or modify database content because these functions provide a high level of abstraction and guarantee that your database manipulation will work against different RDBMSes.&lt;br /&gt;
&lt;br /&gt;
Where possible, tricks and examples will be documented here in order to make developers&#039; lives a bit easier. Of course, feel free to clarify, complete and add more information to  this documentation. It will be welcome, absolutely!&lt;br /&gt;
&lt;br /&gt;
== Main info ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important note:&#039;&#039;&#039; All the functions shown on this page are for use in &#039;&#039;&#039;Moodle 2.0 upwards&#039;&#039;&#039;, where we changed the [[DB layer 2.0|DB layer]] to support some new features. If you need information for previous Moodle version, take a look to the [[DML functions - pre 2.0|DML functions - pre 2.0]] page. For a detailed reference of changes, see the [[DB layer 2.0 migration docs|migration docs]].&lt;br /&gt;
&lt;br /&gt;
* All the function calls on this page are public methods of the $DB global object, so you&#039;ll need to &amp;quot;import&amp;quot; it within your functions (not needed in global scripts) with one simple:&lt;br /&gt;
&amp;lt;code php&amp;gt;global $DB;&amp;lt;/code&amp;gt;&lt;br /&gt;
* The $DB global object is an instance of the moodle_database class, which is defined in [http://git.moodle.org/gw?p=moodle.git;a=blob;f=lib/dml/moodle_database.php;h=2a6676c84e7c77b0534f18a13ba584f58a8ed024;hb=refs/heads/master moodle_database.php]&lt;br /&gt;
* All the $table parameters in the functions are meant to be the table name &#039;&#039;without&#039;&#039; prefixes.&lt;br /&gt;
&amp;lt;code php&amp;gt;$user = $DB-&amp;gt;get_record(&#039;user&#039;, array(&#039;id&#039;=&amp;gt;&#039;1&#039;));&amp;lt;/code&amp;gt;&lt;br /&gt;
* When using the xxx_sql() functions, table names must be enclosed between curly braces.&lt;br /&gt;
&amp;lt;code php&amp;gt;$user = $DB-&amp;gt;get_record_sql(&#039;SELECT * FROM {user} WHERE id = ?&#039;, array(1));&amp;lt;/code&amp;gt;&lt;br /&gt;
* All the $conditions parameters in the functions are arrays of fieldname=&amp;gt;fieldvalue elements.&lt;br /&gt;
&amp;lt;code php&amp;gt;$user = $DB-&amp;gt;get_record(&#039;user&#039;, array(&#039;firstname&#039;=&amp;gt;&#039;Martin&#039;, &#039;lastname&#039;=&amp;gt;&#039;Dougiamas&#039;));&amp;lt;/code&amp;gt;&lt;br /&gt;
* All the $params parameters in the functions are arrays of values used to fill placeholders in SQL statements. Both the question mark and named placeholders can be used. Note that named params &#039;&#039;&#039;must be unique&#039;&#039;&#039; even if the value passed is the same.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/// Question mark placeholders:&lt;br /&gt;
   $DB-&amp;gt;get_record_sql(&#039;SELECT * FROM {user} WHERE firstname = ? AND lastname = ?&#039;, &lt;br /&gt;
                       array(&#039;Martin&#039;, &#039;Dougiamas&#039;));&lt;br /&gt;
&lt;br /&gt;
/// Named placeholders:&lt;br /&gt;
   $DB-&amp;gt;get_record_sql(&#039;SELECT * FROM {user} WHERE firstname = :firstname AND lastname = :lastname&#039;,&lt;br /&gt;
                       array(&#039;firstname&#039;=&amp;gt;&#039;Martin&#039;, &#039;lastname&#039;=&amp;gt;&#039;Dougiamas&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The functions ==&lt;br /&gt;
&lt;br /&gt;
===Getting a single record===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_record($table, array $conditions, $fields=&#039;*&#039;, $strictness=IGNORE_MISSING) &lt;br /&gt;
  /// Get a single database record as an object where all the given conditions met.&lt;br /&gt;
  /// @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;&lt;br /&gt;
  ///                        IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended);&lt;br /&gt;
  ///                        MUST_EXIST means throw exception if no record or multiple records found&lt;br /&gt;
o $DB-&amp;gt;get_record_select($table, $select, array $params=null, $fields=&#039;*&#039;, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single database record as an object which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_record_sql($sql, array $params=null, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single database record as an object using a SQL statement.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Getting an hashed array of records===&lt;br /&gt;
Each of the following methods return an array of objects. The array is indexed by the first column of the fields returned by the query. Thus to assure consistent data, it appears to be best practice to ensure that your query include an &amp;quot;id column&amp;quot; as the first field. (When developing custom tables, be sure to make id your first column for this reason!)&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_records($table, array $conditions=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get a number of records as an array of objects where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;get_records_select($table, $select, array $params=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get a number of records as an array of objects which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0)&lt;br /&gt;
  /// Get a number of records as an array of objects using a SQL statement.&lt;br /&gt;
o $DB-&amp;gt;get_records_list($table, $field, array $values, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=&#039;&#039;, $limitnum=&#039;&#039;) &lt;br /&gt;
  /// Get a number of records as an array of objects where one field match one list of values.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Getting data as key/value pairs in an associative array===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_records_menu($table, array $conditions=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get the first two columns from a number of records as an associative array where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;get_records_select_menu($table, $select, array $params=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0)&lt;br /&gt;
  /// Get the first two columns from a number of records as an associative array which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_records_sql_menu($sql, array $params=null, $limitfrom=0, $limitnum=0)&lt;br /&gt;
  /// Get the first two columns from a number of records as an associative array using a SQL statement.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seeing how many records match a given criterion===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;count_records($table, array $conditions=null) &lt;br /&gt;
  /// Count the records in a table where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;count_records_select($table, $select, array $params=null, $countitem=&amp;quot;COUNT(&#039;x&#039;)&amp;quot;) &lt;br /&gt;
  /// Count the records in a table which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;count_records_sql($sql, array $params=null) &lt;br /&gt;
  /// Get the result of an SQL SELECT COUNT(...) query.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seeing if one record exists===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;record_exists($table, array $conditions=null) &lt;br /&gt;
  /// Test whether a record exists in a table where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;record_exists_select($table, $select, array $params=null) &lt;br /&gt;
  /// Test whether any records exists in a table which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;record_exists_sql($sql, array $params=null) &lt;br /&gt;
  /// Test whether a SQL SELECT statement returns any records.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Examples====&lt;br /&gt;
=====moodle_database::get_records()=====&lt;br /&gt;
Get a number of records as an array of objects where all the given conditions met.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records where foo = bar&lt;br /&gt;
$result = $DB-&amp;gt;get_records($table,array(&#039;foo&#039;=&amp;gt;&#039;bar&#039;));&lt;br /&gt;
&lt;br /&gt;
///Get all records where foo = bar and jon = doe&lt;br /&gt;
$result = $DB-&amp;gt;get_records($table,array(&#039;foo&#039; =&amp;gt; &#039;bar&#039; , &#039;jon&#039; =&amp;gt; &#039;doe&#039;));&lt;br /&gt;
&lt;br /&gt;
///Get all records where foo = bar, but only return the fields foo,bar,jon,doe&lt;br /&gt;
$result = $DB-&amp;gt;get_records($table,array(&#039;foo&#039;=&amp;gt;&#039;bar&#039;),null,&#039;foo,bar,jon,doe&#039;);&lt;br /&gt;
///The previous example would cause data issues unless the &#039;foo&#039; field happens to have unique values.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_select()=====&lt;br /&gt;
Get a number of records as an array of objects which match a particular WHERE clause. Note that the array keys will be the id of the object so you must not rely on the first item having a key of 0.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records where jon = &#039;doe&#039; and bob is not = &#039;tom&#039;&lt;br /&gt;
///The &#039;select&#039; parameter is (if not empty) is dropped directly into the WHERE clause without alteration.&lt;br /&gt;
$table = &#039;foo&#039;;&lt;br /&gt;
$select = &amp;quot;jon = &#039;doe&#039; AND bob &amp;lt;&amp;gt; &#039;tom&#039;&amp;quot;; //is put into the where clause&lt;br /&gt;
$result = $DB-&amp;gt;get_records_select($table,$select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_sql()=====&lt;br /&gt;
Get a number of records as an array of objects using a SQL statement. Defined as an abstract function in moodle_database, this method is implemented per database type.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records from &#039;table&#039; where foo = bar&lt;br /&gt;
$result = $DB-&amp;gt;get_records_sql(&#039;SELECT * FROM {table} WHERE foo = ?&#039;, array(&#039;bar&#039;));&lt;br /&gt;
&lt;br /&gt;
///Get all records from &#039;table&#039; where foo = &#039;bar&#039; and bob = &#039;tom&#039;&lt;br /&gt;
///This is somewhat similar to how Drupal makes its queries&lt;br /&gt;
$result = $DB-&amp;gt;get_records_sql(&#039;SELECT * FROM {table} WHERE foo = ? AND bob = ?&#039;, array( &#039;bar&#039; , &#039;tom&#039; ));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_list()=====&lt;br /&gt;
Get a number of records as an array of objects where one field match one list of values.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records where the values(&#039;bar&#039;, &#039;elephant&#039;, &#039;moodle&#039;) are found in the field &#039;foo&#039;&lt;br /&gt;
$result = $DB-&amp;gt;get_records_list($table, &#039;foo&#039;, array( &#039;bar&#039;, &#039;elephant&#039;, &#039;moodle&#039;));&lt;br /&gt;
&lt;br /&gt;
///Get all records where the values(&#039;bar&#039;, &#039;elephant&#039;, &#039;moodle&#039;) are found in the field &#039;foo&#039;&lt;br /&gt;
///Only returning the fields &#039;id&#039;, &#039;test&#039; and &#039;taco&#039;&lt;br /&gt;
$result = $DB-&amp;gt;get_records_list($table, &#039;foo&#039;, array( &#039;bar&#039;, &#039;elephant&#039;, &#039;moodle&#039;), null, &#039;id,test,taco&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_menu()=====&lt;br /&gt;
Get the first two columns from a number of records as an associative array where all the given conditions met. &lt;br /&gt;
You can choose the two fields or leave the parameter blank and the method will return the first two columns of the table.&lt;br /&gt;
Returns an associative array. &lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records from table &#039;foo&#039; where column &#039;foo&#039; is equal to the value &#039;bar&#039;&lt;br /&gt;
$table = &#039;foo&#039;; ///name of table&lt;br /&gt;
$conditions = array(&#039;foo&#039;=&amp;gt;&#039;bar&#039;); ///the name of the field (key) and the desired value&lt;br /&gt;
&lt;br /&gt;
$result = $DB-&amp;gt;get_records_menu($table,$conditions));&lt;br /&gt;
&lt;br /&gt;
///Get all records from table &#039;foo&#039; where column &#039;foo&#039; is equal to the value &#039;bar&#039;&lt;br /&gt;
///Returning the values from the columns &#039;id&#039; and &#039;tacos&#039;&lt;br /&gt;
$table = &#039;foo&#039;; ///name of table&lt;br /&gt;
$conditions = array(&#039;foo&#039;=&amp;gt;&#039;bar&#039;); ///the name of the field (key) and the desired value&lt;br /&gt;
$sort = &#039;id&#039;; //field or fields you want to sort the result by&lt;br /&gt;
$fields = &#039;id, tacos&#039;; ///list of fields to return&lt;br /&gt;
&lt;br /&gt;
$result = $DB-&amp;gt;get_records_menu($table,$conditions,$sort,$fields));  //If you do not specify $fields, the first two columns of the table will be returned&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
The result of this last example will look something like:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/// The value of the id field  is 909 and the value of the &#039;tacos&#039; column is 6&lt;br /&gt;
array(1) { [909]=6 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_select_menu()=====&lt;br /&gt;
Get the first two columns from a number of records as an associative array which match a particular WHERE clause.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records where jon = &#039;doe&#039; and bob is not = &#039;tom&#039;&lt;br /&gt;
///The &#039;select&#039; parameter is (if not empty) is dropped directly into the WHERE clause without alteration.&lt;br /&gt;
$table = &#039;foo&#039;;&lt;br /&gt;
$select = &#039;jon = &amp;quot;doe&amp;quot; AND bob != &amp;quot;tom&amp;quot; &#039;; //is put into the where clause&lt;br /&gt;
$result = $DB-&amp;gt;get_records_select_menu($table,$select);&lt;br /&gt;
&lt;br /&gt;
$table = &#039;foo&#039;;&lt;br /&gt;
$select = &#039;jon = &amp;quot;doe&amp;quot; AND bob != &amp;quot;tom&amp;quot; &#039;; //is put into the where clause&lt;br /&gt;
$params = null;&lt;br /&gt;
$fields = &#039;id, tacos&#039;;//return these fields&lt;br /&gt;
$sort = &#039;id&#039;; //field or fields you want to sort the result by&lt;br /&gt;
$result = $DB-&amp;gt;get_records_select_menu($table,$select,$params,$sort,$fields);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result of this last example will look something like:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/// The value of the id field  is 909 and the value of the &#039;tacos&#039; column is 6&lt;br /&gt;
array(1) { [909]=6 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_sql_menu()=====&lt;br /&gt;
Get the first two columns from a number of records as an associative array using a SQL statement.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records from table foo where bar = 6&lt;br /&gt;
$sql = &#039;SELECT * FROM foo WHERE bar = ?&#039;;&lt;br /&gt;
$params = array(6);&lt;br /&gt;
&lt;br /&gt;
$result = $DB-&amp;gt;get_records_sql_menu($sql,$params);&lt;br /&gt;
&lt;br /&gt;
///Get all records from table foo where bar = 6&lt;br /&gt;
$sql = &#039;SELECT id,tacos FROM foo WHERE bar = ?&#039;;&lt;br /&gt;
$params = array(6);&lt;br /&gt;
&lt;br /&gt;
$result = $DB-&amp;gt;get_records_sql_menu($sql,$params);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result of this last example will look something like:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/// The value of the id field  is 909 and the value of the &#039;tacos&#039; column is 6&lt;br /&gt;
array(1) { [909]=6 } &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Getting a particular field value from one record===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_field($table, $return, array $conditions, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single field value from a table record where all the given conditions met.&lt;br /&gt;
  /// @param int $strictness&lt;br /&gt;
  ///   IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;&lt;br /&gt;
  ///   IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended);&lt;br /&gt;
  ///   MUST_EXIST means throw exception if no record or multiple records found&lt;br /&gt;
o $DB-&amp;gt;get_field_select($table, $return, $select, array $params=null, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single field value from a table record which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_field_sql($sql, array $params=null, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single field value (first field) using a SQL statement.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Getting a particular field value from various records===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_fieldset_select($table, $return, $select, array $params=null)&lt;br /&gt;
  /// Selects records and return values of chosen field as an array which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_fieldset_sql($sql, array $params=null)&lt;br /&gt;
  /// Selects records and return values (first field) as an array using a SQL statement.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setting a particular field in the database===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;set_field($table, $newfield, $newvalue, array $conditions=null)&lt;br /&gt;
  /// Set a single field in every table record where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;set_field_select($table, $newfield, $newvalue, $select, array $params=null)&lt;br /&gt;
  /// Set a single field in every table record which match a particular WHERE clause.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Deleting Records===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;delete_records($table, array $conditions=null) &lt;br /&gt;
  /// Delete the records from a table where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;delete_records_select($table, $select, array $params=null)&lt;br /&gt;
  /// Delete one or more records from a table which match a particular WHERE clause.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inserting Records===&lt;br /&gt;
The method to insert records is called aptly enough, insert_record(). The method accepts 4 parameters, but the fourth, &amp;quot;bulk&amp;quot;, in most implementations is unused.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;insert_record($table, $dataobject, $returnid=true, $bulk=false) &lt;br /&gt;
  /// Insert a record into a table and return the &amp;quot;id&amp;quot; field if required.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
====Example(s)====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$record = new stdClass();&lt;br /&gt;
$record-&amp;gt;name         = &#039;overview&#039;;&lt;br /&gt;
$record-&amp;gt;displayorder = &#039;10000&#039;;&lt;br /&gt;
$DB-&amp;gt;insert_record(&#039;quiz_report&#039;, $record, false);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$record = new stdClass();&lt;br /&gt;
$record-&amp;gt;name         = &#039;overview&#039;;&lt;br /&gt;
$record-&amp;gt;displayorder = &#039;10000&#039;;&lt;br /&gt;
$lastinsertid = $DB-&amp;gt;insert_record(&#039;quiz_report&#039;, $record);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Updating Records===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;update_record($table, $dataobject, $bulk=false)&lt;br /&gt;
  /// Update a record in a table.&lt;br /&gt;
  /// &lt;br /&gt;
  /// $dataobject is an object containing needed data&lt;br /&gt;
  /// Relies on $dataobject having a variable &amp;quot;id&amp;quot; to&lt;br /&gt;
  /// specify the record to update&lt;br /&gt;
  /// &lt;br /&gt;
  /// @param string $table The database table to be checked against.&lt;br /&gt;
  /// @param object $dataobject An object with contents equal to fieldname=&amp;gt;fieldvalue.&lt;br /&gt;
  ///        Must have an entry for &#039;id&#039; to map to the table specified.&lt;br /&gt;
  /// @param bool $bulk true means repeated updates expected&lt;br /&gt;
  /// @return bool true&lt;br /&gt;
  /// @throws dml_exception if an error occurs.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Recordsets===&lt;br /&gt;
&lt;br /&gt;
Where the number of records to be retrieved from DB is high, the &#039;&#039;&#039;get_records_xxx()&#039;&#039;&#039; functions above are far from optimal, because they load all the records in memory at the same time. Under those circumstances, it is highly recommended to use these &#039;&#039;&#039;get_recordset_xxx()&#039;&#039;&#039; functions instead, which use one nice mechanism to iterate over all the target records and save a lot of memory.&lt;br /&gt;
&lt;br /&gt;
Only one thing is &#039;&#039;&#039;absolutely important&#039;&#039;&#039;: Don&#039;t forget to close the recordsets after using them! (This will free up a lot of resources in the RDBMS).&lt;br /&gt;
&lt;br /&gt;
Here is the general way to iterate over records using the &#039;&#039;&#039;get_recordset_xxx()&#039;&#039;&#039; functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$rs = $DB-&amp;gt;get_recordset(....) {&lt;br /&gt;
foreach ($rs as $record) {&lt;br /&gt;
    // Do whatever you want with this record&lt;br /&gt;
}&lt;br /&gt;
$rs-&amp;gt;close(); // Don&#039;t forget to close the recordset!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And this is the list of available functions (100% paired with the get_records_xxx() above):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_recordset($table, array $conditions=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get a number of records as a moodle_recordset where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;get_recordset_select($table, $select, array $params=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get a number of records as a moodle_recordset which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_recordset_sql($sql, array $params=null, $limitfrom=0, $limitnum=0);&lt;br /&gt;
  /// Get a number of records as a moodle_recordset using a SQL statement.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;get_recordset_list($table, $field=&#039;&#039;, $values=&#039;&#039;, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=&#039;&#039;, $limitnum=&#039;&#039;) &lt;br /&gt;
  /// Get a number of records as a moodle_recordset where one field matches one list of values.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike get_record functions, you cannot use &amp;lt;tt&amp;gt;$rs == true&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;!empty($rs)&amp;lt;/tt&amp;gt; to determine if any records were found.&lt;br /&gt;
Recordsets implement the standard PHP Iterator interface (http://uk.php.net/manual/en/class.iterator.php)&lt;br /&gt;
&lt;br /&gt;
So,&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if ($rs-&amp;gt;valid()) {&lt;br /&gt;
    // The recordset contains records.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delegated transactions===&lt;br /&gt;
&lt;br /&gt;
* Please note some databases do not support transactions (such as the MyISAM MySQL database engine), however all server administrators are strongly encouraged to migrate to databases that support transactions (such as the InnoDB MySQL database engine).&lt;br /&gt;
* Previous versions supported only one level of transaction. Since Moodle 2.0, the DML layer emulates delegated transactions that allow nesting of transactions.&lt;br /&gt;
* Transactions should not be used much in Moodle core; they are intended for various plugins such as web services, enrol and auth plugins.&lt;br /&gt;
* Some subsystems (such as messaging) do not support transactions because is it is not possible to rollback in external systems.&lt;br /&gt;
&lt;br /&gt;
A transaction is started by:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$transaction = $DB-&amp;gt;start_delegated_transaction();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and finished by:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$transaction-&amp;gt;allow_commit();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usually a transaction is rolled back when an exception is thrown. &amp;lt;code&amp;gt;$transaction-&amp;gt;rollback($ex);&amp;lt;/code&amp;gt; must be used very carefully because it might break compatibility with databases that do not support transactions. Transactions cannot be used as part of expected code flow; they can be used only as an emergency protection of data consistency.&lt;br /&gt;
&lt;br /&gt;
See more details in [[DB layer 2.0 delegated transactions]] or MDL-20625.&lt;br /&gt;
&lt;br /&gt;
====Example(s)====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
global $DB;&lt;br /&gt;
try {&lt;br /&gt;
     $transaction = $DB-&amp;gt;start_delegated_transaction();&lt;br /&gt;
     // Insert a record&lt;br /&gt;
     $DB-&amp;gt;insert(&#039;foo&#039;, $object);&lt;br /&gt;
     $DB-&amp;gt;insert(&#039;bar&#039;, $otherobject);&lt;br /&gt;
&lt;br /&gt;
     // Assuming the both inserts work, we get to the following line.&lt;br /&gt;
     $transaction-&amp;gt;allow_commit();&lt;br /&gt;
} catch(Exception $e) {&lt;br /&gt;
     $transaction-&amp;gt;rollback($e);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SQL compatibility functions===&lt;br /&gt;
&lt;br /&gt;
In order have real cross-db compatibility, there are some helper functions used to build SQL fragments based on the DB Moodle is running. Using them we&#039;ll avoid conditional queries here and there and have those &amp;quot;incompatibilities&amp;quot; fixed once and for ever.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;sql_bitand($int1, $int2) &lt;br /&gt;
  /// Returns the SQL text to be used in order to perform one bitwise AND &lt;br /&gt;
  /// operation between 2 integers.&lt;br /&gt;
o $DB-&amp;gt;sql_bitnot($int1) &lt;br /&gt;
  /// Returns the SQL text to be used in order to perform one bitwise NOT &lt;br /&gt;
  /// operation with 1 integer.&lt;br /&gt;
o $DB-&amp;gt;sql_bitor($int1, $int2)&lt;br /&gt;
  /// Returns the SQL text to be used in order to perform one bitwise OR &lt;br /&gt;
  /// operation between 2 integers.&lt;br /&gt;
o $DB-&amp;gt;sql_bitxor($int1, $int2) &lt;br /&gt;
  /// Returns the SQL text to be used in order to perform one bitwise XOR &lt;br /&gt;
  /// operation between 2 integers.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_null_from_clause()&lt;br /&gt;
  /// Returns the FROM clause required by some DBs in all SELECT statements.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_ceil($fieldname)&lt;br /&gt;
  /// Returns the correct CEIL expression applied to fieldname.&lt;br /&gt;
o $DB-&amp;gt;sql_like($fieldname, $param, $casesensitive = true, $accentsensitive = true, $notlike = false, $escapechar = &#039; \\ &#039;)&lt;br /&gt;
  /// Returns the proper SQL to do LIKE. For example:&lt;br /&gt;
  $DB-&amp;gt;get_records_sql(&#039;SELECT ...  WHERE &#039;.$DB-&amp;gt;sql_like(&#039;idnumber&#039;, &#039;:idnum&#039;).&#039; ... &#039;, array( &#039;idnum&#039; =&amp;gt; &#039;foo&#039;));&lt;br /&gt;
  /// Note: Use $DB-&amp;gt;sql_like_escape(...) when its user input from a form.&lt;br /&gt;
&lt;br /&gt;
o $DB-&amp;gt;sql_length($fieldname)&lt;br /&gt;
  /// Returns the SQL text to be used to calculate the length in characters of one expression.&lt;br /&gt;
o $DB-&amp;gt;sql_modulo($int1, $int2)&lt;br /&gt;
  /// Returns the SQL text to be used in order to calculate module - remainder after division&lt;br /&gt;
o $DB-&amp;gt;sql_position($needle, $haystack)&lt;br /&gt;
  /// Returns the SQL for returning searching one string for the location of another.&lt;br /&gt;
  /// Note: If using placeholders BOTH in $needle and $haystack, they MUST be named placeholders.&lt;br /&gt;
o $DB-&amp;gt;sql_substr($expr, $start, $length=false)&lt;br /&gt;
  /// Returns the proper substr() SQL text used to extract substrings from DB.&lt;br /&gt;
  /// Note: This fuction has changed in Moodle 2.0 and now at least 2 params are mandatory.&lt;br /&gt;
  /// Note: Now it returns the whole SQL text to be used instead of only the function name.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_cast_char2int($fieldname, $text=false)&lt;br /&gt;
  /// Returns the SQL to be used in order to CAST one CHAR column to INTEGER.&lt;br /&gt;
o $DB-&amp;gt;sql_cast_char2real($fieldname, $text=false)&lt;br /&gt;
  /// Returns the SQL to be used in order to CAST one CHAR column to REAL number.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_compare_text($fieldname, $numchars=32) &lt;br /&gt;
  /// Returns the SQL text to be used to compare one TEXT (clob) column.&lt;br /&gt;
  /// with one VARCHAR column.&lt;br /&gt;
o $DB-&amp;gt;sql_order_by_text($fieldname, $numchars=32)&lt;br /&gt;
  /// Returns the SQL text to be used to order by one TEXT (clob) column.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_concat()&lt;br /&gt;
  /// Returns the proper SQL to do CONCAT between the elements passed.&lt;br /&gt;
o $DB-&amp;gt;sql_concat_join($separator=&amp;quot;&#039; &#039;&amp;quot;, $elements=array())&lt;br /&gt;
  /// Returns the proper SQL to do CONCAT between the elements passed using one separator.&lt;br /&gt;
o $DB-&amp;gt;sql_fullname($first=&#039;firstname&#039;, $last=&#039;lastname&#039;)&lt;br /&gt;
  /// Returns the proper SQL to concatenate $firstname and $lastname.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_isempty($tablename, $fieldname, $nullablefield, $textfield)&lt;br /&gt;
  /// Returns the proper SQL to know if one field is empty.&lt;br /&gt;
o $DB-&amp;gt;sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield)&lt;br /&gt;
  /// Returns the proper SQL to know if one field is not empty.&lt;br /&gt;
o $DB-&amp;gt;sql_empty()&lt;br /&gt;
  /// Returns the empty string char used by every supported DB.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Debug fuctions===&lt;br /&gt;
&lt;br /&gt;
If you execute&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$DB-&amp;gt;set_debug(true)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
then $DB will outout the SQL of every query executed, along with timing information. This can be useful when debugging your code. Obviously, all such calls should be removed before code is submitted for integration.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[SQL coding style]]&lt;br /&gt;
* [[Core APIs]]&lt;br /&gt;
* [[DML exceptions|DML exceptions]]: New DML code is throwing exceptions instead of returning false if anything goes wrong&lt;br /&gt;
* [[DML drivers|DML drivers]]: Database drivers for new DML layer&lt;br /&gt;
* [[DML functions - pre 2.0|DML functions - pre 2.0]]: &#039;&#039;&#039;(deprecated!)&#039;&#039;&#039; For information valid before Moodle 2.0.&lt;br /&gt;
* [[DDL functions|DDL functions]]: Where all the functions used to handle DB objects ([[wikipedia:Data_Definition_Language|DDL]]) are defined.&lt;br /&gt;
* [[DB layer 2.0 examples|DB layer 2.0 examples]]: To see some code examples using various DML functions.&lt;br /&gt;
* [[DB layer 2.0 migration docs|DB layer 2.0 migration docs]]: Information about how to modify your code to work with the new Moodle 2.0 DB layer.&lt;br /&gt;
* [[DTL functions|DTL functions]]: Exporting, importing and moving of data stored in SQL databases&lt;br /&gt;
&lt;br /&gt;
[[Category:DB]]&lt;br /&gt;
[[Category:XMLDB]]&lt;br /&gt;
[[Category:API]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Data_manipulation_API&amp;diff=42294</id>
		<title>Data manipulation API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Data_manipulation_API&amp;diff=42294"/>
		<updated>2013-09-09T14:13:59Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* SQL compatibility functions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle_2.0}}This page describes the functions available to access data in the Moodle database. You should &#039;&#039;&#039;exclusively&#039;&#039;&#039; use these functions in order to retrieve or modify database content because these functions provide a high level of abstraction and guarantee that your database manipulation will work against different RDBMSes.&lt;br /&gt;
&lt;br /&gt;
Where possible, tricks and examples will be documented here in order to make developers&#039; lives a bit easier. Of course, feel free to clarify, complete and add more information to  this documentation. It will be welcome, absolutely!&lt;br /&gt;
&lt;br /&gt;
== Main info ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important note:&#039;&#039;&#039; All the functions shown on this page are for use in &#039;&#039;&#039;Moodle 2.0 upwards&#039;&#039;&#039;, where we changed the [[DB layer 2.0|DB layer]] to support some new features. If you need information for previous Moodle version, take a look to the [[DML functions - pre 2.0|DML functions - pre 2.0]] page. For a detailed reference of changes, see the [[DB layer 2.0 migration docs|migration docs]].&lt;br /&gt;
&lt;br /&gt;
* All the function calls on this page are public methods of the $DB global object, so you&#039;ll need to &amp;quot;import&amp;quot; it within your functions (not needed in global scripts) with one simple:&lt;br /&gt;
&amp;lt;code php&amp;gt;global $DB;&amp;lt;/code&amp;gt;&lt;br /&gt;
* The $DB global object is an instance of the moodle_database class, which is defined in [http://git.moodle.org/gw?p=moodle.git;a=blob;f=lib/dml/moodle_database.php;h=2a6676c84e7c77b0534f18a13ba584f58a8ed024;hb=refs/heads/master moodle_database.php]&lt;br /&gt;
* All the $table parameters in the functions are meant to be the table name &#039;&#039;without&#039;&#039; prefixes.&lt;br /&gt;
&amp;lt;code php&amp;gt;$user = $DB-&amp;gt;get_record(&#039;user&#039;, array(&#039;id&#039;=&amp;gt;&#039;1&#039;));&amp;lt;/code&amp;gt;&lt;br /&gt;
* When using the xxx_sql() functions, table names must be enclosed between curly braces.&lt;br /&gt;
&amp;lt;code php&amp;gt;$user = $DB-&amp;gt;get_record_sql(&#039;SELECT * FROM {user} WHERE id = ?&#039;, array(1));&amp;lt;/code&amp;gt;&lt;br /&gt;
* All the $conditions parameters in the functions are arrays of fieldname=&amp;gt;fieldvalue elements.&lt;br /&gt;
&amp;lt;code php&amp;gt;$user = $DB-&amp;gt;get_record(&#039;user&#039;, array(&#039;firstname&#039;=&amp;gt;&#039;Martin&#039;, &#039;lastname&#039;=&amp;gt;&#039;Dougiamas&#039;));&amp;lt;/code&amp;gt;&lt;br /&gt;
* All the $params parameters in the functions are arrays of values used to fill placeholders in SQL statements. Both the question mark and named placeholders can be used. Note that named params &#039;&#039;&#039;must be unique&#039;&#039;&#039; even if the value passed is the same.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/// Question mark placeholders:&lt;br /&gt;
   $DB-&amp;gt;get_record_sql(&#039;SELECT * FROM {user} WHERE firstname = ? AND lastname = ?&#039;, &lt;br /&gt;
                       array(&#039;Martin&#039;, &#039;Dougiamas&#039;));&lt;br /&gt;
&lt;br /&gt;
/// Named placeholders:&lt;br /&gt;
   $DB-&amp;gt;get_record_sql(&#039;SELECT * FROM {user} WHERE firstname = :firstname AND lastname = :lastname&#039;,&lt;br /&gt;
                       array(&#039;firstname&#039;=&amp;gt;&#039;Martin&#039;, &#039;lastname&#039;=&amp;gt;&#039;Dougiamas&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The functions ==&lt;br /&gt;
&lt;br /&gt;
===Getting a single record===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_record($table, array $conditions, $fields=&#039;*&#039;, $strictness=IGNORE_MISSING) &lt;br /&gt;
  /// Get a single database record as an object where all the given conditions met.&lt;br /&gt;
  /// @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;&lt;br /&gt;
  ///                        IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended);&lt;br /&gt;
  ///                        MUST_EXIST means throw exception if no record or multiple records found&lt;br /&gt;
o $DB-&amp;gt;get_record_select($table, $select, array $params=null, $fields=&#039;*&#039;, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single database record as an object which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_record_sql($sql, array $params=null, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single database record as an object using a SQL statement.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Getting an hashed array of records===&lt;br /&gt;
Each of the following methods return an array of objects. The array is indexed by the first column of the fields returned by the query. Thus to assure consistent data, it appears to be best practice to ensure that your query include an &amp;quot;id column&amp;quot; as the first field. (When developing custom tables, be sure to make id your first column for this reason!)&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_records($table, array $conditions=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get a number of records as an array of objects where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;get_records_select($table, $select, array $params=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get a number of records as an array of objects which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0)&lt;br /&gt;
  /// Get a number of records as an array of objects using a SQL statement.&lt;br /&gt;
o $DB-&amp;gt;get_records_list($table, $field, array $values, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=&#039;&#039;, $limitnum=&#039;&#039;) &lt;br /&gt;
  /// Get a number of records as an array of objects where one field match one list of values.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Getting data as key/value pairs in an associative array===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_records_menu($table, array $conditions=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get the first two columns from a number of records as an associative array where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;get_records_select_menu($table, $select, array $params=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0)&lt;br /&gt;
  /// Get the first two columns from a number of records as an associative array which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_records_sql_menu($sql, array $params=null, $limitfrom=0, $limitnum=0)&lt;br /&gt;
  /// Get the first two columns from a number of records as an associative array using a SQL statement.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seeing how many records match a given criterion===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;count_records($table, array $conditions=null) &lt;br /&gt;
  /// Count the records in a table where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;count_records_select($table, $select, array $params=null, $countitem=&amp;quot;COUNT(&#039;x&#039;)&amp;quot;) &lt;br /&gt;
  /// Count the records in a table which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;count_records_sql($sql, array $params=null) &lt;br /&gt;
  /// Get the result of an SQL SELECT COUNT(...) query.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Seeing if one record exists===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;record_exists($table, array $conditions=null) &lt;br /&gt;
  /// Test whether a record exists in a table where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;record_exists_select($table, $select, array $params=null) &lt;br /&gt;
  /// Test whether any records exists in a table which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;record_exists_sql($sql, array $params=null) &lt;br /&gt;
  /// Test whether a SQL SELECT statement returns any records.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Examples====&lt;br /&gt;
=====moodle_database::get_records()=====&lt;br /&gt;
Get a number of records as an array of objects where all the given conditions met.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records where foo = bar&lt;br /&gt;
$result = $DB-&amp;gt;get_records($table,array(&#039;foo&#039;=&amp;gt;&#039;bar&#039;));&lt;br /&gt;
&lt;br /&gt;
///Get all records where foo = bar and jon = doe&lt;br /&gt;
$result = $DB-&amp;gt;get_records($table,array(&#039;foo&#039; =&amp;gt; &#039;bar&#039; , &#039;jon&#039; =&amp;gt; &#039;doe&#039;));&lt;br /&gt;
&lt;br /&gt;
///Get all records where foo = bar, but only return the fields foo,bar,jon,doe&lt;br /&gt;
$result = $DB-&amp;gt;get_records($table,array(&#039;foo&#039;=&amp;gt;&#039;bar&#039;),null,&#039;foo,bar,jon,doe&#039;);&lt;br /&gt;
///The previous example would cause data issues unless the &#039;foo&#039; field happens to have unique values.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_select()=====&lt;br /&gt;
Get a number of records as an array of objects which match a particular WHERE clause. Note that the array keys will be the id of the object so you must not rely on the first item having a key of 0.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records where jon = &#039;doe&#039; and bob is not = &#039;tom&#039;&lt;br /&gt;
///The &#039;select&#039; parameter is (if not empty) is dropped directly into the WHERE clause without alteration.&lt;br /&gt;
$table = &#039;foo&#039;;&lt;br /&gt;
$select = &amp;quot;jon = &#039;doe&#039; AND bob &amp;lt;&amp;gt; &#039;tom&#039;&amp;quot;; //is put into the where clause&lt;br /&gt;
$result = $DB-&amp;gt;get_records_select($table,$select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_sql()=====&lt;br /&gt;
Get a number of records as an array of objects using a SQL statement. Defined as an abstract function in moodle_database, this method is implemented per database type.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records from &#039;table&#039; where foo = bar&lt;br /&gt;
$result = $DB-&amp;gt;get_records_sql(&#039;SELECT * FROM {table} WHERE foo = ?&#039;, array(&#039;bar&#039;));&lt;br /&gt;
&lt;br /&gt;
///Get all records from &#039;table&#039; where foo = &#039;bar&#039; and bob = &#039;tom&#039;&lt;br /&gt;
///This is somewhat similar to how Drupal makes its queries&lt;br /&gt;
$result = $DB-&amp;gt;get_records_sql(&#039;SELECT * FROM {table} WHERE foo = ? AND bob = ?&#039;, array( &#039;bar&#039; , &#039;tom&#039; ));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_list()=====&lt;br /&gt;
Get a number of records as an array of objects where one field match one list of values.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records where the values(&#039;bar&#039;, &#039;elephant&#039;, &#039;moodle&#039;) are found in the field &#039;foo&#039;&lt;br /&gt;
$result = $DB-&amp;gt;get_records_list($table, &#039;foo&#039;, array( &#039;bar&#039;, &#039;elephant&#039;, &#039;moodle&#039;));&lt;br /&gt;
&lt;br /&gt;
///Get all records where the values(&#039;bar&#039;, &#039;elephant&#039;, &#039;moodle&#039;) are found in the field &#039;foo&#039;&lt;br /&gt;
///Only returning the fields &#039;id&#039;, &#039;test&#039; and &#039;taco&#039;&lt;br /&gt;
$result = $DB-&amp;gt;get_records_list($table, &#039;foo&#039;, array( &#039;bar&#039;, &#039;elephant&#039;, &#039;moodle&#039;), null, &#039;id,test,taco&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_menu()=====&lt;br /&gt;
Get the first two columns from a number of records as an associative array where all the given conditions met. &lt;br /&gt;
You can choose the two fields or leave the parameter blank and the method will return the first two columns of the table.&lt;br /&gt;
Returns an associative array. &lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records from table &#039;foo&#039; where column &#039;foo&#039; is equal to the value &#039;bar&#039;&lt;br /&gt;
$table = &#039;foo&#039;; ///name of table&lt;br /&gt;
$conditions = array(&#039;foo&#039;=&amp;gt;&#039;bar&#039;); ///the name of the field (key) and the desired value&lt;br /&gt;
&lt;br /&gt;
$result = $DB-&amp;gt;get_records_menu($table,$conditions));&lt;br /&gt;
&lt;br /&gt;
///Get all records from table &#039;foo&#039; where column &#039;foo&#039; is equal to the value &#039;bar&#039;&lt;br /&gt;
///Returning the values from the columns &#039;id&#039; and &#039;tacos&#039;&lt;br /&gt;
$table = &#039;foo&#039;; ///name of table&lt;br /&gt;
$conditions = array(&#039;foo&#039;=&amp;gt;&#039;bar&#039;); ///the name of the field (key) and the desired value&lt;br /&gt;
$sort = &#039;id&#039;; //field or fields you want to sort the result by&lt;br /&gt;
$fields = &#039;id, tacos&#039;; ///list of fields to return&lt;br /&gt;
&lt;br /&gt;
$result = $DB-&amp;gt;get_records_menu($table,$conditions,$sort,$fields));  //If you do not specify $fields, the first two columns of the table will be returned&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
The result of this last example will look something like:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/// The value of the id field  is 909 and the value of the &#039;tacos&#039; column is 6&lt;br /&gt;
array(1) { [909]=6 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_select_menu()=====&lt;br /&gt;
Get the first two columns from a number of records as an associative array which match a particular WHERE clause.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records where jon = &#039;doe&#039; and bob is not = &#039;tom&#039;&lt;br /&gt;
///The &#039;select&#039; parameter is (if not empty) is dropped directly into the WHERE clause without alteration.&lt;br /&gt;
$table = &#039;foo&#039;;&lt;br /&gt;
$select = &#039;jon = &amp;quot;doe&amp;quot; AND bob != &amp;quot;tom&amp;quot; &#039;; //is put into the where clause&lt;br /&gt;
$result = $DB-&amp;gt;get_records_select_menu($table,$select);&lt;br /&gt;
&lt;br /&gt;
$table = &#039;foo&#039;;&lt;br /&gt;
$select = &#039;jon = &amp;quot;doe&amp;quot; AND bob != &amp;quot;tom&amp;quot; &#039;; //is put into the where clause&lt;br /&gt;
$params = null;&lt;br /&gt;
$fields = &#039;id, tacos&#039;;//return these fields&lt;br /&gt;
$sort = &#039;id&#039;; //field or fields you want to sort the result by&lt;br /&gt;
$result = $DB-&amp;gt;get_records_select_menu($table,$select,$params,$sort,$fields);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result of this last example will look something like:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/// The value of the id field  is 909 and the value of the &#039;tacos&#039; column is 6&lt;br /&gt;
array(1) { [909]=6 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====moodle_database::get_records_sql_menu()=====&lt;br /&gt;
Get the first two columns from a number of records as an associative array using a SQL statement.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
///Get all records from table foo where bar = 6&lt;br /&gt;
$sql = &#039;SELECT * FROM foo WHERE bar = ?&#039;;&lt;br /&gt;
$params = array(6);&lt;br /&gt;
&lt;br /&gt;
$result = $DB-&amp;gt;get_records_sql_menu($sql,$params);&lt;br /&gt;
&lt;br /&gt;
///Get all records from table foo where bar = 6&lt;br /&gt;
$sql = &#039;SELECT id,tacos FROM foo WHERE bar = ?&#039;;&lt;br /&gt;
$params = array(6);&lt;br /&gt;
&lt;br /&gt;
$result = $DB-&amp;gt;get_records_sql_menu($sql,$params);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result of this last example will look something like:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/// The value of the id field  is 909 and the value of the &#039;tacos&#039; column is 6&lt;br /&gt;
array(1) { [909]=6 } &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Getting a particular field value from one record===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_field($table, $return, array $conditions, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single field value from a table record where all the given conditions met.&lt;br /&gt;
  /// @param int $strictness&lt;br /&gt;
  ///   IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;&lt;br /&gt;
  ///   IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended);&lt;br /&gt;
  ///   MUST_EXIST means throw exception if no record or multiple records found&lt;br /&gt;
o $DB-&amp;gt;get_field_select($table, $return, $select, array $params=null, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single field value from a table record which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_field_sql($sql, array $params=null, $strictness=IGNORE_MISSING)&lt;br /&gt;
  /// Get a single field value (first field) using a SQL statement.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Getting a particular field value from various records===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_fieldset_select($table, $return, $select, array $params=null)&lt;br /&gt;
  /// Selects records and return values of chosen field as an array which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_fieldset_sql($sql, array $params=null)&lt;br /&gt;
  /// Selects records and return values (first field) as an array using a SQL statement.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setting a particular field in the database===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;set_field($table, $newfield, $newvalue, array $conditions=null)&lt;br /&gt;
  /// Set a single field in every table record where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;set_field_select($table, $newfield, $newvalue, $select, array $params=null)&lt;br /&gt;
  /// Set a single field in every table record which match a particular WHERE clause.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Deleting Records===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;delete_records($table, array $conditions=null) &lt;br /&gt;
  /// Delete the records from a table where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;delete_records_select($table, $select, array $params=null)&lt;br /&gt;
  /// Delete one or more records from a table which match a particular WHERE clause.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Inserting Records===&lt;br /&gt;
The method to insert records is called aptly enough, insert_record(). The method accepts 4 parameters, but the fourth, &amp;quot;bulk&amp;quot;, in most implementations is unused.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;insert_record($table, $dataobject, $returnid=true, $bulk=false) &lt;br /&gt;
  /// Insert a record into a table and return the &amp;quot;id&amp;quot; field if required.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
====Example(s)====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$record = new stdClass();&lt;br /&gt;
$record-&amp;gt;name         = &#039;overview&#039;;&lt;br /&gt;
$record-&amp;gt;displayorder = &#039;10000&#039;;&lt;br /&gt;
$DB-&amp;gt;insert_record(&#039;quiz_report&#039;, $record, false);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$record = new stdClass();&lt;br /&gt;
$record-&amp;gt;name         = &#039;overview&#039;;&lt;br /&gt;
$record-&amp;gt;displayorder = &#039;10000&#039;;&lt;br /&gt;
$lastinsertid = $DB-&amp;gt;insert_record(&#039;quiz_report&#039;, $record);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Updating Records===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;update_record($table, $dataobject, $bulk=false)&lt;br /&gt;
  /// Update a record in a table.&lt;br /&gt;
  /// &lt;br /&gt;
  /// $dataobject is an object containing needed data&lt;br /&gt;
  /// Relies on $dataobject having a variable &amp;quot;id&amp;quot; to&lt;br /&gt;
  /// specify the record to update&lt;br /&gt;
  /// &lt;br /&gt;
  /// @param string $table The database table to be checked against.&lt;br /&gt;
  /// @param object $dataobject An object with contents equal to fieldname=&amp;gt;fieldvalue.&lt;br /&gt;
  ///        Must have an entry for &#039;id&#039; to map to the table specified.&lt;br /&gt;
  /// @param bool $bulk true means repeated updates expected&lt;br /&gt;
  /// @return bool true&lt;br /&gt;
  /// @throws dml_exception if an error occurs.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using Recordsets===&lt;br /&gt;
&lt;br /&gt;
Where the number of records to be retrieved from DB is high, the &#039;&#039;&#039;get_records_xxx()&#039;&#039;&#039; functions above are far from optimal, because they load all the records in memory at the same time. Under those circumstances, it is highly recommended to use these &#039;&#039;&#039;get_recordset_xxx()&#039;&#039;&#039; functions instead, which use one nice mechanism to iterate over all the target records and save a lot of memory.&lt;br /&gt;
&lt;br /&gt;
Only one thing is &#039;&#039;&#039;absolutely important&#039;&#039;&#039;: Don&#039;t forget to close the recordsets after using them! (This will free up a lot of resources in the RDBMS).&lt;br /&gt;
&lt;br /&gt;
Here is the general way to iterate over records using the &#039;&#039;&#039;get_recordset_xxx()&#039;&#039;&#039; functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$rs = $DB-&amp;gt;get_recordset(....) {&lt;br /&gt;
foreach ($rs as $record) {&lt;br /&gt;
    // Do whatever you want with this record&lt;br /&gt;
}&lt;br /&gt;
$rs-&amp;gt;close(); // Don&#039;t forget to close the recordset!&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And this is the list of available functions (100% paired with the get_records_xxx() above):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;get_recordset($table, array $conditions=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get a number of records as a moodle_recordset where all the given conditions met.&lt;br /&gt;
o $DB-&amp;gt;get_recordset_select($table, $select, array $params=null, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=0, $limitnum=0) &lt;br /&gt;
  /// Get a number of records as a moodle_recordset which match a particular WHERE clause.&lt;br /&gt;
o $DB-&amp;gt;get_recordset_sql($sql, array $params=null, $limitfrom=0, $limitnum=0);&lt;br /&gt;
  /// Get a number of records as a moodle_recordset using a SQL statement.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;get_recordset_list($table, $field=&#039;&#039;, $values=&#039;&#039;, $sort=&#039;&#039;, $fields=&#039;*&#039;, $limitfrom=&#039;&#039;, $limitnum=&#039;&#039;) &lt;br /&gt;
  /// Get a number of records as a moodle_recordset where one field matches one list of values.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike get_record functions, you cannot use &amp;lt;tt&amp;gt;$rs == true&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;!empty($rs)&amp;lt;/tt&amp;gt; to determine if any records were found.&lt;br /&gt;
Recordsets implement the standard PHP Iterator interface (http://uk.php.net/manual/en/class.iterator.php)&lt;br /&gt;
&lt;br /&gt;
So,&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if ($rs-&amp;gt;valid()) {&lt;br /&gt;
    // The recordset contains records.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Delegated transactions===&lt;br /&gt;
&lt;br /&gt;
* Please note some databases do not support transactions (such as the MyISAM MySQL database engine), however all server administrators are strongly encouraged to migrate to databases that support transactions (such as the InnoDB MySQL database engine).&lt;br /&gt;
* Previous versions supported only one level of transaction. Since Moodle 2.0, the DML layer emulates delegated transactions that allow nesting of transactions.&lt;br /&gt;
* Transactions should not be used much in Moodle core; they are intended for various plugins such as web services, enrol and auth plugins.&lt;br /&gt;
* Some subsystems (such as messaging) do not support transactions because is it is not possible to rollback in external systems.&lt;br /&gt;
&lt;br /&gt;
A transaction is started by:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$transaction = $DB-&amp;gt;start_delegated_transaction();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and finished by:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$transaction-&amp;gt;allow_commit();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usually a transaction is rolled back when an exception is thrown. &amp;lt;code&amp;gt;$transaction-&amp;gt;rollback($ex);&amp;lt;/code&amp;gt; must be used very carefully because it might break compatibility with databases that do not support transactions. Transactions cannot be used as part of expected code flow; they can be used only as an emergency protection of data consistency.&lt;br /&gt;
&lt;br /&gt;
See more details in [[DB layer 2.0 delegated transactions]] or MDL-20625.&lt;br /&gt;
&lt;br /&gt;
====Example(s)====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
global $DB;&lt;br /&gt;
try {&lt;br /&gt;
     $transaction = $DB-&amp;gt;start_delegated_transaction();&lt;br /&gt;
     // Insert a record&lt;br /&gt;
     $DB-&amp;gt;insert(&#039;foo&#039;, $object);&lt;br /&gt;
     $DB-&amp;gt;insert(&#039;bar&#039;, $otherobject);&lt;br /&gt;
&lt;br /&gt;
     // Assuming the both inserts work, we get to the following line.&lt;br /&gt;
     $transaction-&amp;gt;allow_commit();&lt;br /&gt;
} catch(Exception $e) {&lt;br /&gt;
     $transaction-&amp;gt;rollback($e);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SQL compatibility functions===&lt;br /&gt;
&lt;br /&gt;
In order have real cross-db compatibility, there are some helper functions used to build SQL fragments based on the DB Moodle is running. Using them we&#039;ll avoid conditional queries here and there and have those &amp;quot;incompatibilities&amp;quot; fixed once and for ever.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
o $DB-&amp;gt;sql_bitand($int1, $int2) &lt;br /&gt;
  /// Returns the SQL text to be used in order to perform one bitwise AND &lt;br /&gt;
  /// operation between 2 integers.&lt;br /&gt;
o $DB-&amp;gt;sql_bitnot($int1) &lt;br /&gt;
  /// Returns the SQL text to be used in order to perform one bitwise NOT &lt;br /&gt;
  /// operation with 1 integer.&lt;br /&gt;
o $DB-&amp;gt;sql_bitor($int1, $int2)&lt;br /&gt;
  /// Returns the SQL text to be used in order to perform one bitwise OR &lt;br /&gt;
  /// operation between 2 integers.&lt;br /&gt;
o $DB-&amp;gt;sql_bitxor($int1, $int2) &lt;br /&gt;
  /// Returns the SQL text to be used in order to perform one bitwise XOR &lt;br /&gt;
  /// operation between 2 integers.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_null_from_clause()&lt;br /&gt;
  /// Returns the FROM clause required by some DBs in all SELECT statements.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_ceil($fieldname)&lt;br /&gt;
  /// Returns the correct CEIL expression applied to fieldname.&lt;br /&gt;
o $DB-&amp;gt;sql_like($fieldname, $param, $casesensitive = true, $accentsensitive = true, $notlike = false, $escapechar = &#039; \\ &#039;)&lt;br /&gt;
  /// Returns the proper SQL to do LIKE. For example:&lt;br /&gt;
  $DB-&amp;gt;get_records_sql(&#039;SELECT ...  WHERE &#039;.$DB-&amp;gt;sql_like(&#039;idnumber&#039;, &#039;:idnum&#039;).&#039; ... &#039;, array( &#039;idnum&#039; =&amp;gt; &#039;foo&#039;));&lt;br /&gt;
  /// Use $DB-&amp;gt;sql_like_escape(...) when its user input from a form.&lt;br /&gt;
&lt;br /&gt;
o $DB-&amp;gt;sql_length($fieldname)&lt;br /&gt;
  /// Returns the SQL text to be used to calculate the length in characters of one expression.&lt;br /&gt;
o $DB-&amp;gt;sql_modulo($int1, $int2)&lt;br /&gt;
  /// Returns the SQL text to be used in order to calculate module - remainder after division&lt;br /&gt;
o $DB-&amp;gt;sql_position($needle, $haystack)&lt;br /&gt;
  /// Returns the SQL for returning searching one string for the location of another.&lt;br /&gt;
  /// Note: If using placeholders BOTH in $needle and $haystack, they MUST be named placeholders.&lt;br /&gt;
o $DB-&amp;gt;sql_substr($expr, $start, $length=false)&lt;br /&gt;
  /// Returns the proper substr() SQL text used to extract substrings from DB.&lt;br /&gt;
  /// Note: This fuction has changed in Moodle 2.0 and now at least 2 params are mandatory.&lt;br /&gt;
  /// Note: Now it returns the whole SQL text to be used instead of only the function name.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_cast_char2int($fieldname, $text=false)&lt;br /&gt;
  /// Returns the SQL to be used in order to CAST one CHAR column to INTEGER.&lt;br /&gt;
o $DB-&amp;gt;sql_cast_char2real($fieldname, $text=false)&lt;br /&gt;
  /// Returns the SQL to be used in order to CAST one CHAR column to REAL number.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_compare_text($fieldname, $numchars=32) &lt;br /&gt;
  /// Returns the SQL text to be used to compare one TEXT (clob) column.&lt;br /&gt;
  /// with one VARCHAR column.&lt;br /&gt;
o $DB-&amp;gt;sql_order_by_text($fieldname, $numchars=32)&lt;br /&gt;
  /// Returns the SQL text to be used to order by one TEXT (clob) column.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_concat()&lt;br /&gt;
  /// Returns the proper SQL to do CONCAT between the elements passed.&lt;br /&gt;
o $DB-&amp;gt;sql_concat_join($separator=&amp;quot;&#039; &#039;&amp;quot;, $elements=array())&lt;br /&gt;
  /// Returns the proper SQL to do CONCAT between the elements passed using one separator.&lt;br /&gt;
o $DB-&amp;gt;sql_fullname($first=&#039;firstname&#039;, $last=&#039;lastname&#039;)&lt;br /&gt;
  /// Returns the proper SQL to concatenate $firstname and $lastname.&lt;br /&gt;
 &lt;br /&gt;
o $DB-&amp;gt;sql_isempty($tablename, $fieldname, $nullablefield, $textfield)&lt;br /&gt;
  /// Returns the proper SQL to know if one field is empty.&lt;br /&gt;
o $DB-&amp;gt;sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield)&lt;br /&gt;
  /// Returns the proper SQL to know if one field is not empty.&lt;br /&gt;
o $DB-&amp;gt;sql_empty()&lt;br /&gt;
  /// Returns the empty string char used by every supported DB.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Debug fuctions===&lt;br /&gt;
&lt;br /&gt;
If you execute&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$DB-&amp;gt;set_debug(true)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
then $DB will outout the SQL of every query executed, along with timing information. This can be useful when debugging your code. Obviously, all such calls should be removed before code is submitted for integration.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[SQL coding style]]&lt;br /&gt;
* [[Core APIs]]&lt;br /&gt;
* [[DML exceptions|DML exceptions]]: New DML code is throwing exceptions instead of returning false if anything goes wrong&lt;br /&gt;
* [[DML drivers|DML drivers]]: Database drivers for new DML layer&lt;br /&gt;
* [[DML functions - pre 2.0|DML functions - pre 2.0]]: &#039;&#039;&#039;(deprecated!)&#039;&#039;&#039; For information valid before Moodle 2.0.&lt;br /&gt;
* [[DDL functions|DDL functions]]: Where all the functions used to handle DB objects ([[wikipedia:Data_Definition_Language|DDL]]) are defined.&lt;br /&gt;
* [[DB layer 2.0 examples|DB layer 2.0 examples]]: To see some code examples using various DML functions.&lt;br /&gt;
* [[DB layer 2.0 migration docs|DB layer 2.0 migration docs]]: Information about how to modify your code to work with the new Moodle 2.0 DB layer.&lt;br /&gt;
* [[DTL functions|DTL functions]]: Exporting, importing and moving of data stored in SQL databases&lt;br /&gt;
&lt;br /&gt;
[[Category:DB]]&lt;br /&gt;
[[Category:XMLDB]]&lt;br /&gt;
[[Category:API]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Setting_up_Netbeans&amp;diff=42222</id>
		<title>Setting up Netbeans</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Setting_up_Netbeans&amp;diff=42222"/>
		<updated>2013-08-27T08:34:47Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* Needs updating */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.netbeans.org/features/php/index.html NetBeans] has got a good PHP support. You find a host of information on the website (tutorials, developer blog, screen casts, etc.).&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* CVS integration: see all changes, lines deletion, diff in real time, show annotations, diff history...&lt;br /&gt;
* Ctrl+Click: Go to declaration&lt;br /&gt;
* Export/Import Diff Patch&lt;br /&gt;
* Easy navigation&lt;br /&gt;
* List of functions&lt;br /&gt;
* Code completion&lt;br /&gt;
* Instant rename&lt;br /&gt;
* HTML, CSS, JavaScript support&lt;br /&gt;
* MySQL manager&lt;br /&gt;
* Quick Search&lt;br /&gt;
* Very few bugs&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
* Download the latest stable version from http://netbeans.org. Get the bundle that contains only PHP support.&lt;br /&gt;
* Install and run it.&lt;br /&gt;
&lt;br /&gt;
== Set up for Moodle development ==&lt;br /&gt;
&lt;br /&gt;
* Checkout your Moodle project with a &#039;&#039;&#039;CVS client&#039;&#039;&#039; - see [[:en:CVS for Administrators]] or [[CVS for developers|CVS for Developers]].&lt;br /&gt;
&lt;br /&gt;
* Open File &amp;gt; New Project &amp;gt; PHP &amp;gt; PHP Application &amp;gt; Next &lt;br /&gt;
: You&#039;re going to set the project now. &#039;&#039;Name&#039;&#039;, &#039;&#039;Location&#039;&#039; and &#039;&#039;Folder&#039;&#039; are used by NetBeans and are not related to the source code. So you can choose whatever you like, except your source folder. &#039;&#039;Sources&#039;&#039; has to be your checked out Moodle branch/head folder. The rest is clear enough. Don&#039;t forget to choose UTF-8 for &#039;&#039;Default Encoding&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Example:&lt;br /&gt;
&lt;br /&gt;
 Project Name:        Moodle 1.9 Stable&lt;br /&gt;
 Project Location:    C:\Users\jerome\Documents\NetBeansProjects&lt;br /&gt;
 Project Folder:      C:\Users\jerome\Documents\NetBeansProjects\Moodle 1.9 Stable&lt;br /&gt;
 Project Sources:     C:\Users\jerome\Projects\branch19_STABLE\moodle&lt;br /&gt;
 Project URL:         http://localhost/moodle19/&lt;br /&gt;
 Index File:          index.php&lt;br /&gt;
 Create:              unchecked&lt;br /&gt;
 Default Encoding:    UTF-8&lt;br /&gt;
 Set as Main Project: unchecked&lt;br /&gt;
&lt;br /&gt;
* Click on Finish.&lt;br /&gt;
&lt;br /&gt;
* Start coding!&lt;br /&gt;
&lt;br /&gt;
== CVS with NetBeans ==&lt;br /&gt;
&lt;br /&gt;
NetBeans comes with &#039;&#039;&#039;integrated CVS support&#039;&#039;&#039; which might be the easiest way to check out Moodle.&lt;br /&gt;
&lt;br /&gt;
=== Anonymous checkout ===&lt;br /&gt;
&lt;br /&gt;
# In NetBeans, select Window-&amp;gt;Versioning-&amp;gt;CVS-&amp;gt;Checkout&lt;br /&gt;
# Select Team-&amp;gt;CVS-&amp;gt;Checkout&lt;br /&gt;
# Enter into CVS Root: &#039;&#039;:pserver:anonymous@us.cvs.moodle.org:/cvsroot/moodle&#039;&#039;&lt;br /&gt;
: (Non-US-residents might use one of the other [https://docs.moodle.org/en/CVS_for_Administrators#CVS_Servers Moodle CVS servers] nearer to them.)&lt;br /&gt;
# Click &#039;&#039;Next&#039;&#039;&lt;br /&gt;
# Browse or enter into &#039;&#039;Module:&#039;&#039; moodle&lt;br /&gt;
# Browse or enter into &#039;&#039;Branch:&#039;&#039; MOODLE_19_STABLE&lt;br /&gt;
# Browse or enter into &#039;&#039;Local Folder:&#039;&#039; C:\xampp\htdocs&lt;br /&gt;
# Click &#039;&#039;Finish&#039;&#039; (and wait a few minutes for Moodle to be checked out)&lt;br /&gt;
# When you get the dialog box &amp;quot;Do you want to create an IDE project from the checked-out sources?&amp;quot;, Click &amp;quot;Create Project...&amp;quot;&lt;br /&gt;
# Select PHP Application with Existing Sources, and click Next&lt;br /&gt;
# Browse or enter into &#039;&#039;Sources Folder&#039;&#039; C:\xampp\htdocs\moodle&lt;br /&gt;
# Enter into &#039;&#039;Project Name:&#039;&#039; moodle&lt;br /&gt;
# Keep the other defaults and click next&lt;br /&gt;
# &#039;&#039;Run As:&#039;&#039; should have selected &#039;&#039;Local Web Site (running on local web server)&#039;&#039;&lt;br /&gt;
# Enter into Project URL http://localhost/moodle/&lt;br /&gt;
# Browse or enter into &#039;&#039;Index File:&#039;&#039; index.php&lt;br /&gt;
# Click &#039;&#039;Finish&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Checkout for developers with write access ===&lt;br /&gt;
&lt;br /&gt;
As far as I can tell, there is no way to get NetBeans to work with CVS keys on Mac/Linux via the system SSH binary, so you will need to use the internal SSH and your password (which you can choose to save).&lt;br /&gt;
&lt;br /&gt;
If you wish to use NetBeans CVS and have CVS write access, the procedure is as follows:&lt;br /&gt;
&lt;br /&gt;
====Checkout of main Moodle codebase====&lt;br /&gt;
&lt;br /&gt;
# Follow the above instructions except for point 3&lt;br /&gt;
# At part 3, substitute &#039;&#039;:ext:yourusername&#039;&#039; for the part before the @ and remove the country code from after it, leaving it like this  &#039;&#039;&#039;&#039;&#039;:ext:yourusername&#039;&#039;&#039;@cvs.moodle.org:/cvsroot/moodle&#039;&#039;&lt;br /&gt;
# Follow the rest of the instructions as above&lt;br /&gt;
&lt;br /&gt;
If you wish to work with a plugin, you will need to check this out separately and add it to the Moodle code project you have just made. This because for some reason, the &#039;Do you want to create a project&#039; option fails to show any of the files once you open it if you try to check out the plugin on its own (NetBeans 6.7.1 on a Mac).&lt;br /&gt;
&lt;br /&gt;
====Checkout of contrib code====&lt;br /&gt;
&lt;br /&gt;
# Follow the above steps up to point 3, and again substitute &#039;&#039;:ext:yourusername&#039;&#039; and click &#039;next&#039;. Note that you should not try to specify the full contrib repository path yet.&lt;br /&gt;
# Click &#039;Browse...&#039; next to the &#039;Module&#039; dialogue&lt;br /&gt;
# Find the plugin you wish to work with in CONTRIB&lt;br /&gt;
# Click &#039;OK&#039;&lt;br /&gt;
# Proceed as before up to point 6, then press &#039;Close&#039; when asked if you want to create a new project.&lt;br /&gt;
# Now navigate to the folder you earlier specified in the &#039;local folder&#039; dialogue and you will find a folder marked &#039;contrib&#039;.&lt;br /&gt;
# navigate to the plugin folder, copy that folder, and then navigate to your main Moodle project folder and paste it where it belongs.&lt;br /&gt;
&lt;br /&gt;
Note that the last three points may cause you some grief when attempting to commit changes. CVS doesn&#039;t seem to like having subfolders with different origins. A workaround that operates well for me is to check out the contrib code manually into a folder using the command line as specified in the CVS for developers instructions, then import that code as a new project with existing sources. This allows easy commits and updates, whilst keeping it separate. You can then make a symlink from you main Moodle project to your contrib directory, restart NetBeans (the CVS info and symlink stuff is only refreshed on restart) and then right click the linked directory and choose &#039;Ignore&#039;, then do the same and choose &#039;Exclude from commit&#039;. You can now use the code as if it were part of Moodle, still getting all the code completion stuff, and also do clean updates and commits from the secondary project. [[User:Matt Gibson|Matt Gibson]] 19:53, 6 June 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
===Adding a branch to your plugin===&lt;br /&gt;
Your plugin will likely start with just a HEAD tag and at some point, you will want to branch it so that you can have versions for different Moodles. To add a MOODLE_20_STABLE branch, for example, do the following.&lt;br /&gt;
&lt;br /&gt;
# Checkout as above, but use the MOODLE_20_STABLE branch instead of MOODLE_19_STABLE&lt;br /&gt;
# You will end up with an empty folder, which you copy into place as above.&lt;br /&gt;
# Find the folder in NetBeans, then right click and choose CVS-&amp;gt;Merge changes from branch...&lt;br /&gt;
# Choose to merge from whatever branch has all the current code, using the help link if not sure what to do.&lt;br /&gt;
&lt;br /&gt;
There is a small chance that the Merge link will not be there, in which case, you will have to copy the files into the directory by hand outside netbeans and then check them in. If you do this, make sure you don&#039;t copy over the &#039;CVS&#039; folders that will have been made when you checked out the MOODLE_19_STABLE code.&lt;br /&gt;
&lt;br /&gt;
=== A few warnings ===&lt;br /&gt;
&lt;br /&gt;
Some of these warnings could also apply to other IDEs:&lt;br /&gt;
&lt;br /&gt;
* If you want to delete a file from your computer but not from CVS, delete it from Windows Explorer/Nautilus/Finder. Otherwise your next commit could delete the file from CVS. &amp;lt;br/&amp;gt;In case you have already deleted a wrong file from NetBeans:  with Windows Explorer/Nautilus/Finder, delete all the folder content of this deleted file (including the CVS folder) and update the folder.&lt;br /&gt;
* If you rename files and that other people are working on them, NetBeans could end up to mess up your CVS folder (even though that is quite rare). Then NetBeans CVS will refuse to update your code displaying a no explicit error as &#039;&#039;&#039;Update Failed&#039;&#039;&#039;. In this case, delete the content of the damaged folder with Windows Explorer/Nautilus/Finder. Then update this folder.&lt;br /&gt;
* If you create a patch or a new PHP file with NetBeans on Microsoft Windows, please check that it&#039;s a Unix format file. You may want to use another software to create Unix format patch/php files.&lt;br /&gt;
&lt;br /&gt;
== Git with NetBeans ==&lt;br /&gt;
&lt;br /&gt;
=== NBGit | Git Support for NetBeans ===&lt;br /&gt;
&lt;br /&gt;
&amp;quot;NBGit is a module for the NetBeans IDE that adds support for working with the Git version control system. It uses the JGit library created as part of EGit to interact with Git repositories. Because the module is Java code all the way, it should work better cross-platform modulo platform specific differences, such as file system behavior. It is based on the NetBeans Mercurial module.&amp;quot; &lt;br /&gt;
(http://nbgit.org)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p class=&amp;quot;note orange&amp;quot;&amp;gt;&lt;br /&gt;
Unfortunately, the key word in that quote is &#039;&#039;&#039;should&#039;&#039;&#039;. In reality, because JGit is a rewrite from scratch of the tried-and-tested git core C code, it is still buggy, incomplete and unreliable. Therefore, the NetBeans and Eclipse git plugins are still only beta quality, and pretty sucky. Well, they mostly work for browsing the contents of the repository, but there is a small chance that if you use them for update operations, they will corrupt your repository. Hence, I am still doing git from the command-line.--[[User:Tim Hunt|Tim Hunt]] 11:11, 19 January 2010 (UTC)&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Wiki page needs updating ===&lt;br /&gt;
&lt;br /&gt;
Git is now integrated into Netbeans 7&lt;br /&gt;
https://netbeans.org/kb/70/ide/git.html&lt;br /&gt;
&lt;br /&gt;
== Optimization ==&lt;br /&gt;
&lt;br /&gt;
=== Sun JDK ===&lt;br /&gt;
1. You may want to run NetBeans with the Sun JDK. NetBeans seems to work a bit better with the [http://java.sun.com/javase/downloads/index.jsp Sun JDK]. You&#039;ll have to edit NetBeans config file. Open netbeans/etc/netbeans.conf. Then uncomment and edit: &lt;br /&gt;
&lt;br /&gt;
 netbeans_jdkhome=&amp;quot;your_JDK_path&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. To change the NetBeans look and feel run netbeans in the command line with this parameter:&lt;br /&gt;
 &amp;quot;netbeans&amp;quot;  --laf javax.swing.plaf.metal.MetalLookAndFeel &lt;br /&gt;
&lt;br /&gt;
3. If NetBeans starts to slow down, give it more memory&lt;br /&gt;
 &amp;quot;netbeans&amp;quot; -J-Xmx600m&lt;br /&gt;
See FAQ for more [http://wiki.netbeans.org/FaqSettingHeapSize details on memory optimisation].&lt;br /&gt;
&lt;br /&gt;
=== ScanOnDemand ===&lt;br /&gt;
To prevent NetBeans from scanning the whole code with every start up you can use the following plug-in: http://wiki.netbeans.org/ScanOnDemand&lt;br /&gt;
&lt;br /&gt;
== Coding faster ==&lt;br /&gt;
&lt;br /&gt;
=== Coding standards ===&lt;br /&gt;
&lt;br /&gt;
* There is NB config file available with the [https://github.com/enovation/moodle-utils/tree/master/netbeans-config Moodle coding settings]&lt;br /&gt;
&lt;br /&gt;
=== Keyboard shortcuts ===&lt;br /&gt;
(Note: Some shortcuts might not work for PHP development.)&lt;br /&gt;
* [http://www.phpmag.ru/2009/01/23/extremely-usefull-netbeans-shortcuts/ Extremely Useful NetBeans Shortcuts] &lt;br /&gt;
* [http://netbeanside61.blogspot.com/2008/04/top-10-netbeans-ide-keyboard-shortcuts.html Top 10 NetBeans IDE Keyboard Shortcuts I use the most]&lt;br /&gt;
* [http://wiki.netbeans.org/KeymapProfileFor60 NetBeans IDE 6.x Keyboard Shortcuts Specification]&lt;br /&gt;
&lt;br /&gt;
=== PHPUnit support ===&lt;br /&gt;
See [http://blogs.sun.com/netbeansphp/entry/recent_improvements_in_phpunit_support &amp;quot;Recent improvements in PHPUnit-support&amp;quot;] on how to use PHPUnit with NetBeans.&lt;br /&gt;
&lt;br /&gt;
===JIRA support===&lt;br /&gt;
You can install the optional JIRA module in order to be able to interact with the Moodle Tracker from within NetBeans. This has the advantage of avoiding constantly switching back and forth from the browser and works quite well. Go to &#039;&#039;Tools-&amp;gt;plugins-&amp;gt;available plugins&#039;&#039; and search for JIRA. Once installed, right click &#039;issue trackers&#039; in the &#039;services&#039; pane to make a new tracker instance, then enter your details.&lt;br /&gt;
&lt;br /&gt;
== See also: ==&lt;br /&gt;
Moodle forums &lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=112972 NetBeans 6.5 for moodle/PHP/debugging is a better experience v.s Eclipse]&lt;br /&gt;
&lt;br /&gt;
Online resources&lt;br /&gt;
* [http://www.netbeans.org/kb/trails/php.html NetBeans PHP Learning Trail]&lt;br /&gt;
* [http://wiki.netbeans.org/PHP NetBeans PHP Wiki]&lt;br /&gt;
* Sun&#039;s [http://blogs.sun.com/netbeansphp/ NetBeans PHP Team Blog]&lt;br /&gt;
&lt;br /&gt;
Book&lt;br /&gt;
* [http://www.packtpub.com/netbeans-platform-6-8-developers-guide/book NetBeans Platform 6.8 Developer&#039;s Guide] by Jürgen Petri (March 2010), focus on Java and Swing &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer tools|NetBeans]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Setting_up_Netbeans&amp;diff=42221</id>
		<title>Setting up Netbeans</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Setting_up_Netbeans&amp;diff=42221"/>
		<updated>2013-08-27T08:33:43Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* NBGit | Git Support for NetBeans */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.netbeans.org/features/php/index.html NetBeans] has got a good PHP support. You find a host of information on the website (tutorials, developer blog, screen casts, etc.).&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* CVS integration: see all changes, lines deletion, diff in real time, show annotations, diff history...&lt;br /&gt;
* Ctrl+Click: Go to declaration&lt;br /&gt;
* Export/Import Diff Patch&lt;br /&gt;
* Easy navigation&lt;br /&gt;
* List of functions&lt;br /&gt;
* Code completion&lt;br /&gt;
* Instant rename&lt;br /&gt;
* HTML, CSS, JavaScript support&lt;br /&gt;
* MySQL manager&lt;br /&gt;
* Quick Search&lt;br /&gt;
* Very few bugs&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
* Download the latest stable version from http://netbeans.org. Get the bundle that contains only PHP support.&lt;br /&gt;
* Install and run it.&lt;br /&gt;
&lt;br /&gt;
== Set up for Moodle development ==&lt;br /&gt;
&lt;br /&gt;
* Checkout your Moodle project with a &#039;&#039;&#039;CVS client&#039;&#039;&#039; - see [[:en:CVS for Administrators]] or [[CVS for developers|CVS for Developers]].&lt;br /&gt;
&lt;br /&gt;
* Open File &amp;gt; New Project &amp;gt; PHP &amp;gt; PHP Application &amp;gt; Next &lt;br /&gt;
: You&#039;re going to set the project now. &#039;&#039;Name&#039;&#039;, &#039;&#039;Location&#039;&#039; and &#039;&#039;Folder&#039;&#039; are used by NetBeans and are not related to the source code. So you can choose whatever you like, except your source folder. &#039;&#039;Sources&#039;&#039; has to be your checked out Moodle branch/head folder. The rest is clear enough. Don&#039;t forget to choose UTF-8 for &#039;&#039;Default Encoding&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
: Example:&lt;br /&gt;
&lt;br /&gt;
 Project Name:        Moodle 1.9 Stable&lt;br /&gt;
 Project Location:    C:\Users\jerome\Documents\NetBeansProjects&lt;br /&gt;
 Project Folder:      C:\Users\jerome\Documents\NetBeansProjects\Moodle 1.9 Stable&lt;br /&gt;
 Project Sources:     C:\Users\jerome\Projects\branch19_STABLE\moodle&lt;br /&gt;
 Project URL:         http://localhost/moodle19/&lt;br /&gt;
 Index File:          index.php&lt;br /&gt;
 Create:              unchecked&lt;br /&gt;
 Default Encoding:    UTF-8&lt;br /&gt;
 Set as Main Project: unchecked&lt;br /&gt;
&lt;br /&gt;
* Click on Finish.&lt;br /&gt;
&lt;br /&gt;
* Start coding!&lt;br /&gt;
&lt;br /&gt;
== CVS with NetBeans ==&lt;br /&gt;
&lt;br /&gt;
NetBeans comes with &#039;&#039;&#039;integrated CVS support&#039;&#039;&#039; which might be the easiest way to check out Moodle.&lt;br /&gt;
&lt;br /&gt;
=== Anonymous checkout ===&lt;br /&gt;
&lt;br /&gt;
# In NetBeans, select Window-&amp;gt;Versioning-&amp;gt;CVS-&amp;gt;Checkout&lt;br /&gt;
# Select Team-&amp;gt;CVS-&amp;gt;Checkout&lt;br /&gt;
# Enter into CVS Root: &#039;&#039;:pserver:anonymous@us.cvs.moodle.org:/cvsroot/moodle&#039;&#039;&lt;br /&gt;
: (Non-US-residents might use one of the other [https://docs.moodle.org/en/CVS_for_Administrators#CVS_Servers Moodle CVS servers] nearer to them.)&lt;br /&gt;
# Click &#039;&#039;Next&#039;&#039;&lt;br /&gt;
# Browse or enter into &#039;&#039;Module:&#039;&#039; moodle&lt;br /&gt;
# Browse or enter into &#039;&#039;Branch:&#039;&#039; MOODLE_19_STABLE&lt;br /&gt;
# Browse or enter into &#039;&#039;Local Folder:&#039;&#039; C:\xampp\htdocs&lt;br /&gt;
# Click &#039;&#039;Finish&#039;&#039; (and wait a few minutes for Moodle to be checked out)&lt;br /&gt;
# When you get the dialog box &amp;quot;Do you want to create an IDE project from the checked-out sources?&amp;quot;, Click &amp;quot;Create Project...&amp;quot;&lt;br /&gt;
# Select PHP Application with Existing Sources, and click Next&lt;br /&gt;
# Browse or enter into &#039;&#039;Sources Folder&#039;&#039; C:\xampp\htdocs\moodle&lt;br /&gt;
# Enter into &#039;&#039;Project Name:&#039;&#039; moodle&lt;br /&gt;
# Keep the other defaults and click next&lt;br /&gt;
# &#039;&#039;Run As:&#039;&#039; should have selected &#039;&#039;Local Web Site (running on local web server)&#039;&#039;&lt;br /&gt;
# Enter into Project URL http://localhost/moodle/&lt;br /&gt;
# Browse or enter into &#039;&#039;Index File:&#039;&#039; index.php&lt;br /&gt;
# Click &#039;&#039;Finish&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Checkout for developers with write access ===&lt;br /&gt;
&lt;br /&gt;
As far as I can tell, there is no way to get NetBeans to work with CVS keys on Mac/Linux via the system SSH binary, so you will need to use the internal SSH and your password (which you can choose to save).&lt;br /&gt;
&lt;br /&gt;
If you wish to use NetBeans CVS and have CVS write access, the procedure is as follows:&lt;br /&gt;
&lt;br /&gt;
====Checkout of main Moodle codebase====&lt;br /&gt;
&lt;br /&gt;
# Follow the above instructions except for point 3&lt;br /&gt;
# At part 3, substitute &#039;&#039;:ext:yourusername&#039;&#039; for the part before the @ and remove the country code from after it, leaving it like this  &#039;&#039;&#039;&#039;&#039;:ext:yourusername&#039;&#039;&#039;@cvs.moodle.org:/cvsroot/moodle&#039;&#039;&lt;br /&gt;
# Follow the rest of the instructions as above&lt;br /&gt;
&lt;br /&gt;
If you wish to work with a plugin, you will need to check this out separately and add it to the Moodle code project you have just made. This because for some reason, the &#039;Do you want to create a project&#039; option fails to show any of the files once you open it if you try to check out the plugin on its own (NetBeans 6.7.1 on a Mac).&lt;br /&gt;
&lt;br /&gt;
====Checkout of contrib code====&lt;br /&gt;
&lt;br /&gt;
# Follow the above steps up to point 3, and again substitute &#039;&#039;:ext:yourusername&#039;&#039; and click &#039;next&#039;. Note that you should not try to specify the full contrib repository path yet.&lt;br /&gt;
# Click &#039;Browse...&#039; next to the &#039;Module&#039; dialogue&lt;br /&gt;
# Find the plugin you wish to work with in CONTRIB&lt;br /&gt;
# Click &#039;OK&#039;&lt;br /&gt;
# Proceed as before up to point 6, then press &#039;Close&#039; when asked if you want to create a new project.&lt;br /&gt;
# Now navigate to the folder you earlier specified in the &#039;local folder&#039; dialogue and you will find a folder marked &#039;contrib&#039;.&lt;br /&gt;
# navigate to the plugin folder, copy that folder, and then navigate to your main Moodle project folder and paste it where it belongs.&lt;br /&gt;
&lt;br /&gt;
Note that the last three points may cause you some grief when attempting to commit changes. CVS doesn&#039;t seem to like having subfolders with different origins. A workaround that operates well for me is to check out the contrib code manually into a folder using the command line as specified in the CVS for developers instructions, then import that code as a new project with existing sources. This allows easy commits and updates, whilst keeping it separate. You can then make a symlink from you main Moodle project to your contrib directory, restart NetBeans (the CVS info and symlink stuff is only refreshed on restart) and then right click the linked directory and choose &#039;Ignore&#039;, then do the same and choose &#039;Exclude from commit&#039;. You can now use the code as if it were part of Moodle, still getting all the code completion stuff, and also do clean updates and commits from the secondary project. [[User:Matt Gibson|Matt Gibson]] 19:53, 6 June 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
===Adding a branch to your plugin===&lt;br /&gt;
Your plugin will likely start with just a HEAD tag and at some point, you will want to branch it so that you can have versions for different Moodles. To add a MOODLE_20_STABLE branch, for example, do the following.&lt;br /&gt;
&lt;br /&gt;
# Checkout as above, but use the MOODLE_20_STABLE branch instead of MOODLE_19_STABLE&lt;br /&gt;
# You will end up with an empty folder, which you copy into place as above.&lt;br /&gt;
# Find the folder in NetBeans, then right click and choose CVS-&amp;gt;Merge changes from branch...&lt;br /&gt;
# Choose to merge from whatever branch has all the current code, using the help link if not sure what to do.&lt;br /&gt;
&lt;br /&gt;
There is a small chance that the Merge link will not be there, in which case, you will have to copy the files into the directory by hand outside netbeans and then check them in. If you do this, make sure you don&#039;t copy over the &#039;CVS&#039; folders that will have been made when you checked out the MOODLE_19_STABLE code.&lt;br /&gt;
&lt;br /&gt;
=== A few warnings ===&lt;br /&gt;
&lt;br /&gt;
Some of these warnings could also apply to other IDEs:&lt;br /&gt;
&lt;br /&gt;
* If you want to delete a file from your computer but not from CVS, delete it from Windows Explorer/Nautilus/Finder. Otherwise your next commit could delete the file from CVS. &amp;lt;br/&amp;gt;In case you have already deleted a wrong file from NetBeans:  with Windows Explorer/Nautilus/Finder, delete all the folder content of this deleted file (including the CVS folder) and update the folder.&lt;br /&gt;
* If you rename files and that other people are working on them, NetBeans could end up to mess up your CVS folder (even though that is quite rare). Then NetBeans CVS will refuse to update your code displaying a no explicit error as &#039;&#039;&#039;Update Failed&#039;&#039;&#039;. In this case, delete the content of the damaged folder with Windows Explorer/Nautilus/Finder. Then update this folder.&lt;br /&gt;
* If you create a patch or a new PHP file with NetBeans on Microsoft Windows, please check that it&#039;s a Unix format file. You may want to use another software to create Unix format patch/php files.&lt;br /&gt;
&lt;br /&gt;
== Git with NetBeans ==&lt;br /&gt;
&lt;br /&gt;
=== NBGit | Git Support for NetBeans ===&lt;br /&gt;
&lt;br /&gt;
&amp;quot;NBGit is a module for the NetBeans IDE that adds support for working with the Git version control system. It uses the JGit library created as part of EGit to interact with Git repositories. Because the module is Java code all the way, it should work better cross-platform modulo platform specific differences, such as file system behavior. It is based on the NetBeans Mercurial module.&amp;quot; &lt;br /&gt;
(http://nbgit.org)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p class=&amp;quot;note orange&amp;quot;&amp;gt;&lt;br /&gt;
Unfortunately, the key word in that quote is &#039;&#039;&#039;should&#039;&#039;&#039;. In reality, because JGit is a rewrite from scratch of the tried-and-tested git core C code, it is still buggy, incomplete and unreliable. Therefore, the NetBeans and Eclipse git plugins are still only beta quality, and pretty sucky. Well, they mostly work for browsing the contents of the repository, but there is a small chance that if you use them for update operations, they will corrupt your repository. Hence, I am still doing git from the command-line.--[[User:Tim Hunt|Tim Hunt]] 11:11, 19 January 2010 (UTC)&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Needs updating ====&lt;br /&gt;
&lt;br /&gt;
Git is now integrated into Netbeans 7&lt;br /&gt;
https://netbeans.org/kb/70/ide/git.html&lt;br /&gt;
&lt;br /&gt;
== Optimization ==&lt;br /&gt;
&lt;br /&gt;
=== Sun JDK ===&lt;br /&gt;
1. You may want to run NetBeans with the Sun JDK. NetBeans seems to work a bit better with the [http://java.sun.com/javase/downloads/index.jsp Sun JDK]. You&#039;ll have to edit NetBeans config file. Open netbeans/etc/netbeans.conf. Then uncomment and edit: &lt;br /&gt;
&lt;br /&gt;
 netbeans_jdkhome=&amp;quot;your_JDK_path&amp;quot;&lt;br /&gt;
&lt;br /&gt;
2. To change the NetBeans look and feel run netbeans in the command line with this parameter:&lt;br /&gt;
 &amp;quot;netbeans&amp;quot;  --laf javax.swing.plaf.metal.MetalLookAndFeel &lt;br /&gt;
&lt;br /&gt;
3. If NetBeans starts to slow down, give it more memory&lt;br /&gt;
 &amp;quot;netbeans&amp;quot; -J-Xmx600m&lt;br /&gt;
See FAQ for more [http://wiki.netbeans.org/FaqSettingHeapSize details on memory optimisation].&lt;br /&gt;
&lt;br /&gt;
=== ScanOnDemand ===&lt;br /&gt;
To prevent NetBeans from scanning the whole code with every start up you can use the following plug-in: http://wiki.netbeans.org/ScanOnDemand&lt;br /&gt;
&lt;br /&gt;
== Coding faster ==&lt;br /&gt;
&lt;br /&gt;
=== Coding standards ===&lt;br /&gt;
&lt;br /&gt;
* There is NB config file available with the [https://github.com/enovation/moodle-utils/tree/master/netbeans-config Moodle coding settings]&lt;br /&gt;
&lt;br /&gt;
=== Keyboard shortcuts ===&lt;br /&gt;
(Note: Some shortcuts might not work for PHP development.)&lt;br /&gt;
* [http://www.phpmag.ru/2009/01/23/extremely-usefull-netbeans-shortcuts/ Extremely Useful NetBeans Shortcuts] &lt;br /&gt;
* [http://netbeanside61.blogspot.com/2008/04/top-10-netbeans-ide-keyboard-shortcuts.html Top 10 NetBeans IDE Keyboard Shortcuts I use the most]&lt;br /&gt;
* [http://wiki.netbeans.org/KeymapProfileFor60 NetBeans IDE 6.x Keyboard Shortcuts Specification]&lt;br /&gt;
&lt;br /&gt;
=== PHPUnit support ===&lt;br /&gt;
See [http://blogs.sun.com/netbeansphp/entry/recent_improvements_in_phpunit_support &amp;quot;Recent improvements in PHPUnit-support&amp;quot;] on how to use PHPUnit with NetBeans.&lt;br /&gt;
&lt;br /&gt;
===JIRA support===&lt;br /&gt;
You can install the optional JIRA module in order to be able to interact with the Moodle Tracker from within NetBeans. This has the advantage of avoiding constantly switching back and forth from the browser and works quite well. Go to &#039;&#039;Tools-&amp;gt;plugins-&amp;gt;available plugins&#039;&#039; and search for JIRA. Once installed, right click &#039;issue trackers&#039; in the &#039;services&#039; pane to make a new tracker instance, then enter your details.&lt;br /&gt;
&lt;br /&gt;
== See also: ==&lt;br /&gt;
Moodle forums &lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=112972 NetBeans 6.5 for moodle/PHP/debugging is a better experience v.s Eclipse]&lt;br /&gt;
&lt;br /&gt;
Online resources&lt;br /&gt;
* [http://www.netbeans.org/kb/trails/php.html NetBeans PHP Learning Trail]&lt;br /&gt;
* [http://wiki.netbeans.org/PHP NetBeans PHP Wiki]&lt;br /&gt;
* Sun&#039;s [http://blogs.sun.com/netbeansphp/ NetBeans PHP Team Blog]&lt;br /&gt;
&lt;br /&gt;
Book&lt;br /&gt;
* [http://www.packtpub.com/netbeans-platform-6-8-developers-guide/book NetBeans Platform 6.8 Developer&#039;s Guide] by Jürgen Petri (March 2010), focus on Java and Swing &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer tools|NetBeans]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=PHPUnit&amp;diff=41798</id>
		<title>PHPUnit</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=PHPUnit&amp;diff=41798"/>
		<updated>2013-08-06T09:34:11Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: link to phpunit manual&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.3}}&lt;br /&gt;
&lt;br /&gt;
=What is PHPUnit=&lt;br /&gt;
PHPUnit by Sebastian Bergmann is an advanced unit testing framework for PHP. It is installed as Composer dependency and is not part of Moodle installation. To run PHPUnit tests, you have to manually install it on your development computer or test server.&lt;br /&gt;
&lt;br /&gt;
Read the excellent guide at&lt;br /&gt;
* [http://phpunit.de/manual/current/en/index.html PHPUnit Manual]&lt;br /&gt;
&lt;br /&gt;
=Installation of PHPUnit via Composer=&lt;br /&gt;
&lt;br /&gt;
The installation procedure depends on your operating system.&lt;br /&gt;
* Check that /your/moodle/dirroot/composer.json exists and the contents are similar to&lt;br /&gt;
 {&lt;br /&gt;
     &amp;quot;require-dev&amp;quot;: {&lt;br /&gt;
         &amp;quot;phpunit/phpunit&amp;quot;: &amp;quot;3.7.*&amp;quot;,&lt;br /&gt;
         &amp;quot;phpunit/dbUnit&amp;quot;: &amp;quot;1.2.*&amp;quot;&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
* Install Composer dependency manager&lt;br /&gt;
&lt;br /&gt;
 cd /your/moodle/dirroot&lt;br /&gt;
 curl -s https://getcomposer.org/installer | php&lt;br /&gt;
&lt;br /&gt;
* Execute Composer installer&lt;br /&gt;
&lt;br /&gt;
 cd /your/moodle/dirroot&lt;br /&gt;
 php composer.phar install --dev&lt;br /&gt;
&lt;br /&gt;
(If that gives you connection problems try...)&lt;br /&gt;
&lt;br /&gt;
 php composer.phar install --dev --prefer-source&lt;br /&gt;
&lt;br /&gt;
Detailed instructions:&lt;br /&gt;
* [http://getcomposer.org/doc/00-intro.md Composer documentation]&lt;br /&gt;
&lt;br /&gt;
Detailed instructions:&lt;br /&gt;
* [[PHPUnit installation in Windows]]&lt;br /&gt;
* [[PHPUnit installation in OS X]]&lt;br /&gt;
&lt;br /&gt;
=Initialisation of test environment=&lt;br /&gt;
&lt;br /&gt;
Our PHPUnit integration requires a dedicated database and dataroot.  First, add a new dataroot directory and prefix into your config.php, you can find examples in config-dist.php (scroll down to &#039;Section 9&#039;).&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;phpunit_prefix = &#039;phpu_&#039;;&lt;br /&gt;
 $CFG-&amp;gt;phpunit_dataroot = &#039;/home/example/phpu_moodledata&#039;;&lt;br /&gt;
&lt;br /&gt;
If your system does not have a direct connection to the Internet, you also need to specify your proxy in config.php - even though you normally specify it by using the admin settings user interface. (If you do not use a proxy, you can skip this step.) Check the settings on the relevant admin settings page, or from the mdl_config table in your database, if you are unsure of the correct values.&lt;br /&gt;
 &lt;br /&gt;
 // Normal proxy settings&lt;br /&gt;
 $CFG-&amp;gt;proxyhost = &#039;wwwcache.example.org&#039;;&lt;br /&gt;
 $CFG-&amp;gt;proxyport = 80;&lt;br /&gt;
 $CFG-&amp;gt;proxytype = &#039;HTTP&#039;;&lt;br /&gt;
 $CFG-&amp;gt;proxybypass = &#039;localhost, 127.0.0.1, .example.org&#039;;&lt;br /&gt;
 // Omit the next lines if your proxy doesn&#039;t need a username/password:&lt;br /&gt;
 $CFG-&amp;gt;proxyuser = &#039;systemusername&#039;;&lt;br /&gt;
 $CFG-&amp;gt;proxypassword = &#039;systempassword&#039;;&lt;br /&gt;
&lt;br /&gt;
Then you need to initialise the test environment using following command.&lt;br /&gt;
&lt;br /&gt;
 cd /home/example/moodle&lt;br /&gt;
 php admin/tool/phpunit/cli/init.php&lt;br /&gt;
&lt;br /&gt;
This command has to be repeated after any upgrade, plugin (un)installation or if you have added tests to a plugin you are developing:&lt;br /&gt;
&lt;br /&gt;
=Test execution=&lt;br /&gt;
&lt;br /&gt;
To execute all test suites from main configuration file execute the &amp;lt;code&amp;gt;vendor/bin/phpunit&amp;lt;/code&amp;gt; script from your &amp;lt;code&amp;gt;$CFG-&amp;gt;dirroot&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
 cd /home/example/moodle&lt;br /&gt;
 vendor/bin/phpunit&lt;br /&gt;
&lt;br /&gt;
The rest of examples uses &amp;lt;code&amp;gt;phpunit&amp;lt;/code&amp;gt;, please substitute it with &amp;lt;code&amp;gt;vendor/bin/phpunit&amp;lt;/code&amp;gt; or create a shortcut in your dirroot.&lt;br /&gt;
&lt;br /&gt;
In IDEs, you may need to specify the path to the PHPUnit configuration file. Use the absolute path to &amp;lt;code&amp;gt;phpunit.xml&amp;lt;/code&amp;gt; from your &amp;lt;code&amp;gt;$CFG-&amp;gt;dirroot&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There is an alternative script for running of tests via web interface: &amp;lt;code&amp;gt;admin/tool/phpunit/webrunner.php&amp;lt;/code&amp;gt;. Use this as the last resort only when you cannot use the command-line interface on your test server. It will most probably break due to permissions problems if you try to execute it both from command-line and from webrunner. This feature is not officially supported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===How to run only some tests===&lt;br /&gt;
&lt;br /&gt;
==== Running a single test quickly ====&lt;br /&gt;
&lt;br /&gt;
The fastest way to run a single test is:&lt;br /&gt;
&lt;br /&gt;
 vendor/bin/phpunit my_test_class_name my/tests/filename.php&lt;br /&gt;
&lt;br /&gt;
This is faster than other methods because it avoids the need to search for the test file, but you should be careful because it may be possible to run tests this way which are not included in the normal run. If you use this method, do at least one full test run (or --group run, as below) to ensure the test can be found.&lt;br /&gt;
&lt;br /&gt;
==== Using the @group annotation ====&lt;br /&gt;
&lt;br /&gt;
If you add annotations like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Unit tests for {@link stack_cas_keyval}.&lt;br /&gt;
 * @group qtype_stack&lt;br /&gt;
 */&lt;br /&gt;
class stack_cas_keyval_exception_test extends basic_testcase {&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to all the classes in your plugin, the you can run just the tests for your plugin by doing&lt;br /&gt;
&lt;br /&gt;
 phpunit --group qtype_stack&lt;br /&gt;
&lt;br /&gt;
Therefore, it is suggested that you annotate all your tests with the Frankenstyle name of your plugin.&lt;br /&gt;
&lt;br /&gt;
==== Using multiple phpunit.xml files ====&lt;br /&gt;
&lt;br /&gt;
It&#039;s easy to create alternative phpunit.xml files defining which tests must be run together. For reference, take a look to the default /phpunit.xml available in your base directory once the testing environment has been initialised. After creating the custom file you will be able to run those tests with&lt;br /&gt;
&lt;br /&gt;
 vendor/bin/phpunit -c path/to/your/alternative/phpunit/file.xml&lt;br /&gt;
&lt;br /&gt;
Also, for commodity, you can use this command:&lt;br /&gt;
&lt;br /&gt;
 php admin/tool/phpunit/cli/util.php --buildcomponentconfigs&lt;br /&gt;
&lt;br /&gt;
It will, automatically, create one valid phpunit.xml file within each component (plugin or subsystem) and other important directories, so later you will be able to execute tests like&lt;br /&gt;
&lt;br /&gt;
 vendor/bin/phpunit -c mod/forum[/phpunit.xml]  // Note that it&#039;s not needed to specify the name of the file (if it is &#039;phpunit.xml&#039;).&lt;br /&gt;
 vendor/bin/phpunit -c question&lt;br /&gt;
 vendor/bin/phpunit -c question/type/calculated&lt;br /&gt;
 vendor/bin/phpunit -c backup&lt;br /&gt;
 vendor/bin/phpunit -c lib/dml&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
or, also&lt;br /&gt;
&lt;br /&gt;
 cd directory/with/phpunit.xml&lt;br /&gt;
 phpunit&lt;br /&gt;
&lt;br /&gt;
=Writing new tests=&lt;br /&gt;
* read [http://www.phpunit.de/manual/current/en/ official PHPUnit online documentation]&lt;br /&gt;
* see [[Writing PHPUnit tests]]&lt;br /&gt;
&lt;br /&gt;
=Conversion of existing SimpleTests=&lt;br /&gt;
* see [[SimpleTest conversion]]&lt;br /&gt;
&lt;br /&gt;
=PHPUnit support in IDEs=&lt;br /&gt;
&lt;br /&gt;
* [http://www.phpsrc.org/projects/pti-phpunit/wiki/ Eclipse PHP Tool Integration]&lt;br /&gt;
* [http://blog.jetbrains.com/webide/2009/12/phpunit-support/ PHPStorm IDE]&lt;br /&gt;
* [http://netbeans.org/kb/docs/php/phpunit.html Netbeans]&lt;br /&gt;
&lt;br /&gt;
=Common Unit Test Problems=&lt;br /&gt;
[[Common unit test problems]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Unit testing]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=PHPUnit&amp;diff=41797</id>
		<title>PHPUnit</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=PHPUnit&amp;diff=41797"/>
		<updated>2013-08-06T09:30:02Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: Added contents of composer.json&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.3}}&lt;br /&gt;
&lt;br /&gt;
=What is PHPUnit=&lt;br /&gt;
PHPUnit by Sebastian Bergmann is an advanced unit testing framework for PHP. It is installed as Composer dependency and is not part of Moodle installation. To run PHPUnit tests, you have to manually install it on your development computer or test server.&lt;br /&gt;
&lt;br /&gt;
=Installation of PHPUnit via Composer=&lt;br /&gt;
&lt;br /&gt;
The installation procedure depends on your operating system.&lt;br /&gt;
* Check that /your/moodle/dirroot/composer.json exists and the contents are similar to&lt;br /&gt;
 {&lt;br /&gt;
     &amp;quot;require-dev&amp;quot;: {&lt;br /&gt;
         &amp;quot;phpunit/phpunit&amp;quot;: &amp;quot;3.7.*&amp;quot;,&lt;br /&gt;
         &amp;quot;phpunit/dbUnit&amp;quot;: &amp;quot;1.2.*&amp;quot;&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
* Install Composer dependency manager&lt;br /&gt;
&lt;br /&gt;
 cd /your/moodle/dirroot&lt;br /&gt;
 curl -s https://getcomposer.org/installer | php&lt;br /&gt;
&lt;br /&gt;
* Execute Composer installer&lt;br /&gt;
&lt;br /&gt;
 cd /your/moodle/dirroot&lt;br /&gt;
 php composer.phar install --dev&lt;br /&gt;
&lt;br /&gt;
(If that gives you connection problems try...)&lt;br /&gt;
&lt;br /&gt;
 php composer.phar install --dev --prefer-source&lt;br /&gt;
&lt;br /&gt;
Detailed instructions:&lt;br /&gt;
* [http://getcomposer.org/doc/00-intro.md Composer documentation]&lt;br /&gt;
&lt;br /&gt;
Detailed instructions:&lt;br /&gt;
* [[PHPUnit installation in Windows]]&lt;br /&gt;
* [[PHPUnit installation in OS X]]&lt;br /&gt;
&lt;br /&gt;
=Initialisation of test environment=&lt;br /&gt;
&lt;br /&gt;
Our PHPUnit integration requires a dedicated database and dataroot.  First, add a new dataroot directory and prefix into your config.php, you can find examples in config-dist.php (scroll down to &#039;Section 9&#039;).&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;phpunit_prefix = &#039;phpu_&#039;;&lt;br /&gt;
 $CFG-&amp;gt;phpunit_dataroot = &#039;/home/example/phpu_moodledata&#039;;&lt;br /&gt;
&lt;br /&gt;
If your system does not have a direct connection to the Internet, you also need to specify your proxy in config.php - even though you normally specify it by using the admin settings user interface. (If you do not use a proxy, you can skip this step.) Check the settings on the relevant admin settings page, or from the mdl_config table in your database, if you are unsure of the correct values.&lt;br /&gt;
 &lt;br /&gt;
 // Normal proxy settings&lt;br /&gt;
 $CFG-&amp;gt;proxyhost = &#039;wwwcache.example.org&#039;;&lt;br /&gt;
 $CFG-&amp;gt;proxyport = 80;&lt;br /&gt;
 $CFG-&amp;gt;proxytype = &#039;HTTP&#039;;&lt;br /&gt;
 $CFG-&amp;gt;proxybypass = &#039;localhost, 127.0.0.1, .example.org&#039;;&lt;br /&gt;
 // Omit the next lines if your proxy doesn&#039;t need a username/password:&lt;br /&gt;
 $CFG-&amp;gt;proxyuser = &#039;systemusername&#039;;&lt;br /&gt;
 $CFG-&amp;gt;proxypassword = &#039;systempassword&#039;;&lt;br /&gt;
&lt;br /&gt;
Then you need to initialise the test environment using following command.&lt;br /&gt;
&lt;br /&gt;
 cd /home/example/moodle&lt;br /&gt;
 php admin/tool/phpunit/cli/init.php&lt;br /&gt;
&lt;br /&gt;
This command has to be repeated after any upgrade, plugin (un)installation or if you have added tests to a plugin you are developing:&lt;br /&gt;
&lt;br /&gt;
=Test execution=&lt;br /&gt;
&lt;br /&gt;
To execute all test suites from main configuration file execute the &amp;lt;code&amp;gt;vendor/bin/phpunit&amp;lt;/code&amp;gt; script from your &amp;lt;code&amp;gt;$CFG-&amp;gt;dirroot&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
 cd /home/example/moodle&lt;br /&gt;
 vendor/bin/phpunit&lt;br /&gt;
&lt;br /&gt;
The rest of examples uses &amp;lt;code&amp;gt;phpunit&amp;lt;/code&amp;gt;, please substitute it with &amp;lt;code&amp;gt;vendor/bin/phpunit&amp;lt;/code&amp;gt; or create a shortcut in your dirroot.&lt;br /&gt;
&lt;br /&gt;
In IDEs, you may need to specify the path to the PHPUnit configuration file. Use the absolute path to &amp;lt;code&amp;gt;phpunit.xml&amp;lt;/code&amp;gt; from your &amp;lt;code&amp;gt;$CFG-&amp;gt;dirroot&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There is an alternative script for running of tests via web interface: &amp;lt;code&amp;gt;admin/tool/phpunit/webrunner.php&amp;lt;/code&amp;gt;. Use this as the last resort only when you cannot use the command-line interface on your test server. It will most probably break due to permissions problems if you try to execute it both from command-line and from webrunner. This feature is not officially supported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===How to run only some tests===&lt;br /&gt;
&lt;br /&gt;
==== Running a single test quickly ====&lt;br /&gt;
&lt;br /&gt;
The fastest way to run a single test is:&lt;br /&gt;
&lt;br /&gt;
 vendor/bin/phpunit my_test_class_name my/tests/filename.php&lt;br /&gt;
&lt;br /&gt;
This is faster than other methods because it avoids the need to search for the test file, but you should be careful because it may be possible to run tests this way which are not included in the normal run. If you use this method, do at least one full test run (or --group run, as below) to ensure the test can be found.&lt;br /&gt;
&lt;br /&gt;
==== Using the @group annotation ====&lt;br /&gt;
&lt;br /&gt;
If you add annotations like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * Unit tests for {@link stack_cas_keyval}.&lt;br /&gt;
 * @group qtype_stack&lt;br /&gt;
 */&lt;br /&gt;
class stack_cas_keyval_exception_test extends basic_testcase {&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to all the classes in your plugin, the you can run just the tests for your plugin by doing&lt;br /&gt;
&lt;br /&gt;
 phpunit --group qtype_stack&lt;br /&gt;
&lt;br /&gt;
Therefore, it is suggested that you annotate all your tests with the Frankenstyle name of your plugin.&lt;br /&gt;
&lt;br /&gt;
==== Using multiple phpunit.xml files ====&lt;br /&gt;
&lt;br /&gt;
It&#039;s easy to create alternative phpunit.xml files defining which tests must be run together. For reference, take a look to the default /phpunit.xml available in your base directory once the testing environment has been initialised. After creating the custom file you will be able to run those tests with&lt;br /&gt;
&lt;br /&gt;
 vendor/bin/phpunit -c path/to/your/alternative/phpunit/file.xml&lt;br /&gt;
&lt;br /&gt;
Also, for commodity, you can use this command:&lt;br /&gt;
&lt;br /&gt;
 php admin/tool/phpunit/cli/util.php --buildcomponentconfigs&lt;br /&gt;
&lt;br /&gt;
It will, automatically, create one valid phpunit.xml file within each component (plugin or subsystem) and other important directories, so later you will be able to execute tests like&lt;br /&gt;
&lt;br /&gt;
 vendor/bin/phpunit -c mod/forum[/phpunit.xml]  // Note that it&#039;s not needed to specify the name of the file (if it is &#039;phpunit.xml&#039;).&lt;br /&gt;
 vendor/bin/phpunit -c question&lt;br /&gt;
 vendor/bin/phpunit -c question/type/calculated&lt;br /&gt;
 vendor/bin/phpunit -c backup&lt;br /&gt;
 vendor/bin/phpunit -c lib/dml&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
or, also&lt;br /&gt;
&lt;br /&gt;
 cd directory/with/phpunit.xml&lt;br /&gt;
 phpunit&lt;br /&gt;
&lt;br /&gt;
=Writing new tests=&lt;br /&gt;
* read [http://www.phpunit.de/manual/current/en/ official PHPUnit online documentation]&lt;br /&gt;
* see [[Writing PHPUnit tests]]&lt;br /&gt;
&lt;br /&gt;
=Conversion of existing SimpleTests=&lt;br /&gt;
* see [[SimpleTest conversion]]&lt;br /&gt;
&lt;br /&gt;
=PHPUnit support in IDEs=&lt;br /&gt;
&lt;br /&gt;
* [http://www.phpsrc.org/projects/pti-phpunit/wiki/ Eclipse PHP Tool Integration]&lt;br /&gt;
* [http://blog.jetbrains.com/webide/2009/12/phpunit-support/ PHPStorm IDE]&lt;br /&gt;
* [http://netbeans.org/kb/docs/php/phpunit.html Netbeans]&lt;br /&gt;
&lt;br /&gt;
=Common Unit Test Problems=&lt;br /&gt;
[[Common unit test problems]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Unit testing]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=37673</id>
		<title>CodeSniffer</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=37673"/>
		<updated>2013-02-07T01:04:53Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* Linux set up */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
===Scope===&lt;br /&gt;
This document describes the CodeSniffing/Code checker tools their purpose and usage.&lt;br /&gt;
&lt;br /&gt;
===Function===&lt;br /&gt;
The function of the CodeSniffer tool is to analyse PHP5 (only) code, apply a set of rules that match the [[Coding_style | Moodle Coding Style]], and output a report showing which parts of the code do not conform to this style.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Using codechecker===&lt;br /&gt;
&lt;br /&gt;
codechecker is a local plugin that creates a web based interface for checking the syntax of a given file. It can be found at&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker&lt;br /&gt;
&lt;br /&gt;
Once installed a new codechecker option will appear in site administration\development page.&lt;br /&gt;
&lt;br /&gt;
This page allows for the code in a specified directory to be checked, e.g. if you wanted to check the code for the shortanswer question type you would enter&lt;br /&gt;
/question/type/shortanswer&lt;br /&gt;
&lt;br /&gt;
You would then be presented with a list of the count of files processed and any warnings or errors.&lt;br /&gt;
&lt;br /&gt;
===Installing codechecker===&lt;br /&gt;
&lt;br /&gt;
To install using git, type this command in the root of your Moodle install&lt;br /&gt;
    git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker&lt;br /&gt;
&lt;br /&gt;
Then edit .gitignore in your development folder eg: &lt;br /&gt;
    gedit /var/www/moodle/.gitignore&lt;br /&gt;
&lt;br /&gt;
And add /local/codechecker/ - including the slash at the end&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the zip from &lt;br /&gt;
&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker/zipball/master&lt;br /&gt;
&lt;br /&gt;
unzip it into the local folder, and then rename the new folder to codechecker.&lt;br /&gt;
&lt;br /&gt;
===Codechecker output===&lt;br /&gt;
&lt;br /&gt;
The output is similar to the following &lt;br /&gt;
&lt;br /&gt;
Files found: 21&lt;br /&gt;
&lt;br /&gt;
question\type\calculated\backup\moodle1\lib.php - 1 error(s) and 10 warning(s)&lt;br /&gt;
then a list of all files checked with a count of errors and warnings..followed by a summary&lt;br /&gt;
Total: 31 error(s) and 262 warning(s)&lt;br /&gt;
&lt;br /&gt;
Then a list describing the exact issue in each file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;question\type\calculated\backup\moodle1\lib.php&lt;br /&gt;
&lt;br /&gt;
2: The opening &amp;lt;?php tag must be followed by exactly one newline.&lt;br /&gt;
········//·convert·and·write·the·answers·first&lt;br /&gt;
50: Inline comments must start with a capital letter, digit or 3-dots sequence&lt;br /&gt;
etc etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;You can then edit the files to attempt to remove each issue.&lt;br /&gt;
&lt;br /&gt;
===IDE plugin alternatives===&lt;br /&gt;
&lt;br /&gt;
Using the web based interface means switching between the browser and the editing environment. You may find it easier to use a plugin that allows you to check your code against the standards as you go along. &lt;br /&gt;
&lt;br /&gt;
For Eclipse users&lt;br /&gt;
http://www.phpsrc.org/&lt;br /&gt;
&lt;br /&gt;
For Netbeans users&lt;br /&gt;
&lt;br /&gt;
Make sure you have the PEAR php Codesniffer code installed, you can find instructions at &lt;br /&gt;
http://pear.php.net/package/PHP_CodeSniffer/download/All&lt;br /&gt;
&lt;br /&gt;
Then install the netbeans plugin which can be found at &lt;br /&gt;
&lt;br /&gt;
https://github.com/beberlei/netbeans-php-enhancements/downloads&lt;br /&gt;
&lt;br /&gt;
Once installed you can check it within Netbeans by going to &lt;br /&gt;
Tools/Options/PHP and click on the codesniffer tab.&lt;br /&gt;
&lt;br /&gt;
====Windows set up====&lt;br /&gt;
&lt;br /&gt;
There is an option for the codesniffer script. On my windows xampp install this needs to point to &lt;br /&gt;
&lt;br /&gt;
C:\xampp\php\phpcs.bat&lt;br /&gt;
&lt;br /&gt;
Underneath this should be a list of some of the coding standards available, but by default this will probably not include Moodle. To install the moodle standards copy the moodle folder from local\codechecker into your standards directory which for me was under&lt;br /&gt;
&lt;br /&gt;
php\PEAR\PHP\CodeSniffer\Standards&lt;br /&gt;
&lt;br /&gt;
[[Image:codesniffer.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now when you restart your Netbeans you should see a new moodle coding standard. Right clicking on a file name should present you with a new option of &amp;quot;Show Code Standard Violations&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Linux set up====&lt;br /&gt;
&lt;br /&gt;
After installing codesniffer and codechecker, copy the moodle standards folder from (assuming you have the code in /local/codechecker)&lt;br /&gt;
&lt;br /&gt;
/var/www/moodle/local/codechecker/moodle&lt;br /&gt;
&lt;br /&gt;
to &lt;br /&gt;
&lt;br /&gt;
/usr/share/php/PHP/CodeSniffer/Standards/moodle&lt;br /&gt;
&lt;br /&gt;
I changed the moodle standard in Netbeans - as described for Windows set up - but it didn&#039;t work for me.&lt;br /&gt;
&lt;br /&gt;
There is an option to set the default standard in a configuration file :&lt;br /&gt;
&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
But this gave me an error - its a known bug that should be fixed in the next release of codesniffer http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=470294&lt;br /&gt;
&lt;br /&gt;
To work around it, simply create the required folder then re-run the default setting&lt;br /&gt;
&lt;br /&gt;
    cd /usr/share/php/data&lt;br /&gt;
    sudo mkdir PHP_CodeSniffer&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
Then re-started Netbeans and it works! I also noticed that I can now switch between coding standards.&lt;br /&gt;
&lt;br /&gt;
===Simple example===&lt;br /&gt;
The script is located in lib/pear/PHP and is called runsniffer. To check the syntax of a given file (e.g. index.php), run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get a report that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AND 24 WARNING(S) AFFECTING 130 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
     1 | WARNING | $Id$ tag is no longer required, please remove.&lt;br /&gt;
    28 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | A cast statement must be followed by a single space&lt;br /&gt;
    55 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column shows the line at which the ERROR or WARNING was found. The CodeSniffer uses a set of rules which are still being defined, so that what is currently defined as ERROR or WARNING is likely to change in the near future. &lt;br /&gt;
&lt;br /&gt;
You should fix all ERRORs, but may safely ignore the WARNINGs. Fixing warnings will help your code be even more readable and consistent with other code that follow this standard.&lt;br /&gt;
&lt;br /&gt;
===Advanced Usage===&lt;br /&gt;
====Ignoring warnings====&lt;br /&gt;
You can run the CodeSniffer with the -n flag to ignore warnings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer -n index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resulting output:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AFFECTING 125 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
    28 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recursive analysis====&lt;br /&gt;
If you give the name of a folder instead of a file, it will search, analyse and report on all PHP files found in this folder and all its subfolders. This will produce a full report for each PHP file. Since this is likely to be too much information, you may want to print only a summary report, by using the following syntax (search the files/ folder as an example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Report:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/index.php                        11      58&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/draftfiles.php                   6       22&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 17 ERROR(S) AND 80 WARNING(S) WERE FOUND IN 2 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the -n flag to ignore warnings.&lt;br /&gt;
&lt;br /&gt;
====Several files in one folder====&lt;br /&gt;
If you want to search all files under a folder, but not recurse through the subfolders, you can use the -l flag (local files only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary -l grade&lt;br /&gt;
&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/index.php                        0       2&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/lib.php                          6       210&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/querylib.php                     5       39&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 11 ERROR(S) AND 251 WARNING(S) WERE FOUND IN 3 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can pass as many files and folders to the script as you want, the analysis and flags will apply to all of them.&lt;br /&gt;
&lt;br /&gt;
===Special rules===&lt;br /&gt;
When recursing through folders, the CodeSniffer script looks for a file called thirdpartylibs.xml. Currently there is only one, found under lib/. It lists directories and files which are meant to stay &#039;as-is&#039; in Moodle, in order to ensure minimum hassle when upgrading these libraries. You can use this file as a template to create your own list of exceptions.&lt;br /&gt;
&lt;br /&gt;
===Other report formats===&lt;br /&gt;
CodeSniffer can export its reports in the following formats:&lt;br /&gt;
#full: default, shown first above&lt;br /&gt;
#summary: also shown above&lt;br /&gt;
#xml: Simple XML format&lt;br /&gt;
#csv: Comma-separated list&lt;br /&gt;
#checkstyle: XML format intended for use with CruiseControl&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
#[[Coding]]&lt;br /&gt;
#[[Coding style]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=37672</id>
		<title>CodeSniffer</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=37672"/>
		<updated>2013-02-07T01:04:11Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* IDE plugin alternatives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
===Scope===&lt;br /&gt;
This document describes the CodeSniffing/Code checker tools their purpose and usage.&lt;br /&gt;
&lt;br /&gt;
===Function===&lt;br /&gt;
The function of the CodeSniffer tool is to analyse PHP5 (only) code, apply a set of rules that match the [[Coding_style | Moodle Coding Style]], and output a report showing which parts of the code do not conform to this style.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Using codechecker===&lt;br /&gt;
&lt;br /&gt;
codechecker is a local plugin that creates a web based interface for checking the syntax of a given file. It can be found at&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker&lt;br /&gt;
&lt;br /&gt;
Once installed a new codechecker option will appear in site administration\development page.&lt;br /&gt;
&lt;br /&gt;
This page allows for the code in a specified directory to be checked, e.g. if you wanted to check the code for the shortanswer question type you would enter&lt;br /&gt;
/question/type/shortanswer&lt;br /&gt;
&lt;br /&gt;
You would then be presented with a list of the count of files processed and any warnings or errors.&lt;br /&gt;
&lt;br /&gt;
===Installing codechecker===&lt;br /&gt;
&lt;br /&gt;
To install using git, type this command in the root of your Moodle install&lt;br /&gt;
    git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker&lt;br /&gt;
&lt;br /&gt;
Then edit .gitignore in your development folder eg: &lt;br /&gt;
    gedit /var/www/moodle/.gitignore&lt;br /&gt;
&lt;br /&gt;
And add /local/codechecker/ - including the slash at the end&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the zip from &lt;br /&gt;
&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker/zipball/master&lt;br /&gt;
&lt;br /&gt;
unzip it into the local folder, and then rename the new folder to codechecker.&lt;br /&gt;
&lt;br /&gt;
===Codechecker output===&lt;br /&gt;
&lt;br /&gt;
The output is similar to the following &lt;br /&gt;
&lt;br /&gt;
Files found: 21&lt;br /&gt;
&lt;br /&gt;
question\type\calculated\backup\moodle1\lib.php - 1 error(s) and 10 warning(s)&lt;br /&gt;
then a list of all files checked with a count of errors and warnings..followed by a summary&lt;br /&gt;
Total: 31 error(s) and 262 warning(s)&lt;br /&gt;
&lt;br /&gt;
Then a list describing the exact issue in each file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;question\type\calculated\backup\moodle1\lib.php&lt;br /&gt;
&lt;br /&gt;
2: The opening &amp;lt;?php tag must be followed by exactly one newline.&lt;br /&gt;
········//·convert·and·write·the·answers·first&lt;br /&gt;
50: Inline comments must start with a capital letter, digit or 3-dots sequence&lt;br /&gt;
etc etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;You can then edit the files to attempt to remove each issue.&lt;br /&gt;
&lt;br /&gt;
===IDE plugin alternatives===&lt;br /&gt;
&lt;br /&gt;
Using the web based interface means switching between the browser and the editing environment. You may find it easier to use a plugin that allows you to check your code against the standards as you go along. &lt;br /&gt;
&lt;br /&gt;
For Eclipse users&lt;br /&gt;
http://www.phpsrc.org/&lt;br /&gt;
&lt;br /&gt;
For Netbeans users&lt;br /&gt;
&lt;br /&gt;
Make sure you have the PEAR php Codesniffer code installed, you can find instructions at &lt;br /&gt;
http://pear.php.net/package/PHP_CodeSniffer/download/All&lt;br /&gt;
&lt;br /&gt;
Then install the netbeans plugin which can be found at &lt;br /&gt;
&lt;br /&gt;
https://github.com/beberlei/netbeans-php-enhancements/downloads&lt;br /&gt;
&lt;br /&gt;
Once installed you can check it within Netbeans by going to &lt;br /&gt;
Tools/Options/PHP and click on the codesniffer tab.&lt;br /&gt;
&lt;br /&gt;
====Windows set up====&lt;br /&gt;
&lt;br /&gt;
There is an option for the codesniffer script. On my windows xampp install this needs to point to &lt;br /&gt;
&lt;br /&gt;
C:\xampp\php\phpcs.bat&lt;br /&gt;
&lt;br /&gt;
Underneath this should be a list of some of the coding standards available, but by default this will probably not include Moodle. To install the moodle standards copy the moodle folder from local\codechecker into your standards directory which for me was under&lt;br /&gt;
&lt;br /&gt;
php\PEAR\PHP\CodeSniffer\Standards&lt;br /&gt;
&lt;br /&gt;
[[Image:codesniffer.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now when you restart your Netbeans you should see a new moodle coding standard. Right clicking on a file name should present you with a new option of &amp;quot;Show Code Standard Violations&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Linux set up====&lt;br /&gt;
&lt;br /&gt;
After installing codesniffer and codechecker, copy the moodle standards folder from (assuming you have the code in /local/codechecker)&lt;br /&gt;
&lt;br /&gt;
/var/www/moodle/local/codechecker/moodle&lt;br /&gt;
&lt;br /&gt;
to &lt;br /&gt;
&lt;br /&gt;
/usr/share/php/PHP/CodeSniffer/Standards/moodle&lt;br /&gt;
&lt;br /&gt;
I changed the moodle standard in Netbeans - as described above - but it didn&#039;t work for me.&lt;br /&gt;
&lt;br /&gt;
There is an option to set the default standard in a configuration file :&lt;br /&gt;
&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
But this gave me an error - its a known bug that should be fixed in the next release of codesniffer http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=470294&lt;br /&gt;
&lt;br /&gt;
To work around it, simply create the required folder then re-run the default setting&lt;br /&gt;
&lt;br /&gt;
    cd /usr/share/php/data&lt;br /&gt;
    sudo mkdir PHP_CodeSniffer&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
Then re-started Netbeans and it works! I also noticed that I can now switch between coding standards.&lt;br /&gt;
&lt;br /&gt;
===Simple example===&lt;br /&gt;
The script is located in lib/pear/PHP and is called runsniffer. To check the syntax of a given file (e.g. index.php), run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get a report that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AND 24 WARNING(S) AFFECTING 130 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
     1 | WARNING | $Id$ tag is no longer required, please remove.&lt;br /&gt;
    28 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | A cast statement must be followed by a single space&lt;br /&gt;
    55 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column shows the line at which the ERROR or WARNING was found. The CodeSniffer uses a set of rules which are still being defined, so that what is currently defined as ERROR or WARNING is likely to change in the near future. &lt;br /&gt;
&lt;br /&gt;
You should fix all ERRORs, but may safely ignore the WARNINGs. Fixing warnings will help your code be even more readable and consistent with other code that follow this standard.&lt;br /&gt;
&lt;br /&gt;
===Advanced Usage===&lt;br /&gt;
====Ignoring warnings====&lt;br /&gt;
You can run the CodeSniffer with the -n flag to ignore warnings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer -n index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resulting output:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AFFECTING 125 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
    28 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recursive analysis====&lt;br /&gt;
If you give the name of a folder instead of a file, it will search, analyse and report on all PHP files found in this folder and all its subfolders. This will produce a full report for each PHP file. Since this is likely to be too much information, you may want to print only a summary report, by using the following syntax (search the files/ folder as an example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Report:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/index.php                        11      58&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/draftfiles.php                   6       22&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 17 ERROR(S) AND 80 WARNING(S) WERE FOUND IN 2 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the -n flag to ignore warnings.&lt;br /&gt;
&lt;br /&gt;
====Several files in one folder====&lt;br /&gt;
If you want to search all files under a folder, but not recurse through the subfolders, you can use the -l flag (local files only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary -l grade&lt;br /&gt;
&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/index.php                        0       2&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/lib.php                          6       210&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/querylib.php                     5       39&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 11 ERROR(S) AND 251 WARNING(S) WERE FOUND IN 3 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can pass as many files and folders to the script as you want, the analysis and flags will apply to all of them.&lt;br /&gt;
&lt;br /&gt;
===Special rules===&lt;br /&gt;
When recursing through folders, the CodeSniffer script looks for a file called thirdpartylibs.xml. Currently there is only one, found under lib/. It lists directories and files which are meant to stay &#039;as-is&#039; in Moodle, in order to ensure minimum hassle when upgrading these libraries. You can use this file as a template to create your own list of exceptions.&lt;br /&gt;
&lt;br /&gt;
===Other report formats===&lt;br /&gt;
CodeSniffer can export its reports in the following formats:&lt;br /&gt;
#full: default, shown first above&lt;br /&gt;
#summary: also shown above&lt;br /&gt;
#xml: Simple XML format&lt;br /&gt;
#csv: Comma-separated list&lt;br /&gt;
#checkstyle: XML format intended for use with CruiseControl&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
#[[Coding]]&lt;br /&gt;
#[[Coding style]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:Trusttext_cleaning_bypass&amp;diff=36849</id>
		<title>Talk:Trusttext cleaning bypass</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:Trusttext_cleaning_bypass&amp;diff=36849"/>
		<updated>2012-12-12T04:42:05Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I drafted up this little ditty before abandoning it. It doesn&#039;t require extra fields - other than the userid field which is in most tables.&lt;br /&gt;
&lt;br /&gt;
Use by calling the function before an insert/update or before displaying the data.&lt;br /&gt;
&lt;br /&gt;
The main advantage is that the trust is checked before being displayed. So if a users trust is revoked after they have entered some malicious script, then the script won&#039;t be displayed.&lt;br /&gt;
&lt;br /&gt;
eg:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$data = new stdClass();&lt;br /&gt;
$data-&amp;gt;id = 0;&lt;br /&gt;
$data-&amp;gt;userid = 2;&lt;br /&gt;
$data-&amp;gt;description = &#039;&amp;lt;script&amp;gt;alert(1);&amp;lt;/script&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
$data = my_trusttext_prepare($data, array(&#039;description&#039;), $data-&amp;gt;userid);&lt;br /&gt;
&lt;br /&gt;
$id = $DB-&amp;gt;insert_record(&#039;mytable&#039;, $data);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Returns clean text fields if the user is not trusted&lt;br /&gt;
 *&lt;br /&gt;
 * Removes XSS nasties&lt;br /&gt;
 *&lt;br /&gt;
 * @param object $data Record object - either pre-insert/update or after retrieval&lt;br /&gt;
 * @param array $fields Array of fields to clean&lt;br /&gt;
 * @param integer|object $updatinguserid A user id or object, this is the last editor of the record NOT the current user&lt;br /&gt;
 * @param object $context - Context to use, defaults to system context&lt;br /&gt;
 * @return object $data Cleaned data fields where appropriate&lt;br /&gt;
 */&lt;br /&gt;
function my_trusttext_prepare($data, $fields, $updatinguserid, $context = null) {&lt;br /&gt;
	if (is_null($context)) {&lt;br /&gt;
		// Default to system context&lt;br /&gt;
		$context = get_context_instance(CONTEXT_SYSTEM);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (!is_object($data) || !is_array($fields)) {&lt;br /&gt;
		// Params are invalid&lt;br /&gt;
		print_error(&#039;error:trusttextparam&#039;, &#039;my_errors&#039;);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (!has_capability(&#039;moodle/site:trustcontent&#039;, $context, $updatinguserid)) {&lt;br /&gt;
		// User might be a cheeky monkey, so clean the text&lt;br /&gt;
		foreach ($fields as $field) {&lt;br /&gt;
			if (!isset($data-&amp;gt;$field)) {&lt;br /&gt;
				// Oops, field doesn&#039;t exist&lt;br /&gt;
				print_error(&#039;error:trusttextfieldunknown&#039;, &#039;my_errors&#039;, null, $field);&lt;br /&gt;
			} else {&lt;br /&gt;
				$data-&amp;gt;$field = clean_text($data-&amp;gt;$field);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return $data;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:Trusttext_cleaning_bypass&amp;diff=36848</id>
		<title>Talk:Trusttext cleaning bypass</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:Trusttext_cleaning_bypass&amp;diff=36848"/>
		<updated>2012-12-12T04:40:30Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I drafted up this little ditty before abandoning it. It doesn&#039;t require extra fields - other than the userid field which is in most tables.&lt;br /&gt;
&lt;br /&gt;
Use by calling the function before an insert/update or before displaying the data.&lt;br /&gt;
&lt;br /&gt;
The main advantage is that the trust is checked before being displayed. So if a users trust is revoked after they have entered some malicious script, then the script won&#039;t be displayed.&lt;br /&gt;
&lt;br /&gt;
eg:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$data = new stdClass();&lt;br /&gt;
$data-&amp;gt;id = 0;&lt;br /&gt;
$data-&amp;gt;userid = 2;&lt;br /&gt;
$data-&amp;gt;description = &#039;&amp;lt;script&amp;gt;alaert(1);&amp;lt;/script&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
$data = my_trusttext_prepare($data, array(&#039;description&#039;), $data-&amp;gt;userid);&lt;br /&gt;
&lt;br /&gt;
$id = $DB-&amp;gt;insert_record(&#039;mytable&#039;, $data);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Returns clean text fields if the user is not trusted&lt;br /&gt;
 *&lt;br /&gt;
 * Removes XSS nasties&lt;br /&gt;
 *&lt;br /&gt;
 * @param object $data Record object - either pre-insert/update or after retrieval&lt;br /&gt;
 * @param array $fields Array of fields to clean&lt;br /&gt;
 * @param integer|object $updatinguserid A user id or object, this is the last editor of the record NOT the current user&lt;br /&gt;
 * @param object $context - Context to use, defaults to system context&lt;br /&gt;
 * @return object $data Cleaned data fields where appropriate&lt;br /&gt;
 */&lt;br /&gt;
function my_trusttext_prepare($data, $fields, $updatinguserid, $context = null) {&lt;br /&gt;
	if (is_null($context)) {&lt;br /&gt;
		// Default to system context&lt;br /&gt;
		$context = get_context_instance(CONTEXT_SYSTEM);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (!is_object($data) || !is_array($fields)) {&lt;br /&gt;
		// Params are invalid&lt;br /&gt;
		print_error(&#039;error:trusttextparam&#039;, &#039;totara_core&#039;);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (!has_capability(&#039;moodle/site:trustcontent&#039;, $context, $updatinguserid)) {&lt;br /&gt;
		// User might be a cheeky monkey, so clean the text&lt;br /&gt;
		foreach ($fields as $field) {&lt;br /&gt;
			if (!isset($data-&amp;gt;$field)) {&lt;br /&gt;
				// Oops, field doesn&#039;t exist&lt;br /&gt;
				print_error(&#039;error:trusttextfieldunknown&#039;, &#039;totara_core&#039;, null, $field);&lt;br /&gt;
			} else {&lt;br /&gt;
				$data-&amp;gt;$field = clean_text($data-&amp;gt;$field);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return $data;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:Trusttext_cleaning_bypass&amp;diff=36847</id>
		<title>Talk:Trusttext cleaning bypass</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:Trusttext_cleaning_bypass&amp;diff=36847"/>
		<updated>2012-12-12T04:38:18Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: Possible simple solution for trusttext?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I drafted up this little ditty before abandoning it. It doesn&#039;t require extra fields - other than the userid field which is in most tables.&lt;br /&gt;
&lt;br /&gt;
Use by calling the function before an insert/update or before displaying the data.&lt;br /&gt;
&lt;br /&gt;
The main advantage is that the trust is checked before being displayed. So if a users trust is revoked after they have entered some malicious script, then the script won&#039;t be displayed.&lt;br /&gt;
&lt;br /&gt;
eg:&lt;br /&gt;
&lt;br /&gt;
	$data = new stdClass();&lt;br /&gt;
	$data-&amp;gt;id = 0;&lt;br /&gt;
	$data-&amp;gt;userid = 2;&lt;br /&gt;
	$data-&amp;gt;description = &#039;&amp;lt;script&amp;gt;alaert(1);&amp;lt;/script&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
	...&lt;br /&gt;
&lt;br /&gt;
	$data = my_trusttext_prepare($data, array(&#039;description&#039;), $data-&amp;gt;userid);&lt;br /&gt;
&lt;br /&gt;
	$id = $DB-&amp;gt;insert_record(&#039;mytable&#039;, $data);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Returns clean text fields if the user is not trusted&lt;br /&gt;
	 *&lt;br /&gt;
	 * Removes XSS nasties&lt;br /&gt;
	 *&lt;br /&gt;
	 * @param object $data Record object - either pre-insert/update or after retrieval&lt;br /&gt;
	 * @param array $fields Array of fields to clean&lt;br /&gt;
	 * @param integer|object $updatinguserid A user id or object, this is the last editor of the record NOT the current user&lt;br /&gt;
	 * @param object $context - Context to use, defaults to system context&lt;br /&gt;
	 * @return object $data Cleaned data fields where appropriate&lt;br /&gt;
	 */&lt;br /&gt;
	function my_trusttext_prepare($data, $fields, $updatinguserid, $context = null) {&lt;br /&gt;
		if (is_null($context)) {&lt;br /&gt;
			// Default to system context&lt;br /&gt;
			$context = get_context_instance(CONTEXT_SYSTEM);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		if (!is_object($data) || !is_array($fields)) {&lt;br /&gt;
			// Params are invalid&lt;br /&gt;
			print_error(&#039;error:trusttextparam&#039;, &#039;totara_core&#039;);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		if (!has_capability(&#039;moodle/site:trustcontent&#039;, $context, $updatinguserid)) {&lt;br /&gt;
			// User might be a cheeky monkey, so clean the text&lt;br /&gt;
			foreach ($fields as $field) {&lt;br /&gt;
				if (!isset($data-&amp;gt;$field)) {&lt;br /&gt;
					// Oops, field doesn&#039;t exist&lt;br /&gt;
					print_error(&#039;error:trusttextfieldunknown&#039;, &#039;totara_core&#039;, null, $field);&lt;br /&gt;
				} else {&lt;br /&gt;
					$data-&amp;gt;$field = clean_text($data-&amp;gt;$field);&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		return $data;&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36839</id>
		<title>CodeSniffer</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36839"/>
		<updated>2012-12-10T01:53:01Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* Linux set up */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
===Scope===&lt;br /&gt;
This document describes the CodeSniffing/Code checker tools their purpose and usage.&lt;br /&gt;
&lt;br /&gt;
===Function===&lt;br /&gt;
The function of the CodeSniffer tool is to analyse PHP5 (only) code, apply a set of rules that match the [[Coding_style | Moodle Coding Style]], and output a report showing which parts of the code do not conform to this style.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Using codechecker===&lt;br /&gt;
&lt;br /&gt;
codechecker is a local plugin that creates a web based interface for checking the syntax of a given file. It can be found at&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker&lt;br /&gt;
&lt;br /&gt;
Once installed a new codechecker option will appear in site administration\development page.&lt;br /&gt;
&lt;br /&gt;
This page allows for the code in a specified directory to be checked, e.g. if you wanted to check the code for the shortanswer question type you would enter&lt;br /&gt;
/question/type/shortanswer&lt;br /&gt;
&lt;br /&gt;
You would then be presented with a list of the count of files processed and any warnings or errors.&lt;br /&gt;
&lt;br /&gt;
===Installing codechecker===&lt;br /&gt;
&lt;br /&gt;
To install using git, type this command in the root of your Moodle install&lt;br /&gt;
    git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker&lt;br /&gt;
&lt;br /&gt;
Then edit .gitignore in your development folder eg: &lt;br /&gt;
    gedit /var/www/moodle/.gitignore&lt;br /&gt;
&lt;br /&gt;
And add /local/codechecker/ - including the slash at the end&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the zip from &lt;br /&gt;
&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker/zipball/master&lt;br /&gt;
&lt;br /&gt;
unzip it into the local folder, and then rename the new folder to codechecker.&lt;br /&gt;
&lt;br /&gt;
===Codechecker output===&lt;br /&gt;
&lt;br /&gt;
The output is similar to the following &lt;br /&gt;
&lt;br /&gt;
Files found: 21&lt;br /&gt;
&lt;br /&gt;
question\type\calculated\backup\moodle1\lib.php - 1 error(s) and 10 warning(s)&lt;br /&gt;
then a list of all files checked with a count of errors and warnings..followed by a summary&lt;br /&gt;
Total: 31 error(s) and 262 warning(s)&lt;br /&gt;
&lt;br /&gt;
Then a list describing the exact issue in each file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;question\type\calculated\backup\moodle1\lib.php&lt;br /&gt;
&lt;br /&gt;
2: The opening &amp;lt;?php tag must be followed by exactly one newline.&lt;br /&gt;
········//·convert·and·write·the·answers·first&lt;br /&gt;
50: Inline comments must start with a capital letter, digit or 3-dots sequence&lt;br /&gt;
etc etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;You can then edit the files to attempt to remove each issue.&lt;br /&gt;
&lt;br /&gt;
===IDE plugin alternatives===&lt;br /&gt;
&lt;br /&gt;
Using the web based interface means switching between the browser and the editing environment. You may find it easier to use a plugin that allows you to check your code against the standards as you go along. &lt;br /&gt;
&lt;br /&gt;
For Eclipse users&lt;br /&gt;
http://www.phpsrc.org/&lt;br /&gt;
&lt;br /&gt;
For Netbeans users&lt;br /&gt;
&lt;br /&gt;
Make sure you have the PEAR php Codesniffer code installed, you can find instructions at &lt;br /&gt;
http://pear.php.net/package/PHP_CodeSniffer/download/All&lt;br /&gt;
&lt;br /&gt;
Then install the netbeans plugin which can be found at &lt;br /&gt;
&lt;br /&gt;
https://github.com/beberlei/netbeans-php-enhancements/downloads&lt;br /&gt;
&lt;br /&gt;
Once installed you can check it within Netbeans by going to &lt;br /&gt;
Tools/Options/PHP and click on the codesniffer tab.&lt;br /&gt;
&lt;br /&gt;
There is an option for the codesniffer script. On my windows xampp install this needs to point to &lt;br /&gt;
&lt;br /&gt;
C:\xampp\php\phpcs.bat&lt;br /&gt;
&lt;br /&gt;
Underneath this should be a list of some of the coding standards available, but by default this will probably not include Moodle. To install the moodle standards copy the moodle folder from local\codechecker into your standards directory which for me was under&lt;br /&gt;
&lt;br /&gt;
php\PEAR\PHP\CodeSniffer\Standards&lt;br /&gt;
&lt;br /&gt;
[[Image:codesniffer.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now when you restart your Netbeans you should see a new moodle coding standard. Right clicking on a file name should present you with a new option of &amp;quot;Show Code Standard Violations&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Linux set up====&lt;br /&gt;
&lt;br /&gt;
After installing codesniffer and codechecker, copy the moodle standards folder from (assuming you have the code in /local/codechecker)&lt;br /&gt;
&lt;br /&gt;
/var/www/moodle/local/codechecker/moodle&lt;br /&gt;
&lt;br /&gt;
to &lt;br /&gt;
&lt;br /&gt;
/usr/share/php/PHP/CodeSniffer/Standards/moodle&lt;br /&gt;
&lt;br /&gt;
I changed the moodle standard in Netbeans - as described above - but it didn&#039;t work for me.&lt;br /&gt;
&lt;br /&gt;
There is an option to set the default standard in a configuration file :&lt;br /&gt;
&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
But this gave me an error - its a known bug that should be fixed in the next release of codesniffer http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=470294&lt;br /&gt;
&lt;br /&gt;
To work around it, simply create the required folder then re-run the default setting&lt;br /&gt;
&lt;br /&gt;
    cd /usr/share/php/data&lt;br /&gt;
    sudo mkdir PHP_CodeSniffer&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
Then re-started Netbeans and it works! I also noticed that I can now switch between coding standards.&lt;br /&gt;
&lt;br /&gt;
===Simple example===&lt;br /&gt;
The script is located in lib/pear/PHP and is called runsniffer. To check the syntax of a given file (e.g. index.php), run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get a report that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AND 24 WARNING(S) AFFECTING 130 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
     1 | WARNING | $Id$ tag is no longer required, please remove.&lt;br /&gt;
    28 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | A cast statement must be followed by a single space&lt;br /&gt;
    55 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column shows the line at which the ERROR or WARNING was found. The CodeSniffer uses a set of rules which are still being defined, so that what is currently defined as ERROR or WARNING is likely to change in the near future. &lt;br /&gt;
&lt;br /&gt;
You should fix all ERRORs, but may safely ignore the WARNINGs. Fixing warnings will help your code be even more readable and consistent with other code that follow this standard.&lt;br /&gt;
&lt;br /&gt;
===Advanced Usage===&lt;br /&gt;
====Ignoring warnings====&lt;br /&gt;
You can run the CodeSniffer with the -n flag to ignore warnings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer -n index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resulting output:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AFFECTING 125 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
    28 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recursive analysis====&lt;br /&gt;
If you give the name of a folder instead of a file, it will search, analyse and report on all PHP files found in this folder and all its subfolders. This will produce a full report for each PHP file. Since this is likely to be too much information, you may want to print only a summary report, by using the following syntax (search the files/ folder as an example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Report:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/index.php                        11      58&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/draftfiles.php                   6       22&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 17 ERROR(S) AND 80 WARNING(S) WERE FOUND IN 2 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the -n flag to ignore warnings.&lt;br /&gt;
&lt;br /&gt;
====Several files in one folder====&lt;br /&gt;
If you want to search all files under a folder, but not recurse through the subfolders, you can use the -l flag (local files only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary -l grade&lt;br /&gt;
&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/index.php                        0       2&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/lib.php                          6       210&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/querylib.php                     5       39&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 11 ERROR(S) AND 251 WARNING(S) WERE FOUND IN 3 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can pass as many files and folders to the script as you want, the analysis and flags will apply to all of them.&lt;br /&gt;
&lt;br /&gt;
===Special rules===&lt;br /&gt;
When recursing through folders, the CodeSniffer script looks for a file called thirdpartylibs.xml. Currently there is only one, found under lib/. It lists directories and files which are meant to stay &#039;as-is&#039; in Moodle, in order to ensure minimum hassle when upgrading these libraries. You can use this file as a template to create your own list of exceptions.&lt;br /&gt;
&lt;br /&gt;
===Other report formats===&lt;br /&gt;
CodeSniffer can export its reports in the following formats:&lt;br /&gt;
#full: default, shown first above&lt;br /&gt;
#summary: also shown above&lt;br /&gt;
#xml: Simple XML format&lt;br /&gt;
#csv: Comma-separated list&lt;br /&gt;
#checkstyle: XML format intended for use with CruiseControl&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
#[[Coding]]&lt;br /&gt;
#[[Coding style]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36838</id>
		<title>CodeSniffer</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36838"/>
		<updated>2012-12-10T01:52:03Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* IDE plugin alternatives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
===Scope===&lt;br /&gt;
This document describes the CodeSniffing/Code checker tools their purpose and usage.&lt;br /&gt;
&lt;br /&gt;
===Function===&lt;br /&gt;
The function of the CodeSniffer tool is to analyse PHP5 (only) code, apply a set of rules that match the [[Coding_style | Moodle Coding Style]], and output a report showing which parts of the code do not conform to this style.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Using codechecker===&lt;br /&gt;
&lt;br /&gt;
codechecker is a local plugin that creates a web based interface for checking the syntax of a given file. It can be found at&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker&lt;br /&gt;
&lt;br /&gt;
Once installed a new codechecker option will appear in site administration\development page.&lt;br /&gt;
&lt;br /&gt;
This page allows for the code in a specified directory to be checked, e.g. if you wanted to check the code for the shortanswer question type you would enter&lt;br /&gt;
/question/type/shortanswer&lt;br /&gt;
&lt;br /&gt;
You would then be presented with a list of the count of files processed and any warnings or errors.&lt;br /&gt;
&lt;br /&gt;
===Installing codechecker===&lt;br /&gt;
&lt;br /&gt;
To install using git, type this command in the root of your Moodle install&lt;br /&gt;
    git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker&lt;br /&gt;
&lt;br /&gt;
Then edit .gitignore in your development folder eg: &lt;br /&gt;
    gedit /var/www/moodle/.gitignore&lt;br /&gt;
&lt;br /&gt;
And add /local/codechecker/ - including the slash at the end&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the zip from &lt;br /&gt;
&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker/zipball/master&lt;br /&gt;
&lt;br /&gt;
unzip it into the local folder, and then rename the new folder to codechecker.&lt;br /&gt;
&lt;br /&gt;
===Codechecker output===&lt;br /&gt;
&lt;br /&gt;
The output is similar to the following &lt;br /&gt;
&lt;br /&gt;
Files found: 21&lt;br /&gt;
&lt;br /&gt;
question\type\calculated\backup\moodle1\lib.php - 1 error(s) and 10 warning(s)&lt;br /&gt;
then a list of all files checked with a count of errors and warnings..followed by a summary&lt;br /&gt;
Total: 31 error(s) and 262 warning(s)&lt;br /&gt;
&lt;br /&gt;
Then a list describing the exact issue in each file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;question\type\calculated\backup\moodle1\lib.php&lt;br /&gt;
&lt;br /&gt;
2: The opening &amp;lt;?php tag must be followed by exactly one newline.&lt;br /&gt;
········//·convert·and·write·the·answers·first&lt;br /&gt;
50: Inline comments must start with a capital letter, digit or 3-dots sequence&lt;br /&gt;
etc etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;You can then edit the files to attempt to remove each issue.&lt;br /&gt;
&lt;br /&gt;
===IDE plugin alternatives===&lt;br /&gt;
&lt;br /&gt;
Using the web based interface means switching between the browser and the editing environment. You may find it easier to use a plugin that allows you to check your code against the standards as you go along. &lt;br /&gt;
&lt;br /&gt;
For Eclipse users&lt;br /&gt;
http://www.phpsrc.org/&lt;br /&gt;
&lt;br /&gt;
For Netbeans users&lt;br /&gt;
&lt;br /&gt;
Make sure you have the PEAR php Codesniffer code installed, you can find instructions at &lt;br /&gt;
http://pear.php.net/package/PHP_CodeSniffer/download/All&lt;br /&gt;
&lt;br /&gt;
Then install the netbeans plugin which can be found at &lt;br /&gt;
&lt;br /&gt;
https://github.com/beberlei/netbeans-php-enhancements/downloads&lt;br /&gt;
&lt;br /&gt;
Once installed you can check it within Netbeans by going to &lt;br /&gt;
Tools/Options/PHP and click on the codesniffer tab.&lt;br /&gt;
&lt;br /&gt;
There is an option for the codesniffer script. On my windows xampp install this needs to point to &lt;br /&gt;
&lt;br /&gt;
C:\xampp\php\phpcs.bat&lt;br /&gt;
&lt;br /&gt;
Underneath this should be a list of some of the coding standards available, but by default this will probably not include Moodle. To install the moodle standards copy the moodle folder from local\codechecker into your standards directory which for me was under&lt;br /&gt;
&lt;br /&gt;
php\PEAR\PHP\CodeSniffer\Standards&lt;br /&gt;
&lt;br /&gt;
[[Image:codesniffer.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now when you restart your Netbeans you should see a new moodle coding standard. Right clicking on a file name should present you with a new option of &amp;quot;Show Code Standard Violations&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Linux set up====&lt;br /&gt;
&lt;br /&gt;
After installing codesniffer and codechecker, copy the moodle standards folder from (assuming you have the code in /local/codechecker)&lt;br /&gt;
&lt;br /&gt;
/var/www/moodle/local/codechecker/moodle&lt;br /&gt;
&lt;br /&gt;
to &lt;br /&gt;
&lt;br /&gt;
/usr/share/php/PHP/CodeSniffer/Standards/moodle&lt;br /&gt;
&lt;br /&gt;
I changed the moodle standard in Netbeans - as described above - but it didn&#039;t work for me.&lt;br /&gt;
&lt;br /&gt;
There is an option to set the default standard in a configuration file :&lt;br /&gt;
&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
But this gave me an error - its a known bug that should be fixed in the next release of codesniffer http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=470294&lt;br /&gt;
&lt;br /&gt;
To work around it, simply create the required folder then re-run the default setting&lt;br /&gt;
&lt;br /&gt;
    cd /usr/share/php/data/PHP_CodeSniffer&lt;br /&gt;
    sudo mkdir PHP_CodeSniffer&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
Then re-started Netbeans and it works! I also noticed that I can now switch between coding standards.&lt;br /&gt;
&lt;br /&gt;
===Simple example===&lt;br /&gt;
The script is located in lib/pear/PHP and is called runsniffer. To check the syntax of a given file (e.g. index.php), run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get a report that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AND 24 WARNING(S) AFFECTING 130 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
     1 | WARNING | $Id$ tag is no longer required, please remove.&lt;br /&gt;
    28 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | A cast statement must be followed by a single space&lt;br /&gt;
    55 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column shows the line at which the ERROR or WARNING was found. The CodeSniffer uses a set of rules which are still being defined, so that what is currently defined as ERROR or WARNING is likely to change in the near future. &lt;br /&gt;
&lt;br /&gt;
You should fix all ERRORs, but may safely ignore the WARNINGs. Fixing warnings will help your code be even more readable and consistent with other code that follow this standard.&lt;br /&gt;
&lt;br /&gt;
===Advanced Usage===&lt;br /&gt;
====Ignoring warnings====&lt;br /&gt;
You can run the CodeSniffer with the -n flag to ignore warnings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer -n index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resulting output:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AFFECTING 125 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
    28 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recursive analysis====&lt;br /&gt;
If you give the name of a folder instead of a file, it will search, analyse and report on all PHP files found in this folder and all its subfolders. This will produce a full report for each PHP file. Since this is likely to be too much information, you may want to print only a summary report, by using the following syntax (search the files/ folder as an example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Report:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/index.php                        11      58&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/draftfiles.php                   6       22&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 17 ERROR(S) AND 80 WARNING(S) WERE FOUND IN 2 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the -n flag to ignore warnings.&lt;br /&gt;
&lt;br /&gt;
====Several files in one folder====&lt;br /&gt;
If you want to search all files under a folder, but not recurse through the subfolders, you can use the -l flag (local files only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary -l grade&lt;br /&gt;
&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/index.php                        0       2&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/lib.php                          6       210&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/querylib.php                     5       39&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 11 ERROR(S) AND 251 WARNING(S) WERE FOUND IN 3 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can pass as many files and folders to the script as you want, the analysis and flags will apply to all of them.&lt;br /&gt;
&lt;br /&gt;
===Special rules===&lt;br /&gt;
When recursing through folders, the CodeSniffer script looks for a file called thirdpartylibs.xml. Currently there is only one, found under lib/. It lists directories and files which are meant to stay &#039;as-is&#039; in Moodle, in order to ensure minimum hassle when upgrading these libraries. You can use this file as a template to create your own list of exceptions.&lt;br /&gt;
&lt;br /&gt;
===Other report formats===&lt;br /&gt;
CodeSniffer can export its reports in the following formats:&lt;br /&gt;
#full: default, shown first above&lt;br /&gt;
#summary: also shown above&lt;br /&gt;
#xml: Simple XML format&lt;br /&gt;
#csv: Comma-separated list&lt;br /&gt;
#checkstyle: XML format intended for use with CruiseControl&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
#[[Coding]]&lt;br /&gt;
#[[Coding style]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36837</id>
		<title>CodeSniffer</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36837"/>
		<updated>2012-12-10T01:50:11Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* IDE plugin alternatives */ troubleshooting the linux install&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
===Scope===&lt;br /&gt;
This document describes the CodeSniffing/Code checker tools their purpose and usage.&lt;br /&gt;
&lt;br /&gt;
===Function===&lt;br /&gt;
The function of the CodeSniffer tool is to analyse PHP5 (only) code, apply a set of rules that match the [[Coding_style | Moodle Coding Style]], and output a report showing which parts of the code do not conform to this style.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Using codechecker===&lt;br /&gt;
&lt;br /&gt;
codechecker is a local plugin that creates a web based interface for checking the syntax of a given file. It can be found at&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker&lt;br /&gt;
&lt;br /&gt;
Once installed a new codechecker option will appear in site administration\development page.&lt;br /&gt;
&lt;br /&gt;
This page allows for the code in a specified directory to be checked, e.g. if you wanted to check the code for the shortanswer question type you would enter&lt;br /&gt;
/question/type/shortanswer&lt;br /&gt;
&lt;br /&gt;
You would then be presented with a list of the count of files processed and any warnings or errors.&lt;br /&gt;
&lt;br /&gt;
===Installing codechecker===&lt;br /&gt;
&lt;br /&gt;
To install using git, type this command in the root of your Moodle install&lt;br /&gt;
    git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker&lt;br /&gt;
&lt;br /&gt;
Then edit .gitignore in your development folder eg: &lt;br /&gt;
    gedit /var/www/moodle/.gitignore&lt;br /&gt;
&lt;br /&gt;
And add /local/codechecker/ - including the slash at the end&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the zip from &lt;br /&gt;
&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker/zipball/master&lt;br /&gt;
&lt;br /&gt;
unzip it into the local folder, and then rename the new folder to codechecker.&lt;br /&gt;
&lt;br /&gt;
===Codechecker output===&lt;br /&gt;
&lt;br /&gt;
The output is similar to the following &lt;br /&gt;
&lt;br /&gt;
Files found: 21&lt;br /&gt;
&lt;br /&gt;
question\type\calculated\backup\moodle1\lib.php - 1 error(s) and 10 warning(s)&lt;br /&gt;
then a list of all files checked with a count of errors and warnings..followed by a summary&lt;br /&gt;
Total: 31 error(s) and 262 warning(s)&lt;br /&gt;
&lt;br /&gt;
Then a list describing the exact issue in each file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;question\type\calculated\backup\moodle1\lib.php&lt;br /&gt;
&lt;br /&gt;
2: The opening &amp;lt;?php tag must be followed by exactly one newline.&lt;br /&gt;
········//·convert·and·write·the·answers·first&lt;br /&gt;
50: Inline comments must start with a capital letter, digit or 3-dots sequence&lt;br /&gt;
etc etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;You can then edit the files to attempt to remove each issue.&lt;br /&gt;
&lt;br /&gt;
===IDE plugin alternatives===&lt;br /&gt;
&lt;br /&gt;
Using the web based interface means switching between the browser and the editing environment. You may find it easier to use a plugin that allows you to check your code against the standards as you go along. &lt;br /&gt;
&lt;br /&gt;
For Eclipse users&lt;br /&gt;
http://www.phpsrc.org/&lt;br /&gt;
&lt;br /&gt;
For Netbeans users&lt;br /&gt;
&lt;br /&gt;
Make sure you have the PEAR php Codesniffer code installed, you can find instructions at &lt;br /&gt;
http://pear.php.net/package/PHP_CodeSniffer/download/All&lt;br /&gt;
&lt;br /&gt;
Then install the netbeans plugin which can be found at &lt;br /&gt;
&lt;br /&gt;
https://github.com/beberlei/netbeans-php-enhancements/downloads&lt;br /&gt;
&lt;br /&gt;
Once installed you can check it within Netbeans by going to &lt;br /&gt;
Tools/Options/PHP and click on the codesniffer tab.&lt;br /&gt;
&lt;br /&gt;
There is an option for the codesniffer script. On my windows xampp install this needs to point to &lt;br /&gt;
&lt;br /&gt;
C:\xampp\php\phpcs.bat&lt;br /&gt;
&lt;br /&gt;
Underneath this should be a list of some of the coding standards available, but by default this will probably not include Moodle. To install the moodle standards copy the moodle folder from local\codechecker into your standards directory which for me was under&lt;br /&gt;
&lt;br /&gt;
php\PEAR\PHP\CodeSniffer\Standards&lt;br /&gt;
&lt;br /&gt;
====Linux set up====&lt;br /&gt;
&lt;br /&gt;
After installing codesniffer and codechecker, copy the moodle standards folder from (assuming you have the code in /local/codechecker)&lt;br /&gt;
&lt;br /&gt;
/var/www/moodle/local/codechecker/moodle&lt;br /&gt;
&lt;br /&gt;
to &lt;br /&gt;
&lt;br /&gt;
/usr/share/php/PHP/CodeSniffer/Standards/moodle&lt;br /&gt;
&lt;br /&gt;
I changed the moodle standard in Netbeans - as described below - but it didn&#039;t work for me.&lt;br /&gt;
&lt;br /&gt;
There is an option to set the default standard in a configuration file :&lt;br /&gt;
&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
But this gave me an error - its a known bug that should be fixed in the next release of codesniffer http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=470294&lt;br /&gt;
&lt;br /&gt;
To work around it, simply create the required folder then re-run the default setting&lt;br /&gt;
&lt;br /&gt;
    cd /usr/share/php/data/PHP_CodeSniffer&lt;br /&gt;
    sudo mkdir PHP_CodeSniffer&lt;br /&gt;
    phpcs --config-set default_standard moodle&lt;br /&gt;
&lt;br /&gt;
Then start up Netbeans and it works!&lt;br /&gt;
&lt;br /&gt;
[[Image:codesniffer.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now when you restart your Netbeans you should see a new moodle coding standard. Right clicking on a file name should present you with a new option of &amp;quot;Show Code Standard Violations&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Simple example===&lt;br /&gt;
The script is located in lib/pear/PHP and is called runsniffer. To check the syntax of a given file (e.g. index.php), run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get a report that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AND 24 WARNING(S) AFFECTING 130 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
     1 | WARNING | $Id$ tag is no longer required, please remove.&lt;br /&gt;
    28 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | A cast statement must be followed by a single space&lt;br /&gt;
    55 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column shows the line at which the ERROR or WARNING was found. The CodeSniffer uses a set of rules which are still being defined, so that what is currently defined as ERROR or WARNING is likely to change in the near future. &lt;br /&gt;
&lt;br /&gt;
You should fix all ERRORs, but may safely ignore the WARNINGs. Fixing warnings will help your code be even more readable and consistent with other code that follow this standard.&lt;br /&gt;
&lt;br /&gt;
===Advanced Usage===&lt;br /&gt;
====Ignoring warnings====&lt;br /&gt;
You can run the CodeSniffer with the -n flag to ignore warnings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer -n index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resulting output:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AFFECTING 125 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
    28 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recursive analysis====&lt;br /&gt;
If you give the name of a folder instead of a file, it will search, analyse and report on all PHP files found in this folder and all its subfolders. This will produce a full report for each PHP file. Since this is likely to be too much information, you may want to print only a summary report, by using the following syntax (search the files/ folder as an example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Report:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/index.php                        11      58&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/draftfiles.php                   6       22&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 17 ERROR(S) AND 80 WARNING(S) WERE FOUND IN 2 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the -n flag to ignore warnings.&lt;br /&gt;
&lt;br /&gt;
====Several files in one folder====&lt;br /&gt;
If you want to search all files under a folder, but not recurse through the subfolders, you can use the -l flag (local files only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary -l grade&lt;br /&gt;
&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/index.php                        0       2&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/lib.php                          6       210&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/querylib.php                     5       39&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 11 ERROR(S) AND 251 WARNING(S) WERE FOUND IN 3 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can pass as many files and folders to the script as you want, the analysis and flags will apply to all of them.&lt;br /&gt;
&lt;br /&gt;
===Special rules===&lt;br /&gt;
When recursing through folders, the CodeSniffer script looks for a file called thirdpartylibs.xml. Currently there is only one, found under lib/. It lists directories and files which are meant to stay &#039;as-is&#039; in Moodle, in order to ensure minimum hassle when upgrading these libraries. You can use this file as a template to create your own list of exceptions.&lt;br /&gt;
&lt;br /&gt;
===Other report formats===&lt;br /&gt;
CodeSniffer can export its reports in the following formats:&lt;br /&gt;
#full: default, shown first above&lt;br /&gt;
#summary: also shown above&lt;br /&gt;
#xml: Simple XML format&lt;br /&gt;
#csv: Comma-separated list&lt;br /&gt;
#checkstyle: XML format intended for use with CruiseControl&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
#[[Coding]]&lt;br /&gt;
#[[Coding style]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36836</id>
		<title>CodeSniffer</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36836"/>
		<updated>2012-12-09T22:09:00Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: added location of linux folder&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
===Scope===&lt;br /&gt;
This document describes the CodeSniffing/Code checker tools their purpose and usage.&lt;br /&gt;
&lt;br /&gt;
===Function===&lt;br /&gt;
The function of the CodeSniffer tool is to analyse PHP5 (only) code, apply a set of rules that match the [[Coding_style | Moodle Coding Style]], and output a report showing which parts of the code do not conform to this style.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Using codechecker===&lt;br /&gt;
&lt;br /&gt;
codechecker is a local plugin that creates a web based interface for checking the syntax of a given file. It can be found at&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker&lt;br /&gt;
&lt;br /&gt;
Once installed a new codechecker option will appear in site administration\development page.&lt;br /&gt;
&lt;br /&gt;
This page allows for the code in a specified directory to be checked, e.g. if you wanted to check the code for the shortanswer question type you would enter&lt;br /&gt;
/question/type/shortanswer&lt;br /&gt;
&lt;br /&gt;
You would then be presented with a list of the count of files processed and any warnings or errors.&lt;br /&gt;
&lt;br /&gt;
===Installing codechecker===&lt;br /&gt;
&lt;br /&gt;
To install using git, type this command in the root of your Moodle install&lt;br /&gt;
    git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker&lt;br /&gt;
&lt;br /&gt;
Then edit .gitignore in your development folder eg: &lt;br /&gt;
    gedit /var/www/moodle/.gitignore&lt;br /&gt;
&lt;br /&gt;
And add /local/codechecker/ - including the slash at the end&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the zip from &lt;br /&gt;
&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker/zipball/master&lt;br /&gt;
&lt;br /&gt;
unzip it into the local folder, and then rename the new folder to codechecker.&lt;br /&gt;
&lt;br /&gt;
===Codechecker output===&lt;br /&gt;
&lt;br /&gt;
The output is similar to the following &lt;br /&gt;
&lt;br /&gt;
Files found: 21&lt;br /&gt;
&lt;br /&gt;
question\type\calculated\backup\moodle1\lib.php - 1 error(s) and 10 warning(s)&lt;br /&gt;
then a list of all files checked with a count of errors and warnings..followed by a summary&lt;br /&gt;
Total: 31 error(s) and 262 warning(s)&lt;br /&gt;
&lt;br /&gt;
Then a list describing the exact issue in each file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;question\type\calculated\backup\moodle1\lib.php&lt;br /&gt;
&lt;br /&gt;
2: The opening &amp;lt;?php tag must be followed by exactly one newline.&lt;br /&gt;
········//·convert·and·write·the·answers·first&lt;br /&gt;
50: Inline comments must start with a capital letter, digit or 3-dots sequence&lt;br /&gt;
etc etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;You can then edit the files to attempt to remove each issue.&lt;br /&gt;
&lt;br /&gt;
===IDE plugin alternatives===&lt;br /&gt;
&lt;br /&gt;
Using the web based interface means switching between the browser and the editing environment. You may find it easier to use a plugin that allows you to check your code against the standards as you go along. &lt;br /&gt;
&lt;br /&gt;
For Eclipse users&lt;br /&gt;
http://www.phpsrc.org/&lt;br /&gt;
&lt;br /&gt;
For Netbeans users&lt;br /&gt;
&lt;br /&gt;
Make sure you have the PEAR php Codesniffer code installed, you can find instructions at &lt;br /&gt;
http://pear.php.net/package/PHP_CodeSniffer/download/All&lt;br /&gt;
&lt;br /&gt;
Then install the netbeans plugin which can be found at &lt;br /&gt;
&lt;br /&gt;
https://github.com/beberlei/netbeans-php-enhancements/downloads&lt;br /&gt;
&lt;br /&gt;
Once installed you can check it within Netbeans by going to &lt;br /&gt;
Tools/Options/PHP and click on the codesniffer tab.&lt;br /&gt;
&lt;br /&gt;
There is an option for the codesniffer script. On my windows xampp install this needs to point to &lt;br /&gt;
&lt;br /&gt;
C:\xampp\php\phpcs.bat&lt;br /&gt;
&lt;br /&gt;
Underneath this should be a list of some of the coding standards available, but by default this will probably not include Moodle. To install the moodle standards copy the moodle folder from local\codechecker into your standards directory which for me was under&lt;br /&gt;
&lt;br /&gt;
php\PEAR\PHP\CodeSniffer\Standards&lt;br /&gt;
&lt;br /&gt;
Linux folder is&lt;br /&gt;
&lt;br /&gt;
/usr/share/php/PHP/CodeSniffer/Standards&lt;br /&gt;
&lt;br /&gt;
[[Image:codesniffer.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now when you restart your Netbeans you should see a new moodle coding standard. Right clicking on a file name should present you with a new option of &amp;quot;Show Code Standard Violations&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Simple example===&lt;br /&gt;
The script is located in lib/pear/PHP and is called runsniffer. To check the syntax of a given file (e.g. index.php), run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get a report that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AND 24 WARNING(S) AFFECTING 130 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
     1 | WARNING | $Id$ tag is no longer required, please remove.&lt;br /&gt;
    28 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | A cast statement must be followed by a single space&lt;br /&gt;
    55 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column shows the line at which the ERROR or WARNING was found. The CodeSniffer uses a set of rules which are still being defined, so that what is currently defined as ERROR or WARNING is likely to change in the near future. &lt;br /&gt;
&lt;br /&gt;
You should fix all ERRORs, but may safely ignore the WARNINGs. Fixing warnings will help your code be even more readable and consistent with other code that follow this standard.&lt;br /&gt;
&lt;br /&gt;
===Advanced Usage===&lt;br /&gt;
====Ignoring warnings====&lt;br /&gt;
You can run the CodeSniffer with the -n flag to ignore warnings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer -n index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resulting output:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AFFECTING 125 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
    28 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recursive analysis====&lt;br /&gt;
If you give the name of a folder instead of a file, it will search, analyse and report on all PHP files found in this folder and all its subfolders. This will produce a full report for each PHP file. Since this is likely to be too much information, you may want to print only a summary report, by using the following syntax (search the files/ folder as an example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Report:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/index.php                        11      58&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/draftfiles.php                   6       22&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 17 ERROR(S) AND 80 WARNING(S) WERE FOUND IN 2 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the -n flag to ignore warnings.&lt;br /&gt;
&lt;br /&gt;
====Several files in one folder====&lt;br /&gt;
If you want to search all files under a folder, but not recurse through the subfolders, you can use the -l flag (local files only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary -l grade&lt;br /&gt;
&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/index.php                        0       2&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/lib.php                          6       210&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/querylib.php                     5       39&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 11 ERROR(S) AND 251 WARNING(S) WERE FOUND IN 3 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can pass as many files and folders to the script as you want, the analysis and flags will apply to all of them.&lt;br /&gt;
&lt;br /&gt;
===Special rules===&lt;br /&gt;
When recursing through folders, the CodeSniffer script looks for a file called thirdpartylibs.xml. Currently there is only one, found under lib/. It lists directories and files which are meant to stay &#039;as-is&#039; in Moodle, in order to ensure minimum hassle when upgrading these libraries. You can use this file as a template to create your own list of exceptions.&lt;br /&gt;
&lt;br /&gt;
===Other report formats===&lt;br /&gt;
CodeSniffer can export its reports in the following formats:&lt;br /&gt;
#full: default, shown first above&lt;br /&gt;
#summary: also shown above&lt;br /&gt;
#xml: Simple XML format&lt;br /&gt;
#csv: Comma-separated list&lt;br /&gt;
#checkstyle: XML format intended for use with CruiseControl&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
#[[Coding]]&lt;br /&gt;
#[[Coding style]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36835</id>
		<title>CodeSniffer</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36835"/>
		<updated>2012-12-09T21:57:22Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: /* Installing codechecker */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
===Scope===&lt;br /&gt;
This document describes the CodeSniffing/Code checker tools their purpose and usage.&lt;br /&gt;
&lt;br /&gt;
===Function===&lt;br /&gt;
The function of the CodeSniffer tool is to analyse PHP5 (only) code, apply a set of rules that match the [[Coding_style | Moodle Coding Style]], and output a report showing which parts of the code do not conform to this style.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Using codechecker===&lt;br /&gt;
&lt;br /&gt;
codechecker is a local plugin that creates a web based interface for checking the syntax of a given file. It can be found at&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker&lt;br /&gt;
&lt;br /&gt;
Once installed a new codechecker option will appear in site administration\development page.&lt;br /&gt;
&lt;br /&gt;
This page allows for the code in a specified directory to be checked, e.g. if you wanted to check the code for the shortanswer question type you would enter&lt;br /&gt;
/question/type/shortanswer&lt;br /&gt;
&lt;br /&gt;
You would then be presented with a list of the count of files processed and any warnings or errors.&lt;br /&gt;
&lt;br /&gt;
===Installing codechecker===&lt;br /&gt;
&lt;br /&gt;
To install using git, type this command in the root of your Moodle install&lt;br /&gt;
    git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker&lt;br /&gt;
&lt;br /&gt;
Then edit .gitignore in your development folder eg: &lt;br /&gt;
    gedit /var/www/moodle/.gitignore&lt;br /&gt;
&lt;br /&gt;
And add /local/codechecker/ - including the slash at the end&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the zip from &lt;br /&gt;
&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker/zipball/master&lt;br /&gt;
&lt;br /&gt;
unzip it into the local folder, and then rename the new folder to codechecker.&lt;br /&gt;
&lt;br /&gt;
===Codechecker output===&lt;br /&gt;
&lt;br /&gt;
The output is similar to the following &lt;br /&gt;
&lt;br /&gt;
Files found: 21&lt;br /&gt;
&lt;br /&gt;
question\type\calculated\backup\moodle1\lib.php - 1 error(s) and 10 warning(s)&lt;br /&gt;
then a list of all files checked with a count of errors and warnings..followed by a summary&lt;br /&gt;
Total: 31 error(s) and 262 warning(s)&lt;br /&gt;
&lt;br /&gt;
Then a list describing the exact issue in each file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;question\type\calculated\backup\moodle1\lib.php&lt;br /&gt;
&lt;br /&gt;
2: The opening &amp;lt;?php tag must be followed by exactly one newline.&lt;br /&gt;
········//·convert·and·write·the·answers·first&lt;br /&gt;
50: Inline comments must start with a capital letter, digit or 3-dots sequence&lt;br /&gt;
etc etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;You can then edit the files to attempt to remove each issue.&lt;br /&gt;
&lt;br /&gt;
===IDE plugin alternatives===&lt;br /&gt;
&lt;br /&gt;
Using the web based interface means switching between the browser and the editing environment. You may find it easier to use a plugin that allows you to check your code against the standards as you go along. &lt;br /&gt;
&lt;br /&gt;
For Eclipse users&lt;br /&gt;
http://www.phpsrc.org/&lt;br /&gt;
&lt;br /&gt;
For Netbeans users&lt;br /&gt;
&lt;br /&gt;
Make sure you have the PEAR php Codesniffer code installed, you can find instructions at &lt;br /&gt;
http://pear.php.net/package/PHP_CodeSniffer/download/All&lt;br /&gt;
&lt;br /&gt;
Then install the netbeans plugin which can be found at &lt;br /&gt;
&lt;br /&gt;
https://github.com/beberlei/netbeans-php-enhancements/downloads&lt;br /&gt;
&lt;br /&gt;
Once installed you can check it within Netbeans by going to &lt;br /&gt;
Tools/Options/PHP and click on the codesniffer tab.&lt;br /&gt;
&lt;br /&gt;
There is an option for the codesniffer script. On my windows xampp install this needs to point to &lt;br /&gt;
&lt;br /&gt;
C:\xampp\php\phpcs.bat&lt;br /&gt;
&lt;br /&gt;
Underneath this should be a list of some of the coding standards available, but by default this will probably not include Moodle. To install the moodle standards copy the moodle folder from local\codechecker into your standards directory which for me was under&lt;br /&gt;
&lt;br /&gt;
php\PEAR\PHP\CodeSniffer\Standards&lt;br /&gt;
&lt;br /&gt;
[[Image:codesniffer.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now when you restart your Netbeans you should see a new moodle coding standard. Right clicking on a file name should present you with a new option of &amp;quot;Show Code Standard Violations&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Simple example===&lt;br /&gt;
The script is located in lib/pear/PHP and is called runsniffer. To check the syntax of a given file (e.g. index.php), run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get a report that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AND 24 WARNING(S) AFFECTING 130 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
     1 | WARNING | $Id$ tag is no longer required, please remove.&lt;br /&gt;
    28 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | A cast statement must be followed by a single space&lt;br /&gt;
    55 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column shows the line at which the ERROR or WARNING was found. The CodeSniffer uses a set of rules which are still being defined, so that what is currently defined as ERROR or WARNING is likely to change in the near future. &lt;br /&gt;
&lt;br /&gt;
You should fix all ERRORs, but may safely ignore the WARNINGs. Fixing warnings will help your code be even more readable and consistent with other code that follow this standard.&lt;br /&gt;
&lt;br /&gt;
===Advanced Usage===&lt;br /&gt;
====Ignoring warnings====&lt;br /&gt;
You can run the CodeSniffer with the -n flag to ignore warnings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer -n index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resulting output:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AFFECTING 125 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
    28 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recursive analysis====&lt;br /&gt;
If you give the name of a folder instead of a file, it will search, analyse and report on all PHP files found in this folder and all its subfolders. This will produce a full report for each PHP file. Since this is likely to be too much information, you may want to print only a summary report, by using the following syntax (search the files/ folder as an example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Report:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/index.php                        11      58&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/draftfiles.php                   6       22&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 17 ERROR(S) AND 80 WARNING(S) WERE FOUND IN 2 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the -n flag to ignore warnings.&lt;br /&gt;
&lt;br /&gt;
====Several files in one folder====&lt;br /&gt;
If you want to search all files under a folder, but not recurse through the subfolders, you can use the -l flag (local files only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary -l grade&lt;br /&gt;
&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/index.php                        0       2&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/lib.php                          6       210&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/querylib.php                     5       39&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 11 ERROR(S) AND 251 WARNING(S) WERE FOUND IN 3 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can pass as many files and folders to the script as you want, the analysis and flags will apply to all of them.&lt;br /&gt;
&lt;br /&gt;
===Special rules===&lt;br /&gt;
When recursing through folders, the CodeSniffer script looks for a file called thirdpartylibs.xml. Currently there is only one, found under lib/. It lists directories and files which are meant to stay &#039;as-is&#039; in Moodle, in order to ensure minimum hassle when upgrading these libraries. You can use this file as a template to create your own list of exceptions.&lt;br /&gt;
&lt;br /&gt;
===Other report formats===&lt;br /&gt;
CodeSniffer can export its reports in the following formats:&lt;br /&gt;
#full: default, shown first above&lt;br /&gt;
#summary: also shown above&lt;br /&gt;
#xml: Simple XML format&lt;br /&gt;
#csv: Comma-separated list&lt;br /&gt;
#checkstyle: XML format intended for use with CruiseControl&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
#[[Coding]]&lt;br /&gt;
#[[Coding style]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36834</id>
		<title>CodeSniffer</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=CodeSniffer&amp;diff=36834"/>
		<updated>2012-12-09T21:56:56Z</updated>

		<summary type="html">&lt;p&gt;RussellEngland: added the install instructions from https://github.com/moodlehq/moodle-local_codechecker#readme&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
===Scope===&lt;br /&gt;
This document describes the CodeSniffing/Code checker tools their purpose and usage.&lt;br /&gt;
&lt;br /&gt;
===Function===&lt;br /&gt;
The function of the CodeSniffer tool is to analyse PHP5 (only) code, apply a set of rules that match the [[Coding_style | Moodle Coding Style]], and output a report showing which parts of the code do not conform to this style.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Using codechecker===&lt;br /&gt;
&lt;br /&gt;
codechecker is a local plugin that creates a web based interface for checking the syntax of a given file. It can be found at&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker&lt;br /&gt;
&lt;br /&gt;
Once installed a new codechecker option will appear in site administration\development page.&lt;br /&gt;
&lt;br /&gt;
This page allows for the code in a specified directory to be checked, e.g. if you wanted to check the code for the shortanswer question type you would enter&lt;br /&gt;
/question/type/shortanswer&lt;br /&gt;
&lt;br /&gt;
You would then be presented with a list of the count of files processed and any warnings or errors.&lt;br /&gt;
&lt;br /&gt;
===Installing codechecker===&lt;br /&gt;
&lt;br /&gt;
To install using git, type this command in the root of your Moodle install&lt;br /&gt;
    git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker&lt;br /&gt;
&lt;br /&gt;
Then edit .gitignore in your development folder eg: gedit /var/www/moodle/.gitignore&lt;br /&gt;
&lt;br /&gt;
And add /local/codechecker/ - including the slash at the end&lt;br /&gt;
&lt;br /&gt;
Alternatively, download the zip from &lt;br /&gt;
&lt;br /&gt;
https://github.com/moodlehq/moodle-local_codechecker/zipball/master&lt;br /&gt;
&lt;br /&gt;
unzip it into the local folder, and then rename the new folder to codechecker.&lt;br /&gt;
&lt;br /&gt;
===Codechecker output===&lt;br /&gt;
&lt;br /&gt;
The output is similar to the following &lt;br /&gt;
&lt;br /&gt;
Files found: 21&lt;br /&gt;
&lt;br /&gt;
question\type\calculated\backup\moodle1\lib.php - 1 error(s) and 10 warning(s)&lt;br /&gt;
then a list of all files checked with a count of errors and warnings..followed by a summary&lt;br /&gt;
Total: 31 error(s) and 262 warning(s)&lt;br /&gt;
&lt;br /&gt;
Then a list describing the exact issue in each file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;question\type\calculated\backup\moodle1\lib.php&lt;br /&gt;
&lt;br /&gt;
2: The opening &amp;lt;?php tag must be followed by exactly one newline.&lt;br /&gt;
········//·convert·and·write·the·answers·first&lt;br /&gt;
50: Inline comments must start with a capital letter, digit or 3-dots sequence&lt;br /&gt;
etc etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;You can then edit the files to attempt to remove each issue.&lt;br /&gt;
&lt;br /&gt;
===IDE plugin alternatives===&lt;br /&gt;
&lt;br /&gt;
Using the web based interface means switching between the browser and the editing environment. You may find it easier to use a plugin that allows you to check your code against the standards as you go along. &lt;br /&gt;
&lt;br /&gt;
For Eclipse users&lt;br /&gt;
http://www.phpsrc.org/&lt;br /&gt;
&lt;br /&gt;
For Netbeans users&lt;br /&gt;
&lt;br /&gt;
Make sure you have the PEAR php Codesniffer code installed, you can find instructions at &lt;br /&gt;
http://pear.php.net/package/PHP_CodeSniffer/download/All&lt;br /&gt;
&lt;br /&gt;
Then install the netbeans plugin which can be found at &lt;br /&gt;
&lt;br /&gt;
https://github.com/beberlei/netbeans-php-enhancements/downloads&lt;br /&gt;
&lt;br /&gt;
Once installed you can check it within Netbeans by going to &lt;br /&gt;
Tools/Options/PHP and click on the codesniffer tab.&lt;br /&gt;
&lt;br /&gt;
There is an option for the codesniffer script. On my windows xampp install this needs to point to &lt;br /&gt;
&lt;br /&gt;
C:\xampp\php\phpcs.bat&lt;br /&gt;
&lt;br /&gt;
Underneath this should be a list of some of the coding standards available, but by default this will probably not include Moodle. To install the moodle standards copy the moodle folder from local\codechecker into your standards directory which for me was under&lt;br /&gt;
&lt;br /&gt;
php\PEAR\PHP\CodeSniffer\Standards&lt;br /&gt;
&lt;br /&gt;
[[Image:codesniffer.jpg]]&lt;br /&gt;
&lt;br /&gt;
Now when you restart your Netbeans you should see a new moodle coding standard. Right clicking on a file name should present you with a new option of &amp;quot;Show Code Standard Violations&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Simple example===&lt;br /&gt;
The script is located in lib/pear/PHP and is called runsniffer. To check the syntax of a given file (e.g. index.php), run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will get a report that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AND 24 WARNING(S) AFFECTING 130 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
     1 | WARNING | $Id$ tag is no longer required, please remove.&lt;br /&gt;
    28 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR   | A cast statement must be followed by a single space&lt;br /&gt;
    55 | ERROR   | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first column shows the line at which the ERROR or WARNING was found. The CodeSniffer uses a set of rules which are still being defined, so that what is currently defined as ERROR or WARNING is likely to change in the near future. &lt;br /&gt;
&lt;br /&gt;
You should fix all ERRORs, but may safely ignore the WARNINGs. Fixing warnings will help your code be even more readable and consistent with other code that follow this standard.&lt;br /&gt;
&lt;br /&gt;
===Advanced Usage===&lt;br /&gt;
====Ignoring warnings====&lt;br /&gt;
You can run the CodeSniffer with the -n flag to ignore warnings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer -n index.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Resulting output:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FOUND 139 ERROR(S) AFFECTING 125 LINE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
    28 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
    50 | ERROR | line indented incorrectly; expected 0 spaces, found 4&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Recursive analysis====&lt;br /&gt;
If you give the name of a folder instead of a file, it will search, analyse and report on all PHP files found in this folder and all its subfolders. This will produce a full report for each PHP file. Since this is likely to be too much information, you may want to print only a summary report, by using the following syntax (search the files/ folder as an example):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Report:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/index.php                        11      58&lt;br /&gt;
  /web/htdocs/moodle_blog2/files/draftfiles.php                   6       22&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 17 ERROR(S) AND 80 WARNING(S) WERE FOUND IN 2 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use the -n flag to ignore warnings.&lt;br /&gt;
&lt;br /&gt;
====Several files in one folder====&lt;br /&gt;
If you want to search all files under a folder, but not recurse through the subfolders, you can use the -l flag (local files only):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
lib/pear/PHP/runsniffer --report=summary -l grade&lt;br /&gt;
&lt;br /&gt;
  PHP CODE SNIFFER REPORT SUMMARY&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  FILE                                                            ERRORS  WARNINGS&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/index.php                        0       2&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/lib.php                          6       210&lt;br /&gt;
  /web/htdocs/moodle_blog2/grade/querylib.php                     5       39&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
  A TOTAL OF 11 ERROR(S) AND 251 WARNING(S) WERE FOUND IN 3 FILE(S)&lt;br /&gt;
  --------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can pass as many files and folders to the script as you want, the analysis and flags will apply to all of them.&lt;br /&gt;
&lt;br /&gt;
===Special rules===&lt;br /&gt;
When recursing through folders, the CodeSniffer script looks for a file called thirdpartylibs.xml. Currently there is only one, found under lib/. It lists directories and files which are meant to stay &#039;as-is&#039; in Moodle, in order to ensure minimum hassle when upgrading these libraries. You can use this file as a template to create your own list of exceptions.&lt;br /&gt;
&lt;br /&gt;
===Other report formats===&lt;br /&gt;
CodeSniffer can export its reports in the following formats:&lt;br /&gt;
#full: default, shown first above&lt;br /&gt;
#summary: also shown above&lt;br /&gt;
#xml: Simple XML format&lt;br /&gt;
#csv: Comma-separated list&lt;br /&gt;
#checkstyle: XML format intended for use with CruiseControl&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
#[[Coding]]&lt;br /&gt;
#[[Coding style]]&lt;/div&gt;</summary>
		<author><name>RussellEngland</name></author>
	</entry>
</feed>