From ca74886f30da323f42aa4bd70461003f46ef299b Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 12 Mar 2015 00:43:02 +0100 Subject: LinkDB: move to a proper file, add test coverage Relates to #71 LinkDB - move to application/LinkDB.php - code cleanup - indentation - whitespaces - formatting - comment cleanup - add missing documentation - unify formatting Test coverage for LinkDB - constructor - public / private access - link-related methods Shaarli utilities (LinkDB dependencies) - move startsWith() and endsWith() functions to application/Utils.php - add test coverage Dev utilities - Composer: add PHPUnit to dev dependencies - Makefile: - update lint targets - add test targets - generate coverage reports Signed-off-by: VirtualTam --- application/Utils.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 application/Utils.php (limited to 'application/Utils.php') diff --git a/application/Utils.php b/application/Utils.php new file mode 100644 index 00000000..737f1502 --- /dev/null +++ b/application/Utils.php @@ -0,0 +1,45 @@ + yZH23w + */ +function smallHash($text) +{ + $t = rtrim(base64_encode(hash('crc32', $text, true)), '='); + return strtr($t, '+/', '-_'); +} + +/** + * Tells if a string start with a substring + */ +function startsWith($haystack, $needle, $case=true) +{ + if ($case) { + return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0); + } + return (strcasecmp(substr($haystack, 0, strlen($needle)), $needle) === 0); +} + +/** + * Tells if a string ends with a substring + */ +function endsWith($haystack, $needle, $case=true) +{ + if ($case) { + return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); + } + return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); +} +?> -- cgit v1.2.3