From: Stricted Date: Mon, 17 Feb 2014 03:56:06 +0000 (+0100) Subject: some code styleup X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=701c06d4b7dcf5ae061090ce054f85a855723451;p=Snippets.git some code styleup --- diff --git a/APC.class.php b/APC.class.php index f5b7fe2..83cf39b 100644 --- a/APC.class.php +++ b/APC.class.php @@ -18,7 +18,7 @@ class APC { public $version = 0; /** - * init APC class + * Constructs a new instance of APC class. */ public function __construct () { if (extension_loaded("apcu")) { diff --git a/Feed.class.php b/Feed.class.php index 520ddac..63020b3 100644 --- a/Feed.class.php +++ b/Feed.class.php @@ -4,28 +4,38 @@ * @copyright 2013-2014 Jan Altensen (Stricted) * @license GNU Lesser General Public License */ -class FeedClass { +class Feed { + /** + * Constructs a new instance of Feed class. + * + * @param string $url + * @return array + */ public function __construct($url) { $file = file_get_contents($url); $xml = simplexml_load_string($file); $type = $this->getFeedType($xml); - $data = null; + $data = array(); + switch($type) { case 'rss': $data = $this->parseRSSFeed($xml); break; - + case 'atom': $data = $this->parseAtomFeed($xml); break; - - default: - return null; - break; } + return $data; } - + + /** + * parse rss feed + * + * @param object $xml + * @return array + */ private function parseRSSFeed($xml) { foreach ($xml->channel->item as $item) { $item->pubDate = $this->getTime($item->pubDate); @@ -34,7 +44,13 @@ class FeedClass { } return $data; } - + + /** + * parse rss feed + * + * @param object $xml + * @return array + */ private function parseAtomFeed($xml) { $entries = $xml->children()->entry; foreach ($entries as $entry) { @@ -45,15 +61,33 @@ class FeedClass { } return $data; } - + + /** + * get feed time + * + * @param string $time + * @return integer + */ private function getTime($time) { - return date("d.m.Y H:i:s",intval(strtotime($time))); + return date("d.m.Y H:i:s", $this->getTimeStamp($time)); } - + + /** + * get feed timestamp + * + * @param string $time + * @return integer + */ private function getTimeStamp($time) { return intval(strtotime($time)); } - + + /** + * get feed type + * + * @param object $xml + * @return array + */ public static function getFeedType($xml) { $type = ''; if (isset($xml->channel->item)) { diff --git a/LDAP.class.php b/LDAP.class.php index b53721a..d0ede6e 100644 --- a/LDAP.class.php +++ b/LDAP.class.php @@ -8,11 +8,13 @@ class LDAP { /** * LDAP resource id + * @var object */ protected $ldap = Null; /** * LDAP DN + * @var string */ protected $dn = ''; diff --git a/LDAPHash.class.php b/LDAPHash.class.php index 4528179..c3ef96d 100644 --- a/LDAPHash.class.php +++ b/LDAPHash.class.php @@ -5,7 +5,6 @@ * @license GNU Lesser General Public License */ class LDAPHash { - /** * compare given ldap hash with given password * diff --git a/autoload.class.php b/autoload.class.php index 0329e02..5e92a64 100644 --- a/autoload.class.php +++ b/autoload.class.php @@ -5,28 +5,28 @@ * @license GNU Lesser General Public License */ class autoload { - /* - * constructor to set autoloader - */ - public function __construct () { - spl_autoload_register(array('self', 'autoload')); - } - - /* - * autoload class files from namespace uses - * - * @param string $className - */ - public static function autoload ($className) { - $namespaces = explode('\\', $className); - if (count($namespaces) > 1) { - array_shift($namespaces); - $classPath = dirname(__FILE__) . '/' . implode('/', $namespaces) . '.class.php'; - if (file_exists($classPath)) { - require_once($classPath); - } - } - } + /* + * constructor to set autoloader + */ + public function __construct () { + spl_autoload_register(array('self', 'autoload')); + } + + /* + * autoload class files from namespace uses + * + * @param string $className + */ + public static function autoload ($className) { + $namespaces = explode('\\', $className); + if (count($namespaces) > 1) { + array_shift($namespaces); + $classPath = dirname(__FILE__) . '/' . implode('/', $namespaces) . '.class.php'; + if (file_exists($classPath)) { + require_once($classPath); + } + } + } } new autoload(); ?> \ No newline at end of file diff --git a/bcrypt.class.php b/bcrypt.class.php index a515ece..599fb01 100644 --- a/bcrypt.class.php +++ b/bcrypt.class.php @@ -32,7 +32,7 @@ class bcrypt { * crypt new password * * @param string $password - * @param string $double + * @param string $double * @return string */ public function crypt ($password, $double = false) { diff --git a/db.class.php b/db.class.php index 76eab9b..626f883 100644 --- a/db.class.php +++ b/db.class.php @@ -6,52 +6,89 @@ */ class DB { + /** + * PDO object + * @var object + */ private $conn = NULL; - private $error = NULL; + + /** + * error string + * @var string + */ + private $error = ''; /** * Connects to SQL Server - * - * @return true/false + * + * @param string $driver + * @param string $host + * @param string $username + * @param string $password + * @param string $database + * @param integer $port + * @param array $options + * @return boolean */ - public function connect($driver, $host, $username, $password, $database, $port = "", $driver_options = array()) { - if (!extension_loaded("pdo")) die("Missing PDO PHP extension."); // check if extension loaded + public function connect($driver, $host, $username, $password, $database, $port = 0, $options = array()) { + if (!extension_loaded("pdo")) { + // check if extension loaded + die("Missing PDO PHP extension."); + } + + $driver = strtolower($driver); try { - switch (strtolower($driver)) { - case "mysql": - if (!extension_loaded("pdo_mysql")) die("Missing pdo_mysql PHP extension."); // check if extension loaded - if (empty($port)) $port=3306; - $this->conn = new PDO("mysql:host=".$host.";port=".$port.";dbname=".$v, $username, $password, $driver_options); - break; + if ($driver == "mysql") { + if (!extension_loaded("pdo_mysql")) { + // check if extension loaded + die("Missing pdo_mysql PHP extension."); + } + + if (empty($port)) { + $port=3306; + } + + $this->conn = new PDO("mysql:host=".$host.";port=".$port.";dbname=".$v, $username, $password, $options); + } + else if ($driver == "pgsql") { + if (!extension_loaded("pdo_pgsql")) { + // check if extension loaded + die("Missing pdo_pgsql PHP extension."); + } + + if (empty($port)) { + $port=5432; + } - case "pgsql": - if (!extension_loaded("pdo_pgsql")) die("Missing pdo_pgsql PHP extension."); // check if extension loaded - if (empty($port)) $port=5432; - $this->conn = new PDO("pgsql:host=".$host.";port=".$port.";dbname=".$database, $username, $password, $driver_options); - break; - - case "sqlite": - if (!extension_loaded("pdo_sqlite")) die("Missing pdo_sqlite PHP extension."); // check if extension loaded - if (!file_exists($v)) { - @touch($database); - } - - if (file_exists($database) && is_readable($database) && is_writable($database)) { - $this->conn = new PDO("sqlite:".$database, $username, $password, $driver_options); - } - else { - $this->error = "cant crate/connect the/to sqlite database"; - return false; - } - break; - - default: - $this->error = "not supported database type found"; + $this->conn = new PDO("pgsql:host=".$host.";port=".$port.";dbname=".$database, $username, $password, $options); + } + else if ($driver == "sqlite") { + if (!extension_loaded("pdo_sqlite")) { + // check if extension loaded + die("Missing pdo_sqlite PHP extension."); + } + + if (!file_exists($database)) { + @touch($database); + } + + if (file_exists($database) && is_readable($database) && is_writable($database)) { + $this->conn = new PDO("sqlite:".$database, $username, $password, $options); + } + else { + $this->error = "cant crate/connect the/to sqlite database"; return false; - break; + } } + else{ + $this->error = "not supported database type found"; + return false; + } + return true; - } catch (PDOException $e) { + + } + catch (PDOException $e) { $this->error = $e->getMessage(); return false; } @@ -67,9 +104,9 @@ class DB { /** * Sends a database query to SQL server. * - * @param string $res a database query - * @param array $bind - * @return integer id of the query result + * @param string $res + * @param array $bind + * @return integer */ public function query ($res, $bind = array()) { try { @@ -84,37 +121,40 @@ class DB { } return $query; - } catch (PDOException $e) { + } + catch (PDOException $e) { $this->error = $e->getMessage(); } } - /** * Gets a row from SQL database query result. * - * @param string $res a database query - * @return array a row from result + * @param string $res + * @return array */ public function fetch_array ($res) { try { return $res->fetch(PDO::FETCH_ASSOC); - } catch (PDOException $e) { + } + catch (PDOException $e) { $this->error = $e->getMessage(); } } /** * return the last insert id + * + * @return integer */ public function last_id () { return $this->conn->lastInsertId(); } /** - * Returns SQL error number for last error. + * Returns SQL last error. * - * @return integer MySQL error number + * @return string */ public function error () { return $this->error; diff --git a/git.class.php b/git.class.php index 4acb81f..bbb7435 100644 --- a/git.class.php +++ b/git.class.php @@ -6,7 +6,12 @@ */ class git { protected $repo; - + + /** + * Constructs a new instance of git class. + * + * @param string $repo + */ public function __construct ($repo) { $this->repo = $repo; } @@ -14,8 +19,7 @@ class git { /* * parse all commits from repo * - * @param string $repo - * @param int $count + * @param integer $count * @param string $branch * @return array */ @@ -70,7 +74,6 @@ class git { /* * get latest commit hash * - * @param string $repo * @param string $branch * @raturn string */ @@ -83,9 +86,8 @@ class git { /* * get commit count * - * @param string $repo * @param string $branch - * @raturn string + * @raturn integer */ public function get_count ($branch = "master") { $count = shell_exec('git --git-dir='.$this->repo.' rev-list --oneline --first-parent --header '.$branch.' | wc -l | sed "s/[ \t]//g"'); @@ -96,7 +98,6 @@ class git { /* * get commit version * - * @param string $repo * @param string $branch * @raturn string */ diff --git a/hash.class.php b/hash.class.php index 994c129..719610f 100644 --- a/hash.class.php +++ b/hash.class.php @@ -5,20 +5,39 @@ * @license GNU Lesser General Public License */ class hash { - protected $raw; - protected $hmac; - protected $key; - protected $algo; + /** + * raw output + * @var string + */ + protected $raw = ''; + + /** + * hash with hmac + * @var string + */ + protected $hmac = ''; + + /** + * hmac key + * @var string + */ + protected $key = ''; + + /** + * hash algorithm + * @var string + */ + protected $algo = ''; /** * constructor to validate algorithm * - * @param string $algo - * @param optional $raw - * @param optional $hmac - * @param optional $key + * @param string $algo + * @param string $raw + * @param string $hmac + * @param string $key */ - public function __construct ($algo, $raw = Null, $hmac = Null, $key = Null) { + public function __construct ($algo, $raw = '', $hmac = '', $key = '') { $this->raw = $raw; $this->hmac = $hmac; $this->key = $key; @@ -34,8 +53,8 @@ class hash { /** * hash given data with given algorithm * - * @param mixed $data - * @return hash + * @param string $data + * @return string */ public function hash ($data) { if (!empty($this->hmac)) { @@ -49,8 +68,8 @@ class hash { /** * hash given file with given algorithm * - * @param mixed $file - * @return hash + * @param string $file + * @return string */ public function hash_file ($file) { if (!empty($this->hmac)) { @@ -64,8 +83,8 @@ class hash { /** * compare the given data * - * @param hash $hash - * @param mixed $data + * @param string $hash + * @param string $data * @return boolean */ public function compare ($hash, $data) { @@ -81,8 +100,8 @@ class hash { /** * compare the given file * - * @param hash $hash - * @param mixed $file + * @param string $hash + * @param string $file * @return boolean */ public function compare_file ($hash, $file) {