Changeset View
Standalone View
core/units/helpers/search_helper.php
Show First 20 Lines • Show All 595 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
} | } | ||||
break; | break; | ||||
case 'date_range': | case 'date_range': | ||||
$from = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'from'); | $from = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'from'); | ||||
$to = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'to'); | $to = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'to'); | ||||
$day_seconds = 23 * 60 * 60 + 59 * 60 + 59; | $day_seconds = 23 * 60 * 60 + 59 * 60 + 59; | ||||
if ($from !== false && $to === false) { | |||||
$from = strtotime(date('Y-m-d', $from) . ' 00:00:00', $from); // reset to morning | if ( is_numeric($from) && $to === null && date('H:i:s', $from) == '00:00:00' ) { | ||||
Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
Not Done ReplyNOTE: battle against malformed dates entered by user
change into: if ( is_numeric($from) && $to === null ) { this way to date entered in incorrect format won't be handled as to date not specified alex: NOTE: battle against malformed dates entered by user
change into:
```
lang=php
if… | |||||
$to = $from + $day_seconds; | $to = $from + $day_seconds; | ||||
Not Done Reply
$from == strtotime(date('Y-m-d', $from) . ' 00:00:00', $from) into date('H:i:s', $from) == '00:00:00'
alex: 1. change condition from
```
lang=php
$from == strtotime(date('Y-m-d', $from) . ' 00:00:00'… | |||||
} | } | ||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
elseif ($from === false && $to !== false) { | elseif ( $from === null && is_numeric($to) && date('H:i:s', $to) == '00:00:00' ) { | ||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
Not Done ReplyNOTE: battle against malformed dates entered by user
change into: if ( $from === null && is_numeric($to) ) { this way from date entered in incorrect format won't be handled as from date not specified alex: NOTE: battle against malformed dates entered by user
change into:
```
lang=php
if ( $from ===… | |||||
$to = strtotime(date('Y-m-d', $to) . ' 23:59:59', $to); // reset to evening | $from = $to; | ||||
$from = $to - $day_seconds; | $to += $day_seconds; | ||||
} | } | ||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
if ($from !== false && $to !== false) { | if ( is_numeric($from) && $to === null || $from === null && is_numeric($to) ) { | ||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
$from = $from === null ? $to : $from; | |||||
$to = $from; | |||||
Not Done Reply
$to == strtotime(date('Y-m-d', $to) . ' 00:00:00', $to) into date('H:i:s', $to) == '00:00:00'
alex: 1. change condition from
```
lang=php
$to == strtotime(date('Y-m-d', $to) . ' 00:00:00', $to)… | |||||
} | |||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
Not Done ReplyNOTE: battle against malformed dates entered by user
change into: if ( is_numeric($from) && $to === null || $from === null && is_numeric($to) ) { $from = $from === null ? $to : $from; $to = $from; } this way we won't replace malformed from/to date entered by user with to/from date, that user entered correctly alex: NOTE: battle against malformed dates entered by user
change into:
```
lang=php
if… | |||||
if ( is_numeric($from) && is_numeric($to) ) { | |||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
$from = strtotime(date('Y-m-d H:i', $from) . ':00', $from); | |||||
$to = strtotime(date('Y-m-d H:i', $to) . ':59', $to); | |||||
Not Done ReplyNOTE: battle against malformed dates entered by user
change into: if ( is_numeric($from) && is_numeric($to) ) { this way only correctly entered dates would be used in filter alex: NOTE: battle against malformed dates entered by user
change into:
```
lang=php
if… | |||||
$filter_value = $table_name.'`'.$field_name.'` >= '.$from.' AND '.$table_name.'`'.$field_name.'` <= '.$to; | $filter_value = $table_name.'`'.$field_name.'` >= '.$from.' AND '.$table_name.'`'.$field_name.'` <= '.$to; | ||||
Line exceeds 120 characters; contains 130 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 130 characters | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
Expected 1 space before concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceBefore: Expected 1 space before concat operator; 0 found | |||||
Expected 1 space after concat operator; 0 found Lint: CodingStandard.Strings.ConcatenationSpacing.NoSpaceAfter: Expected 1 space after concat operator; 0 found | |||||
} | } | ||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
else { | |||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
$filter_value = 'FALSE'; | |||||
} | |||||
Line indented incorrectly; expected 4 tabs, found 5 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 4 tabs, found 5 | |||||
Not Done ReplyNOTE: battle against malformed dates entered by user
Please add else statement, that would set $filter_value variable value to FALSE (as string). this way if we've submitted filter with incorrectly formatted date, then we'll see 0 records instead of all records alex: NOTE: battle against malformed dates entered by user
Please add `else` statement, that would… | |||||
break; | break; | ||||
case 'equals': | case 'equals': | ||||
case 'options': | case 'options': | ||||
$field_value = strlen($field_options['submit_value']) ? $this->Conn->qstr($field_options['submit_value']) : false; | $field_value = strlen($field_options['submit_value']) ? $this->Conn->qstr($field_options['submit_value']) : false; | ||||
if ($field_value) { | if ($field_value) { | ||||
$filter_value = $table_name.'`'.$field_name.'` = '.$field_value; | $filter_value = $table_name.'`'.$field_name.'` = '.$field_value; | ||||
} | } | ||||
Show All 38 Lines | |||||
} | } | ||||
/** | /** | ||||
* Enter description here... | * Enter description here... | ||||
* | * | ||||
* @param kdbItem $object | * @param kdbItem $object | ||||
* @param string $search_field | * @param string $search_field | ||||
* @param string $value | * @param string $value | ||||
* @param string $type | * @param string $type | ||||
Missing parameter comment Lint: CodingStandard.Commenting.FunctionComment.MissingParamComment: Missing parameter comment | |||||
Expected 2 spaces after parameter type; 1 found Lint: CodingStandard.Commenting.FunctionComment.SpacingAfterParamType: Expected 2 spaces after parameter type; 1 found | |||||
* @param string $format_option_prefix Format option prefix. | |||||
Expected 2 spaces after parameter type; 1 found Lint: CodingStandard.Commenting.FunctionComment.SpacingAfterParamType: Expected 2 spaces after parameter type; 1 found | |||||
*/ | */ | ||||
Missing @return tag in function comment Lint: CodingStandard.Commenting.FunctionComment.MissingReturn: Missing @return tag in function comment | |||||
function processRangeField(&$object, $search_field, $value, $type) | function processRangeField(&$object, $search_field, $value, $type, $format_option_prefix = '') | ||||
Line indented incorrectly; expected 1 tabs, found 2 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 1 tabs, found 2 | |||||
Visibility must be declared on method "processRangeField" Lint: Squiz.Scope.MethodScope.Missing: Visibility must be declared on method "processRangeField" | |||||
Type hint "kdbItem" missing for $object Lint: CodingStandard.Commenting.FunctionComment.TypeHintMissing: Type hint "kdbItem" missing for $object | |||||
{ | { | ||||
if ( !strlen($value[$type]) ) { | if ( !strlen($value[$type]) ) { | ||||
Line indented incorrectly; expected 2 tabs, found 3 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 2 tabs, found 3 | |||||
alexUnsubmitted Not Done Reply
When performing recursive method call the altered $value argument (trimmed & time added, when specified by user) is given and that results in the parsing error. Test plan fragment to cover this:
alex: # extract `$value[$type]` into temporary variable
# apply all manipulations, that were done on… | |||||
return false; | return null; | ||||
Not Done ReplyNOTE: battle against malformed dates entered by user
return null instead of false this way recipient would know if user haven't specified any value alex: NOTE: battle against malformed dates entered by user
return `null` instead of `false`… | |||||
} | } | ||||
Line indented incorrectly; expected 2 tabs, found 3 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 2 tabs, found 3 | |||||
$options = $object->GetFieldOptions($search_field); | $options = $object->GetFieldOptions($search_field); | ||||
$dt_separator = array_key_exists('date_time_separator', $options) ? $options['date_time_separator'] : ' '; | $dt_separator = array_key_exists('date_time_separator', $options) ? $options['date_time_separator'] : ' '; | ||||
$value[$type] = trim($value[$type], $dt_separator); // trim any | $value[$type] = trim($value[$type], $dt_separator); // trim any | ||||
$tmp_value = explode($dt_separator, $value[$type], 2); | $tmp_value = explode($dt_separator, $value[$type], 2); | ||||
if ( count($tmp_value) == 1 ) { | if ( count($tmp_value) == 1 ) { | ||||
Line indented incorrectly; expected 2 tabs, found 3 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 2 tabs, found 3 | |||||
No blank line found before "if" control structure Lint: CodingStandard.WhiteSpace.ControlStructureSpacing.NoLineBeforeOpen: No blank line found before "if" control structure | |||||
$time_format = $this->_getInputTimeFormat($options); | $time_format = $this->_getInputTimeFormat($options, $format_option_prefix . 'time_format'); | ||||
Lint: CodingStandard.WhiteSpace.CommaSpacing.After: Expected 1 space after comma; 2 found | |||||
Expected 1 space after comma in function call; 2 found Lint: Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma: Expected 1 space after comma in function call; 2 found | |||||
if ( $time_format ) { | if ( $time_format ) { | ||||
No blank line found before "if" control structure Lint: CodingStandard.WhiteSpace.ControlStructureSpacing.NoLineBeforeOpen: No blank line found before "if" control structure | |||||
Line indented incorrectly; expected 3 tabs, found 4 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 3 tabs, found 4 | |||||
// time is missing, but time format available -> guess time and add to date | // time is missing, but time format available -> guess time and add to date | ||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
Inline comments must end in full-stops, exclamation marks, or question marks Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
$time = ($type == 'from') ? adodb_mktime(0, 0, 0) : adodb_mktime(23, 59, 59); | $time = adodb_mktime(0, 0, 0); | ||||
$time = adodb_date($time_format, $time); | $time = adodb_date($time_format, $time); | ||||
$value[$type] .= $dt_separator . $time; | $value[$type] .= $dt_separator . $time; | ||||
} | } | ||||
} | } | ||||
alexUnsubmitted Not Done ReplyWith current test plan this code is never executed on recursive call to this method. I recommend debugging actual code to verify, that it works. alex: With current test plan this code is never executed on recursive call to this method. I… | |||||
/** @var kFormatter $formatter */ | /** @var kFormatter $formatter */ | ||||
$formatter = $this->Application->recallObject($options['formatter']); | $formatter = $this->Application->recallObject($options['formatter']); | ||||
$format = $options[$format_option_prefix . 'format']; | |||||
$value_ts = $formatter->Parse($value[$type], $search_field, $object); | $value_ts = $formatter->Parse($value[$type], $search_field, $object, $format); | ||||
if ( $object->GetErrorPseudo($search_field) ) { | if ( $object->GetErrorPseudo($search_field) ) { | ||||
// invalid format -> ignore this date in search | // invalid format -> ignore this date in search | ||||
$object->RemoveError($search_field); | $object->RemoveError($search_field); | ||||
if ( $format_option_prefix == 'input_' ) { | |||||
Line indented incorrectly; expected 3 tabs, found 4 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 3 tabs, found 4 | |||||
return false; | return false; | ||||
} | } | ||||
Line indented incorrectly; expected 3 tabs, found 4 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 3 tabs, found 4 | |||||
return $this->processRangeField($object, $search_field, $value, $type, 'input_'); | |||||
} | |||||
Line indented incorrectly; expected 2 tabs, found 3 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 2 tabs, found 3 | |||||
Not Done Replyremove else statement, but keep the code inside it since code inside else statement is always executed it's pointless to wrap return ... statements with it alex: remove `else` statement, but keep the code inside it
---
since code inside `else` statement… | |||||
return $value_ts; | return $value_ts; | ||||
} | } | ||||
/** | /** | ||||
* Returns InputTimeFormat using given field options | * Returns InputTimeFormat using given field options | ||||
* | * | ||||
* @param Array $field_options | * @param Array $field_options | ||||
Tag value indented incorrectly; expected 2 spaces but found 1 Lint: CodingStandard.Commenting.DocComment.TagValueIndent: Tag value indented incorrectly; expected 2 spaces but found 1 | |||||
Missing parameter comment Lint: CodingStandard.Commenting.FunctionComment.MissingParamComment: Missing parameter comment | |||||
Expected "array" but found "Array" for parameter type Lint: CodingStandard.Commenting.FunctionComment.IncorrectParamVarName: Expected "array" but found "Array" for parameter type | |||||
* @param string $format_option_name Format option name. | |||||
Tag value indented incorrectly; expected 2 spaces but found 1 Lint: CodingStandard.Commenting.DocComment.TagValueIndent: Tag value indented incorrectly; expected 2 spaces but found 1 | |||||
* @return string | * @return string | ||||
Tag cannot be grouped with parameter tags in a doc comment Lint: CodingStandard.Commenting.DocComment.NonParamGroup: Tag cannot be grouped with parameter tags in a doc comment | |||||
*/ | */ | ||||
function _getInputTimeFormat($field_options) | function _getInputTimeFormat($field_options, $format_option_name = 'input_time_format') | ||||
Visibility must be declared on method "_getInputTimeFormat" Lint: Squiz.Scope.MethodScope.Missing: Visibility must be declared on method "_getInputTimeFormat" | |||||
Line indented incorrectly; expected 1 tabs, found 2 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 1 tabs, found 2 | |||||
{ | { | ||||
if ( array_key_exists('input_time_format', $field_options) ) { | if ( array_key_exists($format_option_name, $field_options) ) { | ||||
Line indented incorrectly; expected 2 tabs, found 3 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 2 tabs, found 3 | |||||
return $field_options['input_time_format']; | return $field_options[$format_option_name]; | ||||
} | } | ||||
Line indented incorrectly; expected 2 tabs, found 3 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 2 tabs, found 3 | |||||
/** @var LanguagesItem $lang_current */ | /** @var LanguagesItem $lang_current */ | ||||
$lang_current = $this->Application->recallObject('lang.current'); | $lang_current = $this->Application->recallObject('lang.current'); | ||||
$field_name = str_replace(' ', '', ucwords(str_replace('_', ' ', $format_option_name))); | |||||
return $lang_current->GetDBField('InputTimeFormat'); | return $lang_current->GetDBField($field_name); | ||||
} | } | ||||
Line indented incorrectly; expected 1 tabs, found 2 Lint: Generic.WhiteSpace.ScopeIndent.IncorrectExact: Line indented incorrectly; expected 1 tabs, found 2 | |||||
/** | /** | ||||
* Resets current search | * Resets current search | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function resetSearch($event) | function resetSearch($event) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |
Line indented incorrectly; expected 4 tabs, found 5