StringField::getDocumentFieldValue()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8333
c 0
b 0
f 0
cc 7
nc 4
nop 1
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity;
4
5
class StringField extends Field
6
{
7
    /**
8
     * @param object $entity
9
     * @return string
10
     */
11
    public function getDocumentFieldValue($entity)
12
    {
13
        $entityValue = $this->getEntityFieldValue($entity);
14
        $documentValue = '';
15
        if (is_scalar($entityValue)) {
16
            $documentValue = strval($entityValue);
17
        } elseif (is_array($entityValue) || $entityValue instanceof \Iterator || $entityValue instanceof \IteratorAggregate) {
18
            $documentValue = [];
19
            foreach ($entityValue as $value) {
20
                $documentValue[] = (string) $value;
21
            }
22
23
            $documentValue = join(',', $documentValue);
24
        } elseif (is_object($entityValue)) {
25
            $documentValue = (string) $entityValue;
26
        }
27
28
        return $documentValue;
29
    }
30
}