Merge pull request #5076 from colemanw/Attachment
[civicrm-core.git] / CRM / Core / DAO.php
index 18a4cffd5a32115ec08952b30bd255a220506d1e..54f85cc25fe33d859eafdc00eb2d58455da2aa75 100644 (file)
@@ -23,7 +23,7 @@
   | GNU Affero General Public License or the licensing of CiviCRM,     |
   | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
   +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * Our base DAO class. All DAO classes should inherit from this class.
@@ -52,20 +52,21 @@ class CRM_Core_DAO extends DB_DataObject {
 
   static $_dbColumnValueCache = NULL;
   const NOT_NULL = 1, IS_NULL = 2,
-  DB_DAO_NOTNULL = 128,
-  VALUE_SEPARATOR = "\ 1",
-  BULK_INSERT_COUNT = 200,
-  BULK_INSERT_HIGH_COUNT = 200,
-  // special value for mail bulk inserts to avoid
-  // potential duplication, assuming a smaller number reduces number of queries
-  // by some factor, so some tradeoff. CRM-8678
-  BULK_MAIL_INSERT_COUNT = 10,
-  QUERY_FORMAT_WILDCARD = 1,
-  QUERY_FORMAT_NO_QUOTES = 2;
-
-  /*
+    DB_DAO_NOTNULL = 128,
+    VALUE_SEPARATOR = "\ 1",
+    BULK_INSERT_COUNT = 200,
+    BULK_INSERT_HIGH_COUNT = 200,
+    // special value for mail bulk inserts to avoid
+    // potential duplication, assuming a smaller number reduces number of queries
+    // by some factor, so some tradeoff. CRM-8678
+    BULK_MAIL_INSERT_COUNT = 10,
+    QUERY_FORMAT_WILDCARD = 1,
+    QUERY_FORMAT_NO_QUOTES = 2;
+
+  /**
    * Define entities that shouldn't be created or deleted when creating/ deleting
-   *  test objects - this prevents world regions, countries etc from being added / deleted
+   * test objects - this prevents world regions, countries etc from being added / deleted
+   * @var array
    */
   static $_testEntitiesToSkip = array();
   /**
@@ -80,7 +81,6 @@ class CRM_Core_DAO extends DB_DataObject {
    * Class constructor
    *
    * @return \CRM_Core_DAO
-  @access public
    */
   public function __construct() {
     $this->initialize();
@@ -101,7 +101,6 @@ class CRM_Core_DAO extends DB_DataObject {
    *   The database connection string.
    *
    * @return void
-   * @static
    */
   public static function init($dsn) {
     $options = &PEAR::getStaticProperty('DB_DataObject', 'options');
@@ -130,7 +129,7 @@ class CRM_Core_DAO extends DB_DataObject {
       $required = TRUE;
     }
     if (!$required && $dbName != 'contact_id') {
-      $fkDAO = new $FKClassName;
+      $fkDAO = new $FKClassName();
       if ($fkDAO->find(TRUE)) {
         $this->$dbName = $fkDAO->id;
       }
@@ -222,8 +221,8 @@ class CRM_Core_DAO extends DB_DataObject {
 
         case CRM_Utils_Type::T_TIME:
           CRM_Core_Error::fatal('T_TIME shouldnt be used.');
-        //$object->$dbName='000000';
-        //break;
+          //$object->$dbName='000000';
+          //break;
         case CRM_Utils_Type::T_CCNUM:
           $this->$dbName = '4111 1111 1111 1111';
           break;
@@ -333,7 +332,6 @@ class CRM_Core_DAO extends DB_DataObject {
    *   The factory application object.
    *
    * @return void
-   * @static
    */
   public static function setFactory(&$factory) {
     self::$_factory = &$factory;
@@ -397,10 +395,9 @@ class CRM_Core_DAO extends DB_DataObject {
   /**
    * Returns list of FK relationships
    *
-   * @static
    *
    * @return array
-   *   of CRM_Core_Reference_Interface
+   *   Array of CRM_Core_Reference_Interface
    */
   public static function getReferenceColumns() {
     return array();
@@ -412,7 +409,7 @@ class CRM_Core_DAO extends DB_DataObject {
    *
    * @return array
    */
-   static function &fields() {
+  public static function &fields() {
     $result = NULL;
     return $result;
   }
@@ -420,7 +417,6 @@ class CRM_Core_DAO extends DB_DataObject {
   /**
    * Get/set an associative array of table columns
    *
-   * @param array key=>type array
    * @return array
    *   (associative)
    */
@@ -463,6 +459,31 @@ class CRM_Core_DAO extends DB_DataObject {
     return $this;
   }
 
+  /**
+   * Deletes items from table which match current objects variables
+   *
+   * Returns the true on success
+   *
+   * for example
+   *
+   * Designed to be extended
+   *
+   * $object = new mytable();
+   * $object->ID=123;
+   * echo $object->delete(); // builds a conditon
+   *
+   * $object = new mytable();
+   * $object->whereAdd('age > 12');
+   * $object->limit(1);
+   * $object->orderBy('age DESC');
+   * $object->delete(true); // dont use object vars, use the conditions, limit and order.
+   *
+   * @param bool $useWhere (optional) If DB_DATAOBJECT_WHEREADD_ONLY is passed in then
+   *             we will build the condition only using the whereAdd's.  Default is to
+   *             build the condition only using the object parameters.
+   *
+   *     * @return mixed Int (No. of rows affected) on success, false on failure, 0 on no data affected
+   */
   public function delete($useWhere = FALSE) {
     $result = parent::delete($useWhere);
 
@@ -492,10 +513,10 @@ class CRM_Core_DAO extends DB_DataObject {
       return;
     }
 
-    $dao                = new CRM_Core_DAO_Log();
-    $dao->entity_table  = $this->getTableName();
-    $dao->entity_id     = $this->id;
-    $dao->modified_id   = $cid;
+    $dao = new CRM_Core_DAO_Log();
+    $dao->entity_table = $this->getTableName();
+    $dao->entity_id = $this->id;
+    $dao->modified_id = $cid;
     $dao->modified_date = date("YmdHis");
     $dao->insert();
   }
@@ -507,8 +528,8 @@ class CRM_Core_DAO extends DB_DataObject {
    * @param array $params
    *   (reference ) associative array of name/value pairs.
    *
-   * @return boolean
-   *   did we copy all null values into the object
+   * @return bool
+   *   Did we copy all null values into the object
    */
   public function copyValues(&$params) {
     $fields = &$this->fields();
@@ -552,7 +573,6 @@ class CRM_Core_DAO extends DB_DataObject {
    *   (reference ) associative array of name/value pairs.
    *
    * @return void
-   * @static
    */
   public static function storeValues(&$object, &$values) {
     $fields = &$object->fields();
@@ -573,8 +593,8 @@ class CRM_Core_DAO extends DB_DataObject {
    * @param array $field
    *   The field under task.
    *
-   * @return array|null the attributes for the object
-   * @static
+   * @return array|null
+   *   the attributes for the object
    */
   public static function makeAttribute($field) {
     if ($field) {
@@ -602,7 +622,7 @@ class CRM_Core_DAO extends DB_DataObject {
           $cols = 80;
         }
 
-        $attributes         = array();
+        $attributes = array();
         $attributes['rows'] = $rows;
         $attributes['cols'] = $cols;
         return $attributes;
@@ -617,7 +637,7 @@ class CRM_Core_DAO extends DB_DataObject {
   }
 
   /**
-   * Get the size and maxLength attributes for this text field
+   * Get the size and maxLength attributes for this text field.
    * (or for all text fields) in the DAO object.
    *
    * @param string $class
@@ -628,10 +648,9 @@ class CRM_Core_DAO extends DB_DataObject {
    *
    * @return array
    *   assoc array of name => attribute pairs
-   * @static
    */
   public static function getAttribute($class, $fieldName = NULL) {
-    $object = new $class( );
+    $object = new $class();
     $fields = &$object->fields();
     if ($fieldName != NULL) {
       $field = CRM_Utils_Array::value($fieldName, $fields);
@@ -675,12 +694,11 @@ class CRM_Core_DAO extends DB_DataObject {
    * @param string $fieldName
    *   The name of the field in the DAO.
    *
-   * @return boolean
+   * @return bool
    *   true if object exists
-   * @static
    */
   public static function objectExists($value, $daoName, $daoID, $fieldName = 'name') {
-    $object = new $daoName( );
+    $object = new $daoName();
     $object->$fieldName = $value;
 
     $config = CRM_Core_Config::singleton();
@@ -701,9 +719,8 @@ class CRM_Core_DAO extends DB_DataObject {
    * @param bool $i18nRewrite
    *   Whether to rewrite the query on multilingual setups.
    *
-   * @return boolean
+   * @return bool
    *   true if exists, else false
-   * @static
    */
   public static function checkFieldExists($tableName, $columnName, $i18nRewrite = TRUE) {
     $query = "
@@ -712,7 +729,7 @@ FROM $tableName
 LIKE %1
 ";
     $params = array(1 => array($columnName, 'String'));
-    $dao    = CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, $i18nRewrite);
+    $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, $i18nRewrite);
     $result = $dao->fetch() ? TRUE : FALSE;
     $dao->free();
     return $result;
@@ -729,7 +746,6 @@ LIKE %1
    * @param string $fieldName
    *
    * @return array
-   * @static
    */
   public static function getStorageValues($tableName = NULL, $maxTablesToCheck = 10, $fieldName = 'Engine') {
     $values = array();
@@ -787,9 +803,8 @@ LIKE %1
    * @param string $tableName
    * @param string $constraint
    *
-   * @return boolean
+   * @return bool
    *   true if constraint exists, false otherwise
-   * @static
    */
   public static function checkConstraintExists($tableName, $constraint) {
     static $show = array();
@@ -816,7 +831,7 @@ LIKE %1
    *
    * @throws Exception
    *
-   * @return boolean
+   * @return bool
    *   true if CONSTRAINT keyword exists, false otherwise
    */
   public static function schemaRequiresRebuilding($tables = array("civicrm_contact")) {
@@ -852,9 +867,8 @@ LIKE %1
    * @param string $tableName
    * @param string $columnName
    *
-   * @return boolean
+   * @return bool
    *   true if in format, false otherwise
-   * @static
    */
   public static function checkFKConstraintInFormat($tableName, $columnName) {
     static $show = array();
@@ -872,7 +886,7 @@ LIKE %1
     }
     $constraint = "`FK_{$tableName}_{$columnName}`";
     $pattern = "/\bCONSTRAINT\b\s+%s\s+\bFOREIGN\s+KEY\b\s/i";
-    return preg_match(sprintf($pattern, $constraint),$show[$tableName]) ? TRUE : FALSE;
+    return preg_match(sprintf($pattern, $constraint), $show[$tableName]) ? TRUE : FALSE;
   }
 
   /**
@@ -882,13 +896,12 @@ LIKE %1
    * @param string $columnName
    * @param string $columnValue
    *
-   * @return boolean
+   * @return bool
    *   true if the value is always $columnValue, false otherwise
-   * @static
    */
   public static function checkFieldHasAlwaysValue($tableName, $columnName, $columnValue) {
-    $query  = "SELECT * FROM $tableName WHERE $columnName != '$columnValue'";
-    $dao    = CRM_Core_DAO::executeQuery($query);
+    $query = "SELECT * FROM $tableName WHERE $columnName != '$columnValue'";
+    $dao = CRM_Core_DAO::executeQuery($query);
     $result = $dao->fetch() ? FALSE : TRUE;
     $dao->free();
     return $result;
@@ -900,13 +913,12 @@ LIKE %1
    * @param string $tableName
    * @param string $columnName
    *
-   * @return boolean
+   * @return bool
    *   true if if the value is always NULL, false otherwise
-   * @static
    */
   public static function checkFieldIsAlwaysNull($tableName, $columnName) {
-    $query  = "SELECT * FROM $tableName WHERE $columnName IS NOT NULL";
-    $dao    = CRM_Core_DAO::executeQuery($query);
+    $query = "SELECT * FROM $tableName WHERE $columnName IS NOT NULL";
+    $dao = CRM_Core_DAO::executeQuery($query);
     $result = $dao->fetch() ? FALSE : TRUE;
     $dao->free();
     return $result;
@@ -917,9 +929,8 @@ LIKE %1
    *
    * @param string $tableName
    *
-   * @return boolean
+   * @return bool
    *   true if exists, else false
-   * @static
    */
   public static function checkTableExists($tableName) {
     $query = "
@@ -980,8 +991,8 @@ FROM   civicrm_domain
    * @param bool $force
    *   Skip use of the cache.
    *
-   * @return string|null          Value of $returnColumn in the retrieved record
-   * @static
+   * @return string|null
+   *   Value of $returnColumn in the retrieved record
    */
   public static function getFieldValue($daoName, $searchValue, $returnColumn = 'name', $searchColumn = 'id', $force = FALSE) {
     if (
@@ -1000,7 +1011,7 @@ FROM   civicrm_domain
     }
 
     if (!array_key_exists($cacheKey, self::$_dbColumnValueCache) || $force) {
-      $object   = new $daoName( );
+      $object = new $daoName();
       $object->$searchColumn = $searchValue;
       $object->selectAdd();
       $object->selectAdd($returnColumn);
@@ -1030,12 +1041,11 @@ FROM   civicrm_domain
    * @param string $searchColumn
    *   Name of the column you want to search by.
    *
-   * @return boolean
+   * @return bool
    *   true if we found and updated the object, else false
-   * @static
    */
   public static function setFieldValue($daoName, $searchValue, $setColumn, $setValue, $searchColumn = 'id') {
-    $object = new $daoName( );
+    $object = new $daoName();
     $object->selectAdd();
     $object->selectAdd("$searchColumn, $setColumn");
     $object->$searchColumn = $searchValue;
@@ -1059,7 +1069,6 @@ FROM   civicrm_domain
    *
    * @return string
    *   sortString
-   * @static
    */
   public static function getSortString($sort, $default = NULL) {
     // check if sort is of type CRM_Utils_Sort
@@ -1091,10 +1100,9 @@ FROM   civicrm_domain
    *
    * @return object
    *   an object of type referenced by daoName
-   * @static
    */
   public static function commonRetrieve($daoName, &$params, &$defaults, $returnProperities = NULL) {
-    $object = new $daoName( );
+    $object = new $daoName();
     $object->copyValues($params);
 
     // return only specific fields if returnproperties are sent
@@ -1119,10 +1127,9 @@ FROM   civicrm_domain
    *   Id of the contact to delete.
    *
    * @return void
-   * @static
    */
   public static function deleteEntityContact($daoName, $contactId) {
-    $object = new $daoName( );
+    $object = new $daoName();
 
     $object->entity_table = 'civicrm_contact';
     $object->entity_id = $contactId;
@@ -1142,16 +1149,18 @@ FROM   civicrm_domain
    * @param bool $i18nRewrite
    * @param bool $trapException
    *
-   * @return CRM_Core_DAO object that holds the results of the query
-   * @static
+   * @return CRM_Core_DAO|object
+   *   object that holds the results of the query
+   *   NB - if this is defined as just returning a DAO phpstorm keeps pointing
+   *   out all the properties that are not part of the DAO
    */
-  static function &executeQuery(
+  public static function &executeQuery(
     $query,
-    $params        = array(),
-    $abort         = TRUE,
-    $daoName       = NULL,
-    $freeDAO       = FALSE,
-    $i18nRewrite   = TRUE,
+    $params = array(),
+    $abort = TRUE,
+    $daoName = NULL,
+    $freeDAO = FALSE,
+    $i18nRewrite = TRUE,
     $trapException = FALSE
   ) {
     $queryStr = self::composeQuery($query, $params, $abort);
@@ -1160,7 +1169,7 @@ FROM   civicrm_domain
       $dao = new CRM_Core_DAO();
     }
     else {
-      $dao = new $daoName( );
+      $dao = new $daoName();
     }
 
     if ($trapException) {
@@ -1176,7 +1185,7 @@ FROM   civicrm_domain
     if ($freeDAO ||
       preg_match('/^(insert|update|delete|create|drop|replace)/i', $queryStr)
     ) {
-      // we typically do this for insert/update/delete stataments OR if explicitly asked to
+      // we typically do this for insert/update/delete statements OR if explicitly asked to
       // free the dao
       $dao->free();
     }
@@ -1191,14 +1200,14 @@ FROM   civicrm_domain
    * @param array $params
    * @param bool $abort
    * @param bool $i18nRewrite
-   * @return string|null the result of the query if any
+   * @return string|null
+   *   the result of the query if any
    *
-   * @static
    */
-  static function &singleValueQuery(
+  public static function &singleValueQuery(
     $query,
-    $params      = array(),
-    $abort       = TRUE,
+    $params = array(),
+    $abort = TRUE,
     $i18nRewrite = TRUE
   ) {
     $queryStr = self::composeQuery($query, $params, $abort);
@@ -1305,7 +1314,7 @@ FROM   civicrm_domain
   }
 
   /**
-   * make a shallow copy of an object
+   * make a shallow copy of an object.
    * and all the fields in the object
    *
    * @param string $daoName
@@ -1323,10 +1332,11 @@ FROM   civicrm_domain
    *                                        getting copied
    *
    *
-   * @return (reference )                   the newly created copy of the object
+   * @return CRM_Core_DAO
+   *   the newly created copy of the object
    */
-  static function &copyGeneric($daoName, $criteria, $newData = NULL, $fieldsFix = NULL, $blockCopyOfDependencies = NULL) {
-    $object = new $daoName( );
+  public static function &copyGeneric($daoName, $criteria, $newData = NULL, $fieldsFix = NULL, $blockCopyOfDependencies = NULL) {
+    $object = new $daoName();
     if (!$newData) {
       $object->id = $criteria['id'];
     }
@@ -1346,12 +1356,12 @@ FROM   civicrm_domain
         break;
       }
 
-      $newObject   = new $daoName( );
+      $newObject = new $daoName();
 
       $fields = &$object->fields();
       if (!is_array($fieldsFix)) {
-        $fieldsToPrefix  = array();
-        $fieldsToSuffix  = array();
+        $fieldsToPrefix = array();
+        $fieldsToSuffix = array();
         $fieldsToReplace = array();
       }
       if (!empty($fieldsFix['prefix'])) {
@@ -1398,12 +1408,22 @@ FROM   civicrm_domain
     return $newObject;
   }
 
+  /**
+   * Cascade update through related entities.
+   *
+   * @param string $daoName
+   * @param $fromId
+   * @param $toId
+   * @param array $newData
+   *
+   * @return null
+   */
   public static function cascadeUpdate($daoName, $fromId, $toId, $newData = array()) {
-    $object = new $daoName( );
+    $object = new $daoName();
     $object->id = $fromId;
 
     if ($object->find(TRUE)) {
-      $newObject = new $daoName( );
+      $newObject = new $daoName();
       $newObject->id = $toId;
 
       if ($newObject->find(TRUE)) {
@@ -1476,11 +1496,10 @@ SELECT contact_id
    *
    * @return object
    *   an object of type referenced by daoName
-   * @static
    */
   public static function commonRetrieveAll($daoName, $fieldIdName = 'id', $fieldId, &$details, $returnProperities = NULL) {
-    require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php");
-    $object = new $daoName( );
+    require_once str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php";
+    $object = new $daoName();
     $object->$fieldIdName = $fieldId;
 
     // return only specific fields if returnproperties are sent
@@ -1582,7 +1601,8 @@ SELECT contact_id
     // note that mysql does not escape these characters
     if ($string && in_array($string,
         array('%', '_', '%%', '_%')
-      )) {
+      )
+    ) {
       return '\\' . $string;
     }
 
@@ -1599,9 +1619,10 @@ SELECT contact_id
    * @param int $numObjects
    * @param bool $createOnly
    *
-   * @return
+   * @return object|array|NULL
+   *   NULL if $createOnly. A single object if $numObjects==1. Otherwise, an array of multiple objects.
    */
-  static function createTestObject(
+  public static function createTestObject(
     $daoName,
     $params = array(),
     $numObjects = 1,
@@ -1618,7 +1639,8 @@ SELECT contact_id
       'CRM_Core_DAO_StateProvince',
       'CRM_Core_DAO_Country',
       'CRM_Core_DAO_Domain',
-      'CRM_Financial_DAO_FinancialType'//because valid ones exist & we use pick them due to pseudoconstant can't reliably create & delete these
+      'CRM_Financial_DAO_FinancialType',
+      //because valid ones exist & we use pick them due to pseudoconstant can't reliably create & delete these
     );
 
     // Prefer to instantiate BAO's instead of DAO's (when possible)
@@ -1634,7 +1656,7 @@ SELECT contact_id
       /** @var CRM_Core_DAO $object */
       $object = new $daoName();
 
-      $fields = & $object->fields();
+      $fields = &$object->fields();
       foreach ($fields as $fieldName => $fieldDef) {
         $dbName = $fieldDef['name'];
         $FKClassName = CRM_Utils_Array::value('FKClassName', $fieldDef);
@@ -1666,7 +1688,7 @@ SELECT contact_id
     }
 
     if ($createOnly) {
-      return;
+      return NULL;
     }
     elseif ($numObjects == 1) {
       return $objects[0];
@@ -1708,7 +1730,8 @@ SELECT contact_id
           && ($required || $dbName == 'contact_id')
           //I'm a bit stuck on this one - we might need to change the singleValueAlter so that the entities don't share a contact
           // to make this test process pass - line below makes pass for now
-          && $dbName != 'member_of_contact_id') {
+          && $dbName != 'member_of_contact_id'
+        ) {
           $deletions[] = array($FKClassName, array('id' => $object->$dbName)); // x
         }
       }
@@ -1718,7 +1741,7 @@ SELECT contact_id
 
     foreach ($deletions as $deletion) {
       CRM_Core_DAO::deleteTestObjects($deletion[0], $deletion[1]);
-  }
+    }
   }
 
   /**
@@ -1837,7 +1860,7 @@ SELECT contact_id
   public static function triggerRebuild($tableName = NULL, $force = FALSE) {
     $info = array();
 
-    $logging = new CRM_Logging_Schema;
+    $logging = new CRM_Logging_Schema();
     $logging->triggerInfo($info, $tableName, $force);
 
     CRM_Core_I18n_Schema::triggerInfo($info, $tableName);
@@ -1878,7 +1901,7 @@ SELECT contact_id
   public static function dropTriggers($tableName = NULL) {
     $info = array();
 
-    $logging = new CRM_Logging_Schema;
+    $logging = new CRM_Logging_Schema();
     $logging->triggerInfo($info, $tableName);
 
     // drop all existing triggers on all tables
@@ -1976,11 +1999,11 @@ SELECT contact_id
       }
       foreach ($tables as $eventName => $events) {
         foreach ($events as $whenName => $parts) {
-          $varString   = implode("\n", $parts['variables']);
-          $sqlString   = implode("\n", $parts['sql']);
-          $validName   = CRM_Core_DAO::shortenSQLName($tableName, 48, TRUE);
+          $varString = implode("\n", $parts['variables']);
+          $sqlString = implode("\n", $parts['sql']);
+          $validName = CRM_Core_DAO::shortenSQLName($tableName, 48, TRUE);
           $triggerName = "{$validName}_{$whenName}_{$eventName}";
-          $triggerSQL  = "CREATE TRIGGER $triggerName $whenName $eventName ON $tableName FOR EACH ROW BEGIN $varString $sqlString END";
+          $triggerSQL = "CREATE TRIGGER $triggerName $whenName $eventName ON $tableName FOR EACH ROW BEGIN $varString $sqlString END";
 
           CRM_Core_DAO::executeQuery("DROP TRIGGER IF EXISTS $triggerName");
           CRM_Core_DAO::executeQuery(
@@ -2024,7 +2047,7 @@ SELECT contact_id
    * Find all records which refer to this entity.
    *
    * @return array
-   *   of objects referencing this
+   *   Array of objects referencing this
    */
   public function findReferences() {
     $links = self::getReferencesToTable(static::getTableName());
@@ -2049,11 +2072,11 @@ SELECT contact_id
   /**
    * @return array
    *   each item has keys:
-   *  - name: string
-   *  - type: string
-   *  - count: int
-   *  - table: string|null SQL table name
-   *  - key: string|null SQL column name
+   *   - name: string
+   *   - type: string
+   *   - count: int
+   *   - table: string|null SQL table name
+   *   - key: string|null SQL column name
    */
   public function getReferenceCounts() {
     $links = self::getReferencesToTable(static::getTableName());
@@ -2090,7 +2113,7 @@ SELECT contact_id
    *
    * @return array
    *   structure of table and column, listing every table with a
-   * foreign key reference to $tableName, and the column where the key appears.
+   *   foreign key reference to $tableName, and the column where the key appears.
    */
   public static function getReferencesToTable($tableName) {
     $refsFound = array();
@@ -2136,11 +2159,11 @@ SELECT contact_id
    *
    * @param string $fieldName
    * @param string $context
-   *   : @see CRM_Core_DAO::buildOptionsContext.
+   * @see CRM_Core_DAO::buildOptionsContext
    * @param array $props
-   *   whatever is known about this bao object.
+   *   whatever is known about this bao object.
    *
-   * @return Array|bool
+   * @return array|bool
    */
   public static function buildOptions($fieldName, $context = NULL, $props = array()) {
     // If a given bao does not override this function
@@ -2156,7 +2179,7 @@ SELECT contact_id
   public function getOptionLabels() {
     $fields = $this->fields();
     if ($fields === NULL) {
-      throw new Exception ('Cannot call getOptionLabels on CRM_Core_DAO');
+      throw new Exception('Cannot call getOptionLabels on CRM_Core_DAO');
     }
     foreach ($fields as $field) {
       $name = CRM_Utils_Array::value('name', $field);
@@ -2230,7 +2253,7 @@ SELECT contact_id
    *   alternative field name ('as') @todo- not actually used.
    * @param bool $returnSanitisedArray
    *   Return a sanitised array instead of a clause.
-   *  this is primarily so we can add filters @ the api level to the Query object based fields
+   *   this is primarily so we can add filters @ the api level to the Query object based fields
    *
    * @throws Exception
    *
@@ -2241,7 +2264,8 @@ SELECT contact_id
    *  preferable to not double-banger the return context next refactor of this - but keeping the attention
    *  in one place has some advantages as we try to extend this format
    *
-   * @return NULL|string|array a string is returned if $returnSanitisedArray is not set, otherwise and Array or NULL
+   * @return NULL|string|array
+   *   a string is returned if $returnSanitisedArray is not set, otherwise and Array or NULL
    *   depending on whether it is supported as yet
    */
   public static function createSQLFilter($fieldName, $filter, $type, $alias = NULL, $returnSanitisedArray = FALSE) {
@@ -2283,19 +2307,18 @@ SELECT contact_id
             }
             $escapedCriteria = array_map(array(
               'CRM_Core_DAO',
-              'escapeString'
+              'escapeString',
             ), $criteria);
             if (!$returnSanitisedArray) {
               return (sprintf('%s %s ("%s")', $fieldName, $operator, implode('", "', $escapedCriteria)));
             }
             return $escapedCriteria;
-            break;
 
           // binary operators
 
           default:
             if (!$returnSanitisedArray) {
-              return(sprintf('%s %s "%s"', $fieldName, $operator, CRM_Core_DAO::escapeString($criteria)));
+              return (sprintf('%s %s "%s"', $fieldName, $operator, CRM_Core_DAO::escapeString($criteria)));
             }
             else {
               return NULL; // not yet implemented (tests required to implement)
@@ -2311,7 +2334,23 @@ SELECT contact_id
    * @return array
    */
   public static function acceptedSQLOperators() {
-    return array('=', '<=', '>=', '>', '<', 'LIKE', "<>", "!=", "NOT LIKE", 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'IS NOT NULL', 'IS NULL');
+    return array(
+      '=',
+      '<=',
+      '>=',
+      '>',
+      '<',
+      'LIKE',
+      "<>",
+      "!=",
+      "NOT LIKE",
+      'IN',
+      'NOT IN',
+      'BETWEEN',
+      'NOT BETWEEN',
+      'IS NOT NULL',
+      'IS NULL',
+    );
   }
 
   /**
@@ -2353,6 +2392,7 @@ SELECT contact_id
   /**
    * @param array $params
    */
-  public function setApiFilter(&$params) {}
+  public function setApiFilter(&$params) {
+  }
 
 }