Skip to content

Commit

Permalink
Code style guide: space after if before parens
Browse files Browse the repository at this point in the history
"Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls." http://drupal.org/coding-standards#indenting
  • Loading branch information
ginatrapani committed Jun 9, 2011
1 parent 9cc0f32 commit 772b885
Show file tree
Hide file tree
Showing 36 changed files with 185 additions and 189 deletions.
46 changes: 21 additions & 25 deletions docs/source/contribute/developers/writecode/styleguide/php.rst
Expand Up @@ -4,13 +4,10 @@ PHP Code Style Guide
This is the Code Style guide for PHP. See the main :doc:`main page </contribute/developers/writecode/styleguide/index>`
page for general guidelines and guides specific to other languages.

Assume we're using `the Drupal PHP coding
style <http://drupal.org/coding-standards>`_ unless otherwise noted
here.
Assume we're using `the Drupal PHP coding style <http://drupal.org/coding-standards>`_ unless otherwise noted here.

Always use to delimit PHP code, not the shorthand, <?, as this is the
most used and supported across PHP setups and the one PHP will continue
supporting in the future.
Always use to delimit PHP code, not the shorthand, <?, as this is the most used and supported across PHP setups and the
one PHP will continue supporting in the future.

Use PHP5 Conventions
--------------------
Expand All @@ -35,41 +32,40 @@ When in doubt, use PHP5 (not PHP4) coding conventions.
Maximum Line Length: 120 characters
-----------------------------------

