Skip to content

Commit

Permalink
comment clean up to help with static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmunro committed May 19, 2017
1 parent 0e4804c commit e9ff544
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 19 deletions.
42 changes: 40 additions & 2 deletions lib/cache.php
Expand Up @@ -212,54 +212,89 @@ class Hm_Memcached {
private $port;
private $cache_con;

/**
* @param Hm_Config $config site config object
*/
public function __construct($config) {
$this->server = $config->get('memcached_server', false);
$this->port = $config->get('memcached_port', false);
$this->enabled = $config->get('enable_memcached', false);
$this->supported = Hm_Functions::class_exists('Memcached');
}

/**
* @return boolean
*/
public function close() {
if (!$this->active()) {
return false;
}
return $this->cache_con->quit();
}

/**
* @param string $key cache key to delete
*/
public function del($key) {
if (!$this->active()) {
return false;
}
return $this->cache_con->delete($key);
}

public function set($key, $val, $lifetime=300, $crypt_key=false) {
/**
* @param string $key key to set
* @param string $val value to set
* @param integer $lifetime lifetime of the cache entry
* @param string $crypt_key encryption key
* @return boolean
*/
public function set($key, $val, $lifetime=300, $crypt_key='') {
if (!$this->active()) {
return false;
}
return $this->cache_con->set($key, $this->prep_in($val, $crypt_key), $lifetime);
}

public function get($key, $crypt_key=false) {
/**
* @param string $key name of value to fetch
* @param string $crypt_key encryption key
* @return false|string
*/
public function get($key, $crypt_key='') {
if (!$this->active()) {
return false;
}
return $this->prep_out($this->cache_con->get($key), $crypt_key);
}

/**
* @param array $data data to prep
* @param string $crypt_key encryption key
* @return string
*/
private function prep_in($data, $crypt_key) {
if ($crypt_key) {
return Hm_Crypt::ciphertext(Hm_transform::stringify($data), $crypt_key);
}
return $data;
}

/**
* @param array $data data to prep
* @param string $crypt_key encryption key
* @return array
*/
private function prep_out($data, $crypt_key) {
if ($crypt_key && is_string($data) && trim($data)) {
return Hm_transform::unstringify(Hm_Crypt::plaintext($data, $crypt_key));
}
return $data;
}

/*
* @return boolean
*/
private function connect() {
$this->cache_con = Hm_Functions::memcached();
if (!$this->cache_con->addServer($this->server, $this->port)) {
Expand All @@ -270,6 +305,9 @@ private function connect() {
return true;
}

/*
* @return boolean
*/
public function active() {
if (!$this->enabled) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/dispatch.php
Expand Up @@ -73,7 +73,7 @@ private function process_request() {

/**
* Force TLS connections unless the site config has it disabled
* @return bool
* @return null|false
*/
public function check_for_tls_redirect() {
if (!$this->request->tls && !$this->site_config->get('disable_tls', false) &&
Expand All @@ -86,7 +86,7 @@ public function check_for_tls_redirect() {

/**
* Redirect the page after a POST form is submitted and forward any user notices
* @return mixed
* @return string|false
*/
public function check_for_redirect() {
if (array_key_exists('no_redirect', $this->module_exec->handler_response) && $this->module_exec->handler_response['no_redirect']) {
Expand Down Expand Up @@ -142,7 +142,7 @@ private function render_output() {
/**
* Determine the page id
* @param array $filters list of filters
* @param object $request request details
* @param Hm_Request $request request details
* @return void
*/
public function get_page($filters, $request) {
Expand Down
6 changes: 2 additions & 4 deletions lib/format.php
Expand Up @@ -28,7 +28,6 @@ public function __construct($config) {
/**
* Return combined output from all modules. Must be overridden by specific
* output classes
* @param array $output data from the output modules
* @param array $allowed_output allowed fields for JSON responses
* @return mixed combined output
*/
Expand All @@ -42,8 +41,7 @@ class Hm_Format_JSON extends HM_Format {

/**
* Run modules and merge + filter the result array
* @param array $input data from the handler modules
* @param array $lang_str langauge strings
* @param array $output data from the handler modules
* @param array $allowed_output allowed fields for JSON responses
* @return JSON encoded data to be sent to the browser
*/
Expand Down Expand Up @@ -114,7 +112,7 @@ class Hm_Transform {
* Convert an array to a string
* @param array $data data to be transformed to a string
* @param string $encoding encoding to use for values
* @return mixed string on success, false on failure
* @return string on success, false on failure
*/
static function stringify($data, $encoding='base64_encode') {
if (is_string($data)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/module.php
Expand Up @@ -284,7 +284,7 @@ public function validate_origin() {
* Validate a form key. If this is a non-empty POST form from an
* HTTP request or AJAX update, it will take the user to the home
* page if the page_key value is either not present or not valid
* @return void
* @return false|string
*/
public function process_key() {
if (empty($this->request->post)) {
Expand Down Expand Up @@ -406,7 +406,7 @@ public function trans($string) {

/**
* Build output by calling module specific output functions
* @param string $formt output type, either HTML5 or AJAX
* @param string $format output type, either HTML5 or AJAX
* @param array $lang_str list of language translation strings
* @return mixed module output, a string for HTML5 format,
* and an array for AJAX
Expand Down
2 changes: 1 addition & 1 deletion lib/modules.php
Expand Up @@ -140,7 +140,7 @@ public static function add($page, $module, $logged_in, $marker=false, $placement
* @param bool $logged_in true if the module requires the user to be logged in
* @param string $placement "before" or "after" the $marker module
* @param string $source the module set containing this module
* @return void
* @return boolean
*/
private static function insert_at_marker($marker, $page, $module, $logged_in, $placement, $source) {
$inserted = false;
Expand Down
5 changes: 3 additions & 2 deletions lib/modules_exec.php
Expand Up @@ -13,8 +13,9 @@ trait Hm_Output_Module_Exec {

/**
* Run all the handler modules for a page and merge the results
* @param object $request details about the request
* @param Hm_Request $request details about the request
* @param bool $active_session true if the session is active
* @param string $page current page request
* @return void
*/
public function run_output_modules($request, $active_session, $page) {
Expand Down Expand Up @@ -86,7 +87,7 @@ trait Hm_Handler_Module_Exec {

/**
* Run all the handler modules for a page and merge the results
* @param object $request details about the request
* @param Hm_Request $request details about the request
* @param object $session session interface
* @param string $page page id
* @return void
Expand Down
2 changes: 1 addition & 1 deletion lib/oauth2.php
Expand Up @@ -20,7 +20,7 @@ class Hm_Oauth2 {
* Load default settings
* @param string $id Oath2 client id
* @param string $secret Oath2 client secret
* @param string $redirect_uri URI to redirect to from the remote site
* @param string $uir URI to redirect to from the remote site
* @return object
*/
public function __construct($id, $secret, $uri) {
Expand Down
8 changes: 4 additions & 4 deletions lib/session_base.php
Expand Up @@ -126,7 +126,7 @@ abstract protected function auth($user, $pass);
/**
* Return a session value, or a user settings value stored in the session
* @param string $name session value name to return
* @param mixed $default value to return if $name is not found
* @param string $default value to return if $name is not found
* @return mixed the value if found, otherwise $default
*/
abstract protected function get($name, $default=false);
Expand Down Expand Up @@ -201,7 +201,7 @@ protected function just_started() {

/**
* Record session level changes not yet saved in persistant storage
* @param string $vaue short description of the unsaved value
* @param string $value short description of the unsaved value
* @return void
*/
public function record_unsaved($value) {
Expand Down Expand Up @@ -285,8 +285,8 @@ public function get_key($request) {
* @param string $lifetime cookie lifetime
* @param string $path cookie path
* @param string $domain cookie domain
* @param bool $html_only set html only cookie flag
* @return void
* @param boolean $html_only set html only cookie flag
* @return boolean
*/
public function secure_cookie($request, $name, $value, $lifetime=false, $path='', $domain='', $html_only=true) {
if ($name == 'hm_reload_folders') {
Expand Down

0 comments on commit e9ff544

Please sign in to comment.