Test Failed
Push — develop ( 3663ad...1f9f00 )
by Nuno
04:47
created

ObjectsResolver::toUpdate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Scout Extended.
7
 *
8
 * (c) Algolia Team <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Algolia\ScoutExtended\Searchable;
15
16
use Illuminate\Support\Collection;
17
18
/**
19
 * @internal
20
 */
21
final class ObjectsResolver
22
{
23
    /**
24
     * Get an collection of objects to update
25
     * from the given searchables.
26
     *
27
     * @param \Illuminate\Support\Collection $searchables
28
     *
29
     * @return \Illuminate\Support\Collection
30
     */
31
    public function toUpdate(Collection $searchables): Collection
32
    {
33
        $result = [];
34
35
        foreach ($searchables as $key => $searchable) {
36
            if (empty($array = array_merge($searchable->toSearchableArray(), $searchable->scoutMetadata()))) {
37
                continue;
38
            }
39
40
            $array['objectID'] = $searchable->getScoutKey();
41
42
            $result[] = $array;
43
        }
44
45
        return collect($result);
46
    }
47
}
48