The maximum length of any line of code is 120 characters, unless it
contains a string that should not have a break in it. (This differs from
Drupal's 80-character maximum length.)
The maximum length of any line of code is 120 characters, unless it contains a string that cannot have a break in it.
(This differs from Drupal's 80-character maximum length.)

Tip: Add a ruler to the 120 mark in Eclipse to see where you should
break to the next line. See [[Developer Guide: Setting Up Eclipse PDT]]
for how.
Tip: If you're using Eclipse, add a ruler to the 120 mark to see where you should break to the next line. See
[[Developer Guide: Setting Up Eclipse PDT]] for how.

Include Docblocks on All New Code
---------------------------------

ThinkUp uses PHPDocumentor to ease code maintenance and `auto-generate
class documentation <http://thinkupapp.com/docs/>`_. Include
PHPDoc-style “docblocks” in all of your PHP code. When writing your
documentation, please use `PHPDocumentor's
ThinkUp uses PHPDocumentor to ease code maintenance and `auto-generate class documentation
<http://thinkupapp.com/docs/>`_. Include PHPDoc-style “docblocks” in all of your PHP code. When writing your
documentation, please use `PHPDocumentor's
syntax <http://github.com/ginatrapani/ThinkUp/wiki/ThinkUp-and-PHPDocumentor-(PHPDoc)>`_.

Keyword case
------------

Drupal style guide states use of uppercase value keywords (TRUE, FALSE,
NULL), ThinkUp user lowercase.
Drupal style guide states use of uppercase value keywords (TRUE, FALSE, NULL), ThinkUp user lowercase.

Same-line Curly Braces
----------------------

Unlike Drupal's style guide, ThinkUp keeps opening and closing curly braces on the same line as the control keyword
(if, else).

MVC Architecture
----------------

ThinkUp implements the
:doc:`Model-View-Controller </contribute/developers/mvc>`
design pattern. All new PHP code should follow suit. Read more about
ThinkUp's :doc:`MVC
implementation </contribute/developers/mvc>`.
ThinkUp implements the :doc:`Model-View-Controller </contribute/developers/mvc>` design pattern. All new PHP code
should follow suit. Read more about ThinkUp's :doc:`MVC implementation </contribute/developers/mvc>`.

Drupal conventions to take notice of
------------------------------------

Some of these are inherited from PEAR:
\* When constructing multi line IFs, the boolean operator should be at
the beginning of the line, not the end.

* When constructing multi line IFs, the boolean operator should be at the beginning of the line, not the end.
Expand Up @@ -128,7 +128,7 @@ public function authControl() {
/* Begin plugin-specific configuration handling */
if (isset($_GET['p'])) {
// add config js to header
if($this->isAdmin()) {
if ($this->isAdmin()) {
$this->addHeaderJavaScript('assets/js/plugin_options.js');
}
$active_plugin = $_GET['p'];
Expand Down
24 changes: 12 additions & 12 deletions webapp/_lib/controller/class.AppConfigController.php
Expand Up @@ -38,7 +38,7 @@ public function adminControl() {
$this->disableCaching();
$option_dao = DAOFactory::getDAO("OptionDAO");

if(isset($_POST['save'])) {
if (isset($_POST['save'])) {
$required = array();
$config_values = array();
$parent_config_values = array();
Expand All @@ -49,26 +49,26 @@ public function adminControl() {
$app_config[$key]['title'] =
isset($app_config[$key]['title']) ? $app_config[$key]['title'] : $key;

if((isset($_POST[$key]) && $_POST[$key] != '') || $app_config[$key]['required'] &&
if ((isset($_POST[$key]) && $_POST[$key] != '') || $app_config[$key]['required'] &&
( (! isset($app_config[$key]['value']) || $app_config[$key]['value'] == '')
&& ! isset($required[$key]) ) ) {
$config_values[$key] = $app_config[$key];
if(isset($_POST[$key])) {
if (isset($_POST[$key])) {
$config_values[$key]['value'] = $_POST[$key];
$values++;
}
$config_values[$key]['value'] = isset($_POST[$key]) ? $_POST[$key] : '';
if( isset($app_config[$key]['match'])
if ( isset($app_config[$key]['match'])
&& ! preg_match($app_config[$key]['match'], $config_values[$key]['value']) ) {
$required[$key] = $app_config[$key]['title'] .
' should ' . $app_config[$key]['match_message'];
}

if(isset($app_config[$key]['dependencies'])) {
if (isset($app_config[$key]['dependencies'])) {
foreach( $config_values[$key]['dependencies'] as $dep_key ) {
$config_values[$dep_key]['value'] = isset($_POST[$dep_key]) ? $_POST[$dep_key] : '';
$value = $config_values[$dep_key]['value'];
if( isset($app_config[$dep_key]['match'])
if ( isset($app_config[$dep_key]['match'])
&& ! preg_match($app_config[$dep_key]['match'], $value) ) {
$required[$dep_key] = $app_config[$dep_key]['title'] .
' is required if ' . $app_config[$key]['title'] .
Expand All @@ -79,16 +79,16 @@ public function adminControl() {
}
}

if(count($required) > 0) {
if (count($required) > 0) {
$this->setJsonData( array( 'status' => 'failed', 'required' => $required));
} else {
// save our data
$saved = 0;
$deleted = 0;
foreach($config_values as $key => $config_value) {
$config = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, $key);
if($config_value['value'] != '') {
if($config) {
if ($config_value['value'] != '') {
if ($config) {
$option_dao->updateOption($config->option_id, $config_value['value']);
} else {
$option_dao->insertOption(OptionDAO::APP_OPTIONS, $key, $config_value['value']);
Expand All @@ -98,9 +98,9 @@ public function adminControl() {
}
foreach($app_config as $key => $value) {
// delete the record if it exists and is empty in the post request
if(! isset($config_values[$key]['value']) || $config_values[$key]['value'] == '') {
if (! isset($config_values[$key]['value']) || $config_values[$key]['value'] == '') {
$config = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, $key);
if($config) {
if ($config) {
$option_dao->deleteOption($config->option_id);
$deleted++;
}
Expand All @@ -115,7 +115,7 @@ public function adminControl() {
$app_config = AppConfig::getConfigData();
$filtered_config_values = array();
foreach($app_config as $key => $value) {
if(isset($config_values[$key])) {
if (isset($config_values[$key])) {
$filtered_config_values[$key] = $config_values[$key];
}
}
Expand Down
18 changes: 9 additions & 9 deletions webapp/_lib/controller/class.BackupController.php
Expand Up @@ -47,23 +47,23 @@ public function __construct($session_started=false) {
public function adminControl() {
$this->disableCaching();
$this->view_mgr->addHelp('backup', 'install/backup');
if(! self::checkForZipSupport()) {
if (! self::checkForZipSupport()) {
$this->addToView('no_zip_support', true);
}
try {
$backup_dao = DAOFactory::getDAO('BackupDAO');
if(isset($_GET['backup'])) {
if (isset($_GET['backup'])) {
self::mutexLock();
/* export/download backup file */
$backup_dao->export();
if( ! headers_sent() ) { // this is so our test don't barf on us
if ( ! headers_sent() ) { // this is so our test don't barf on us
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="thinkup_db_backup.zip"');
header('Pragma: no-cache');
header('Expires: 0');
}
$fh = fopen($this->backup_file, "rb");
if($fh) {
if ($fh) {
while (!feof($fh)) {
$data = fread($fh, 256);
echo $data;
Expand All @@ -75,14 +75,14 @@ public function adminControl() {
throw new Exception("Unable to read backup zip file: " + $this->backup_file);
}
self::mutexLock(true);
} else if(isset($_FILES['backup_file'])) {
} else if (isset($_FILES['backup_file'])) {
self::mutexLock();
/* upload backup file */
if($_FILES['backup_file']['error']) {
if($_FILES['backup_file']['error'] == UPLOAD_ERR_INI_SIZE) {
if ($_FILES['backup_file']['error']) {
if ($_FILES['backup_file']['error'] == UPLOAD_ERR_INI_SIZE) {
throw new Exception("Backup file upload failed. The file is too large." .
"You may need to increase the upload_max_filesize in php.ini.");
} else if($_FILES['backup_file']['error'] == UPLOAD_ERR_NO_FILE) {
} else if ($_FILES['backup_file']['error'] == UPLOAD_ERR_NO_FILE) {
throw new Exception("No file uploaded. Please select a backup file to upload");
} else {
throw new Exception("Backup file upload failed.");
Expand Down Expand Up @@ -124,7 +124,7 @@ public static function checkForZipSupport() {
public static function mutexLock($release = false) {
$mutex_dao = DAOFactory::getDAO('MutexDAO');
$global_mutex_name = Crawler::GLOBAL_MUTEX;
if($release) {
if ($release) {
$mutex_dao->releaseMutex($global_mutex_name);
} else {
// Everyone needs to check the global mutex
Expand Down
2 changes: 1 addition & 1 deletion webapp/_lib/controller/class.DashboardController.php
Expand Up @@ -90,7 +90,7 @@ private function loadView() {
$this->addToView('last_page', $page-1);
}
$this->addToView($dataset->name, $dataset->retrieveDataset($page));
if(Session::isLoggedIn() && $dataset->isSearchable()) {
if (Session::isLoggedIn() && $dataset->isSearchable()) {
$view_name = 'is_searchable';
$this->addToView($view_name, true);
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/_lib/controller/class.ExportController.php
Expand Up @@ -140,7 +140,7 @@ public static function outputCSV($data, $column_labels, $filename="export") {
// make sure the file name does not contain spaces.
$filename = str_replace(' ', '_', $filename);

if( ! headers_sent() ) { // this is so our test don't barf on us
if ( ! headers_sent() ) { // this is so our test don't barf on us
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Pragma: no-cache');
Expand Down
8 changes: 4 additions & 4 deletions webapp/_lib/controller/class.GridController.php
Expand Up @@ -64,7 +64,7 @@ public function __construct($session_started=false) {
$this->setViewTemplate('inline.view.tpl');
}
// or replies?
if($this->is_missing_param) {
if ($this->is_missing_param) {
if (isset($_GET['t'])) {
$this->is_missing_param = false;
}
Expand Down Expand Up @@ -93,12 +93,12 @@ public function authControl() {
} else {
echo "tu_grid_search.populate_grid(";
$posts_it;
if(isset($_GET['t'])) {
if (isset($_GET['t'])) {
// replies?
$post_dao = DAOFactory::getDAO('PostDAO');
$posts_it = $post_dao->getRepliesToPostIterator($_GET['t'], $_GET['n']);
} else {
if(isset($_GET['nolimit']) && $_GET['nolimit'] == 'true') {
if (isset($_GET['nolimit']) && $_GET['nolimit'] == 'true') {
self::$MAX_ROWS = 0;
}
$webapp = Webapp::getInstance();
Expand All @@ -109,7 +109,7 @@ public function authControl() {
echo '{"status":"success","limit":' . self::$MAX_ROWS . ',"posts": [' . "\n";
$cnt = 0;
// lets make sure we have a post iterator, and not just a list of posts
if( get_class($posts_it) != 'PostIterator' ) {
if ( get_class($posts_it) != 'PostIterator' ) {
throw Exception("Grid Search should use a PostIterator to conserve memory");
}
foreach($posts_it as $key => $value) {
Expand Down
8 changes: 4 additions & 4 deletions webapp/_lib/controller/class.GridExportController.php
Expand Up @@ -45,18 +45,18 @@ public function __construct($session_started=false) {
}

public function authControl() {
if( $this->is_missing_param ) {
if ( $this->is_missing_param ) {
echo('No search data to export.');
} else {
if(get_magic_quotes_gpc()) {
if (get_magic_quotes_gpc()) {
$_POST['grid_export_data'] = stripslashes($_POST['grid_export_data']);
}
$data = json_decode( $_POST['grid_export_data'] );
if(! $data ) {
if (! $data ) {
echo('No search data to export.' . json_last_error() . "<br />");
echo( $_POST['grid_export_data']);
} else {
if( ! headers_sent() ) { // this is so our test don't barf on us
if ( ! headers_sent() ) { // this is so our test don't barf on us
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export.csv"');
header('Pragma: no-cache');
Expand Down
2 changes: 1 addition & 1 deletion webapp/_lib/controller/class.InstallerController.php
Expand Up @@ -460,7 +460,7 @@ protected function getTimeZoneList() {
}

//avoid undefined offset error
if(!isset($option_data[1])) {
if (!isset($option_data[1])) {
$option_data[1] = $option_data[0];
}

Expand Down
22 changes: 11 additions & 11 deletions webapp/_lib/controller/class.PluginConfigurationController.php
Expand Up @@ -165,7 +165,7 @@ public function __construct($owner, $folder_name) {
protected function generateView() {
// if we have some p[lugin option elements defined
// render them and add to the parent view...
if(count($this->option_elements) > 0) {
if (count($this->option_elements) > 0) {
$this->setValues();
$view_mgr = new SmartyThinkUp();
$view_mgr->disableCaching();
Expand Down Expand Up @@ -229,7 +229,7 @@ public function addPluginOptionRequiredMessage($name, $message) {
*/
public function addPluginOption($option_type, $args) {

if(isset($args['name'])) {
if (isset($args['name'])) {

$element = array('name' => $args['name'], 'type' => $option_type);
switch($option_type) {
Expand All @@ -241,24 +241,24 @@ public function addPluginOption($option_type, $args) {
break;
default:
// text field, do nothing...
if(isset($args['validation_regex'])) {
if (isset($args['validation_regex'])) {
$element['validation_regex'] = $args['validation_regex'];
}

}
if(isset($args['default_value'])) {
if (isset($args['default_value'])) {
$element['default_value'] = $args['default_value'];
}
if(isset($args['label'])) {
if (isset($args['label'])) {
$element['label'] = $args['label'];
}
if(isset($args['id'])) {
if (isset($args['id'])) {
$element['id'] = $args['id'];
}
if(isset($args['value'])) {
if (isset($args['value'])) {
$element['value'] = $args['value'];
}
if(isset($args['advanced'])) {
if (isset($args['advanced'])) {
$element['advanced'] = true;
// advanced options should not be required
$this->setPluginOptionNotRequired($args['name']);
Expand All @@ -274,11 +274,11 @@ public function addPluginOption($option_type, $args) {
public function setValues() {
$options_hash = $this->optionList2HashByOptionName();
foreach( $this->option_elements as $key => $value) {
if(isset($options_hash[$key])) {
if (isset($options_hash[$key])) {
$this->option_elements[$key]['id'] = $options_hash[$key]->id;
$this->option_elements[$key]['value'] = $options_hash[$key]->option_value;
} else {
if(isset($this->option_elements[$key]['default_value'])) {
if (isset($this->option_elements[$key]['default_value'])) {
$this->option_elements[$key]['value'] = $this->option_elements[$key]['default_value'];
}
}
Expand Down Expand Up @@ -309,7 +309,7 @@ public function getPluginOption($key) {
* @return array A hash table op Options with option_name as the key
*/
public function optionList2HashByOptionName() {
if(count($this->options_values) > 0 && count($this->options_hash) == 0) {
if (count($this->options_values) > 0 && count($this->options_hash) == 0) {
foreach ($this->options_values as $option) {
$this->options_hash[ $option->option_name ] = $option;
}
Expand Down

0 comments on commit 772b885

Please sign in to comment.