Completed
Push — master ( 0219a7...757819 )
by Brent
11s
created

Builder::find()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
1
<?php
2
3
namespace Spatie\BinaryUuid;
4
5
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
6
7
class Builder extends EloquentBuilder {
8
  /**
9
   * Find a model by its primary key.
10
   *
11
   * @param  mixed  $id
12
   * @param  array  $columns
13
   * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|null
14
   */
15
  public function find($id, $columns = ['*'])
16
  {
17
      if (is_array($id) || $id instanceof Arrayable) {
0 ignored issues
show
Bug introduced by
The class Spatie\BinaryUuid\Arrayable does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
18
          return $this->findMany($id, $columns);
19
      }
20
21
      return $this->withUuid($id)->first($columns);
0 ignored issues
show
Documentation Bug introduced by
The method withUuid does not exist on object<Spatie\BinaryUuid\Builder>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
22
  }
23
24
  /**
25
   * Find multiple models by their primary keys.
26
   *
27
   * @param  \Illuminate\Contracts\Support\Arrayable|array  $ids
28
   * @param  array  $columns
29
   * @return \Illuminate\Database\Eloquent\Collection
30
   */
31
  public function findMany($ids, $columns = ['*'])
32
  {
33
      if (empty($ids)) {
34
          return $this->model->newCollection();
35
      }
36
37
      return $this->withUuid($ids)->get($columns);
0 ignored issues
show
Documentation Bug introduced by
The method withUuid does not exist on object<Spatie\BinaryUuid\Builder>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
38
  }
39
}
40