Completed
Push — master ( 554b31...9f86af )
by Nuno
31:31 queued 27:37
created

AggregatorCollection::__wakeup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 function get_class;
17
use Illuminate\Support\Collection;
18
use Illuminate\Queue\SerializesAndRestoresModelIdentifiers;
19
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
20
21
/**
22
 * @method static string searchable()
23
 * @method static string unsearchable()
24
 */
25
final class AggregatorCollection extends Collection
26
{
27
    use SerializesAndRestoresModelIdentifiers;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\Seriali...estoresModelIdentifiers requires some properties which are not provided by Algolia\ScoutExtended\Se...le\AggregatorCollection: $id, $class, $connection, $relations
Loading history...
28
29
    /**
30
     * The class name of the aggregator.
31
     *
32
     * @var string|null
33
     */
34
    public $aggregator;
35
36
    /**
37
     * Prepare the instance for serialization.
38
     *
39
     * @return array []string
40
     */
41 1
    public function __sleep()
42
    {
43 1
        $this->aggregator = get_class($this->first());
44
45
        $this->items = $this->getSerializedPropertyValue(EloquentCollection::make($this->map(function ($aggregator) {
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getSerializedProp...n(...) { /* ... */ }))) of type Illuminate\Contracts\Database\ModelIdentifier is incompatible with the declared type array of property $items.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46 1
            return $aggregator->getModel();
47 1
        })));
48
49 1
        return ['aggregator', 'items'];
50
    }
51
52
    /**
53
     * Restore the model after serialization.
54
     *
55
     * @return void
56
     */
57 1
    public function __wakeup()
58
    {
59
        $this->items = $this->getRestoredPropertyValue($this->items)->map(function ($model) {
60 1
            return $this->aggregator::create($model);
0 ignored issues
show
Bug introduced by
The method create() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
            return $this->aggregator::/** @scrutinizer ignore-call */ create($model);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61 1
        })->toArray();
62 1
    }
63
}
64