ArrayField   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 26
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getDocumentFieldValue() 0 20 7
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity;
4
5
use Mdiyakov\DoctrineSolrBundle\Exception\InvalidFieldValueException;
6
7
class ArrayField extends Field
8
{
9
    /**
10
     * @param object $entity
11
     * @return string[]
12
     */
13
    public function getDocumentFieldValue($entity)
14
    {
15
        $result = [];
16
        $entityValue = $this->getEntityFieldValue($entity);
17
        if (!is_null($entityValue)) {
18
            if (is_scalar($entityValue)) {
19
                $entityValue =  [ $entityValue ];
20
            } elseif (
21
                !is_array($entityValue) &&
22
                ((!$entityValue instanceof \Iterator) && (!$entityValue instanceof \IteratorAggregate))
23
            ) {
24
                throw new InvalidFieldValueException('Field value must be \Iterator or \IteratorAggregate instance');
25
            }
26
27
            foreach ($entityValue as $value) {
28
                $result[] = strval($value);
29
            }
30
        }
31
32
        return $result;
33
    }
34
}