Completed
Push — master ( 3d45a5...2bc3d9 )
by Sergey
15:01
created

ElasticsearchModel::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Isswp101\Persimmon;
4
5
use Elasticsearch\Client;
6
use Isswp101\Persimmon\Collection\ElasticsearchCollection;
7
use Isswp101\Persimmon\DAL\ElasticsearchDAL;
8
use Isswp101\Persimmon\Traits\Elasticsearchable;
9
use Isswp101\Persimmon\Traits\Mappingable;
10
use Isswp101\Persimmon\Traits\Relationshipable;
11
12
class ElasticsearchModel extends Model
13
{
14
    use Elasticsearchable, Mappingable, Relationshipable;
15
16
    /**
17
     * @var ElasticsearchDAL
18
     */
19
    public $_dal;
20
21
    public function __construct(array $attributes = [])
22
    {
23
        $this->validateIndexAndType();
24
25
        parent::__construct($attributes);
26
    }
27
28
    public function injectDependencies()
29
    {
30
        // @TODO: move logger to DAL
31
        $this->injectDataAccessLayer(new ElasticsearchDAL($this, app(Client::class)));
32
        // $this->injectLogger(app(Log::class));
1 ignored issue
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
    }
34
35
    public static function findWithParentId($id, $parentId, array $columns = ['*'])
36
    {
37
        /** @var static $model */
38
        $model = parent::find($id, $columns, ['parent_id' => $parentId]);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (find() instead of findWithParentId()). Are you sure this is correct? If so, you might want to change this to $this->find().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
39
40
        if ($model) {
41
            $model->setParentId($parentId);
42
        }
43
44
        return $model;
45
    }
46
47
    /**
48
     * @param array $query
49
     * @return ElasticsearchCollection|static[]
50
     */
51
    public static function search($query = [])
52
    {
53
        $model = static::createInstance();
54
55
        return $model->_dal->search($query);
56
    }
57
}