From 2558c2b0bc4cbb430206eb419c947d5c3792c48a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 24 May 2014 14:46:58 +1200 Subject: [PATCH] add CRM/Core/CodeGen comment blocks --- CRM/Core/CodeGen/BaseTask.php | 6 +++ CRM/Core/CodeGen/Main.php | 17 ++++++ CRM/Core/CodeGen/Schema.php | 12 +++++ CRM/Core/CodeGen/Specification.php | 85 ++++++++++++++++++++++++++++++ CRM/Core/CodeGen/Util/File.php | 12 +++++ CRM/Core/CodeGen/Util/Template.php | 4 ++ 6 files changed, 136 insertions(+) diff --git a/CRM/Core/CodeGen/BaseTask.php b/CRM/Core/CodeGen/BaseTask.php index 9fb779e207..0e731fbcce 100644 --- a/CRM/Core/CodeGen/BaseTask.php +++ b/CRM/Core/CodeGen/BaseTask.php @@ -6,11 +6,17 @@ abstract class CRM_Core_CodeGen_BaseTask implements CRM_Core_CodeGen_ITask { protected $config; + /** + * + */ function __construct() { } // TODO: this is the most rudimentary possible hack. CG config should // eventually be made into a first-class object. + /** + * @param is $config + */ function setConfig($config) { $this->config = $config; $this->tables = $this->config->tables; diff --git a/CRM/Core/CodeGen/Main.php b/CRM/Core/CodeGen/Main.php index 451d054c98..924713f733 100644 --- a/CRM/Core/CodeGen/Main.php +++ b/CRM/Core/CodeGen/Main.php @@ -25,6 +25,17 @@ class CRM_Core_CodeGen_Main { */ var $digest; + /** + * @param $CoreDAOCodePath + * @param $sqlCodePath + * @param $phpCodePath + * @param $tplCodePath + * @param $smartyPluginDirs + * @param $argCms + * @param $argVersion + * @param $schemaPath + * @param $digestPath + */ function __construct($CoreDAOCodePath, $sqlCodePath, $phpCodePath, $tplCodePath, $smartyPluginDirs, $argCms, $argVersion, $schemaPath, $digestPath) { $this->CoreDAOCodePath = $CoreDAOCodePath; $this->sqlCodePath = $sqlCodePath; @@ -159,6 +170,9 @@ Alternatively you can get a version of CiviCRM that matches your PHP version return $this->digest; } + /** + * @return array + */ function getExpectedFiles() { return array( $this->sqlCodePath . '/civicrm.mysql', @@ -166,6 +180,9 @@ Alternatively you can get a version of CiviCRM that matches your PHP version ); } + /** + * @return bool + */ function hasExpectedFiles() { foreach ($this->getExpectedFiles() as $file) { if (!file_exists($file)) { diff --git a/CRM/Core/CodeGen/Schema.php b/CRM/Core/CodeGen/Schema.php index 2745392fed..87487b6183 100644 --- a/CRM/Core/CodeGen/Schema.php +++ b/CRM/Core/CodeGen/Schema.php @@ -4,6 +4,9 @@ * Create SQL files to create and populate a new schema. */ class CRM_Core_CodeGen_Schema extends CRM_Core_CodeGen_BaseTask { + /** + * + */ function __construct() { parent::__construct(); $this->locales = $this->findLocales(); @@ -25,6 +28,9 @@ class CRM_Core_CodeGen_Schema extends CRM_Core_CodeGen_BaseTask { $this->generateSample(); } + /** + * @param string $fileName + */ function generateCreateSql($fileName = 'civicrm.mysql') { echo "Generating sql file\n"; $template = new CRM_Core_CodeGen_Util_Template('sql'); @@ -38,6 +44,9 @@ class CRM_Core_CodeGen_Schema extends CRM_Core_CodeGen_BaseTask { $template->run('schema.tpl', $this->config->sqlCodePath . $fileName); } + /** + * @param string $fileName + */ function generateDropSql($fileName = 'civicrm_drop.mysql') { echo "Generating sql drop tables file\n"; $dropOrder = array_reverse(array_keys($this->tables)); @@ -93,6 +102,9 @@ class CRM_Core_CodeGen_Schema extends CRM_Core_CodeGen_BaseTask { $template->run('case_sample.tpl', $this->config->sqlCodePath . 'case_sample.mysql'); } + /** + * @return array + */ function findLocales() { require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(FALSE); diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index cd415662f9..1818d3c52d 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -56,6 +56,11 @@ class CRM_Core_CodeGen_Specification { } } + /** + * @param $dbXML + * + * @return array + */ function &getDatabase(&$dbXML) { $database = array('name' => trim((string ) $dbXML->name)); @@ -75,6 +80,12 @@ class CRM_Core_CodeGen_Specification { return $database; } + /** + * @param $dbXML + * @param $database + * + * @return array + */ function getTables($dbXML, &$database) { $tables = array(); foreach ($dbXML->tables as $tablesXML) { @@ -92,12 +103,21 @@ class CRM_Core_CodeGen_Specification { return $tables; } + /** + * @param $tables + * @param $classNames + */ function resolveForeignKeys(&$tables, &$classNames) { foreach (array_keys($tables) as $name) { $this->resolveForeignKey($tables, $classNames, $name); } } + /** + * @param $tables + * @param $classNames + * @param $name + */ function resolveForeignKey(&$tables, &$classNames, $name) { if (!array_key_exists('foreignKey', $tables[$name])) { return; @@ -115,6 +135,11 @@ class CRM_Core_CodeGen_Specification { } } + /** + * @param $tables + * + * @return array + */ function orderTables(&$tables) { $ordered = array(); @@ -129,6 +154,13 @@ class CRM_Core_CodeGen_Specification { return $ordered; } + /** + * @param $tables + * @param $valid + * @param $name + * + * @return bool + */ function validTable(&$tables, &$valid, $name) { if (!array_key_exists('foreignKey', $tables[$name])) { return TRUE; @@ -143,6 +175,11 @@ class CRM_Core_CodeGen_Specification { return TRUE; } + /** + * @param $tableXML + * @param $database + * @param $tables + */ function getTable($tableXML, &$database, &$tables) { $name = trim((string ) $tableXML->name); $klass = trim((string ) $tableXML->class); @@ -239,6 +276,10 @@ class CRM_Core_CodeGen_Specification { return; } + /** + * @param $fieldXML + * @param $fields + */ function getField(&$fieldXML, &$fields) { $name = trim((string ) $fieldXML->name); $field = array('name' => $name, 'localizable' => $fieldXML->localizable); @@ -373,6 +414,11 @@ class CRM_Core_CodeGen_Specification { $fields[$name] = &$field; } + /** + * @param $name + * + * @return string + */ function composeTitle($name) { $names = explode('_', strtolower($name)); $title = ''; @@ -394,6 +440,11 @@ class CRM_Core_CodeGen_Specification { return trim($title); } + /** + * @param $primaryXML + * @param $fields + * @param $table + */ function getPrimaryKey(&$primaryXML, &$fields, &$table) { $name = trim((string ) $primaryXML->name); @@ -413,6 +464,11 @@ class CRM_Core_CodeGen_Specification { $table['primaryKey'] = &$primaryKey; } + /** + * @param $indexXML + * @param $fields + * @param $indices + */ function getIndex(&$indexXML, &$fields, &$indices) { //echo "\n\n*******************************************************\n"; //echo "entering getIndex\n"; @@ -474,6 +530,12 @@ class CRM_Core_CodeGen_Specification { $indices[$indexName] = &$index; } + /** + * @param $foreignXML + * @param $fields + * @param $foreignKeys + * @param $currentTableName + */ function getForeignKey(&$foreignXML, &$fields, &$foreignKeys, &$currentTableName) { $name = trim((string ) $foreignXML->name); @@ -499,6 +561,10 @@ class CRM_Core_CodeGen_Specification { $foreignKeys[$name] = &$foreignKey; } + /** + * @param $foreignXML + * @param $dynamicForeignKeys + */ function getDynamicForeignKey(&$foreignXML, &$dynamicForeignKeys) { $foreignKey = array( 'idColumn' => trim($foreignXML->idColumn), @@ -508,6 +574,13 @@ class CRM_Core_CodeGen_Specification { $dynamicForeignKeys[] = $foreignKey; } + /** + * @param $key + * @param $object + * @param null $default + * + * @return null|string + */ protected function value($key, &$object, $default = NULL) { if (isset($object->$key)) { return (string ) $object->$key; @@ -515,6 +588,13 @@ class CRM_Core_CodeGen_Specification { return $default; } + /** + * @param $attributes + * @param $object + * @param $name + * @param null $pre + * @param null $post + */ protected function checkAndAppend(&$attributes, &$object, $name, $pre = NULL, $post = NULL) { if (!isset($object->$name)) { return; @@ -524,6 +604,11 @@ class CRM_Core_CodeGen_Specification { $this->append($attributes, ' ', trim($value)); } + /** + * @param $str + * @param $delim + * @param $name + */ protected function append(&$str, $delim, $name) { if (empty($name)) { return; diff --git a/CRM/Core/CodeGen/Util/File.php b/CRM/Core/CodeGen/Util/File.php index 099c911a08..47f99ea623 100644 --- a/CRM/Core/CodeGen/Util/File.php +++ b/CRM/Core/CodeGen/Util/File.php @@ -4,12 +4,19 @@ * Class CRM_Core_CodeGen_Util_File */ class CRM_Core_CodeGen_Util_File { + /** + * @param $dir + * @param int $perm + */ static function createDir($dir, $perm = 0755) { if (!is_dir($dir)) { mkdir($dir, $perm, TRUE); } } + /** + * @param $dir + */ static function removeDir($dir) { foreach (glob("$dir/*") as $tempFile) { unlink($tempFile); @@ -17,6 +24,11 @@ class CRM_Core_CodeGen_Util_File { rmdir($dir); } + /** + * @param $prefix + * + * @return string + */ static function createTempDir($prefix) { if (isset($_SERVER['TMPDIR'])) { $tempDir = $_SERVER['TMPDIR']; diff --git a/CRM/Core/CodeGen/Util/Template.php b/CRM/Core/CodeGen/Util/Template.php index c092ed725a..f9a509f584 100644 --- a/CRM/Core/CodeGen/Util/Template.php +++ b/CRM/Core/CodeGen/Util/Template.php @@ -84,6 +84,10 @@ class CRM_Core_CodeGen_Util_Template { } } + /** + * @param $key + * @param $value + */ function assign($key, $value) { $this->smarty->assign_by_ref($key, $value); } -- 2.25.1