scrutinizer suggestions

This commit is contained in:
Shish 2015-07-21 01:20:53 +01:00
parent 9508bec8d3
commit e5e7f891e2
5 changed files with 22 additions and 18 deletions

View File

@ -75,6 +75,8 @@ class Image {
* @param null|mixed $row
*/
public function __construct($row=null) {
assert('is_null($row) || is_array($row)');
if(!is_null($row)) {
foreach($row as $name => $value) {
// some databases use table.name rather than name

View File

@ -82,7 +82,7 @@ function sql_escape($input) {
* Turn all manner of HTML / INI / JS / DB booleans into a PHP one
*
* @param $input
* @return boolean
* @return bool
*/
function bool_escape($input) {
/*
@ -234,7 +234,7 @@ function autodate($date, $html=true) {
* Check if a given string is a valid date-time. ( Format: yyyy-mm-dd hh:mm:ss )
*
* @param $dateTime
* @return boolean
* @return bool
*/
function isValidDateTime($dateTime) {
if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) {
@ -250,7 +250,7 @@ function isValidDateTime($dateTime) {
* Check if a given string is a valid date. ( Format: yyyy-mm-dd )
*
* @param $date
* @return boolean
* @return bool
*/
function isValidDate($date) {
if (preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $date, $matches)) {
@ -1052,7 +1052,7 @@ if (!function_exists('http_parse_headers')) { #http://www.php.net/manual/en/func
* In cases like these, we need to make sure to check for them if the camelcase version does not exist.
*
* @param array $headers
* @param mixed $key
* @param mixed $name
* @return mixed
*/
function findHeader ($headers, $name) {
@ -1140,29 +1140,29 @@ define("SCORE_LOG_NOTSET", 0);
* @param string $section
* @param int $priority
* @param string $message
* @param null|bool|string $flash
* @param bool|string $flash
* @param array $args
*/
function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $flash=null, $args=array()) {
function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $flash=false, $args=array()) {
send_event(new LogEvent($section, $priority, $message, $args));
$threshold = defined("CLI_LOG_LEVEL") ? CLI_LOG_LEVEL : 0;
if(is_cli() && ($priority >= $threshold)) {
print date("c")." $section: $message\n";
}
if($flash === True) {
if($flash === true) {
flash_message($message);
}
else if(!is_null($flash)) {
else if(is_string($flash)) {
flash_message($flash);
}
}
// More shorthand ways of logging
function log_debug( /*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_DEBUG, $message, $flash, $args);}
function log_info( /*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_INFO, $message, $flash, $args);}
function log_warning( /*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_WARNING, $message, $flash, $args);}
function log_error( /*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_ERROR, $message, $flash, $args);}
function log_critical(/*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash, $args);}
function log_debug( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_DEBUG, $message, $flash, $args);}
function log_info( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_INFO, $message, $flash, $args);}
function log_warning( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_WARNING, $message, $flash, $args);}
function log_error( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_ERROR, $message, $flash, $args);}
function log_critical(/*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash, $args);}
$_request_id = null;

View File

@ -67,7 +67,7 @@ class ArrowkeyNavigation extends Extension {
$images_per_page = $config->get_int('index_images');
// if there are no tags, use default
if ($event->get_arg(1) == null){
if (is_null($event->get_arg(1))){
$prefix = "";
$page_number = int_escape($event->get_arg(0));
$total_pages = ceil($database->get_one(

View File

@ -33,15 +33,15 @@ class Oekaki extends Extension {
$metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = 'oekaki tagme';
$metadata['source'] = null;
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);
if($event->image_id == -1) {
$duev = new DataUploadEvent($tmpname, $metadata);
send_event($duev);
if($duev->image_id == -1) {
throw new UploadException("File type not recognised");
}
else {
unlink($tmpname);
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/".$event->image_id));
$page->set_redirect(make_link("post/view/".$duev->image_id));
}
}
}

View File

@ -159,6 +159,7 @@ class Upload extends Extension {
$source = isset($_POST['source']) ? $_POST['source'] : null;
$tags = ''; // Tags aren't changed when uploading. Set to null to stop PHP warnings.
$ok = false;
if(count($_FILES)) {
foreach($_FILES as $file) {
$ok = $this->try_upload($file, $tags, $source, $image_id);
@ -177,6 +178,7 @@ class Upload extends Extension {
}
else if(!empty($_GET['url'])) {
$url = $_GET['url'];
$tags = isset($_GET['tags']) ? $_GET['tags'] : 'tagme';
$source = isset($_GET['source']) ? $_GET['source'] : $url;
$ok = $this->try_transload($url, $tags, $source, $image_id);
$this->theme->display_upload_status($page, $ok);