Code Duplication    Length = 24-24 lines in 2 locations

lib/midcom/helper/datamanager2/indexer/document.php 1 location

@@ 252-275 (lines=24) @@
249
     * @todo Refactor this to use DateTime
250
     * @param string $name The name of the field that should be stored
251
     */
252
    private function _add_as_date_field($name)
253
    {
254
        if ($this->_schema->fields[$name]['type'] == 'date')
255
        {
256
            $timestamp = 0;
257
            if (!$this->_datamanager->types[$name]->is_empty())
258
            {
259
                $timestamp = $this->_datamanager->types[$name]->value->format('U');
260
            }
261
            $this->add_date_pair($name, $timestamp);
262
        }
263
        else
264
        {
265
            $string = $this->_datamanager->types[$name]->convert_to_html();
266
            $timestamp = strtotime($string);
267
            if ($timestamp === -1)
268
            {
269
                debug_add("The string representation of the field {$name} could not be parsed into a timestamp; treating as 0.", MIDCOM_LOG_INFO);
270
                debug_print_r('String representation was:', $string);
271
                $timestamp = 0;
272
            }
273
            $this->add_date_pair($name, $timestamp);
274
        }
275
    }
276
277
    /**
278
     * This helper will process the given field using the guidelines given in

src/midcom/datamanager/indexer/document.php 1 location

@@ 250-273 (lines=24) @@
247
     * @todo Refactor this to use DateTime
248
     * @param string $name The name of the field that should be stored
249
     */
250
    private function add_as_date_field(FormView $field)
251
    {
252
        if ($field->vars['dm2_type'] == 'date')
253
        {
254
            $timestamp = 0;
255
            if (!$this->datamanager->types[$name]->is_empty())
256
            {
257
                $timestamp = $this->datamanager->types[$name]->value->format('U');
258
            }
259
            $this->add_date_pair($name, $timestamp);
260
        }
261
        else
262
        {
263
            $string = $this->datamanager->types[$name]->convert_to_html();
264
            $timestamp = strtotime($string);
265
            if ($timestamp === -1)
266
            {
267
                debug_add("The string representation of the field {$name} could not be parsed into a timestamp; treating as 0.", MIDCOM_LOG_INFO);
268
                debug_print_r('String representation was:', $string);
269
                $timestamp = 0;
270
            }
271
            $this->add_date_pair($name, $timestamp);
272
        }
273
    }
274
275
    /**
276
     * @param string $name The field name