RepositoryProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 32
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 4 1
A getRepository() 0 11 2
1
<?php
2
/**
3
 * This file is part of Hydrogen package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace RDS\Hydrogen\Query;
11
12
use Doctrine\Common\Persistence\ObjectRepository;
13
use RDS\Hydrogen\Hydrogen;
14
use RDS\Hydrogen\Query;
15
16
/**
17
 * Trait RepositoryProvider
18
 * @mixin Query
19
 */
20
trait RepositoryProvider
21
{
22
    /**
23
     * @var ObjectRepository|Hydrogen
24
     */
25
    protected $repository;
26
27
    /**
28
     * @param ObjectRepository|Hydrogen $repository
29
     * @return Query|$this
30
     */
31 30
    public function from(ObjectRepository $repository): self
32
    {
33 30
        return $this->scope($this->repository = $repository);
0 ignored issues
show
Bug introduced by
It seems like scope() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34
    }
35
36
    /**
37
     * @return ObjectRepository|Hydrogen
38
     * @throws \LogicException
39
     */
40 30
    public function getRepository(): ObjectRepository
41
    {
42 30
        if ($this->repository === null) {
43
            $error = 'Query should be attached to repository';
44
            throw new \LogicException($error);
45
        }
46
47 30
        $this->bootIfNotBooted();
0 ignored issues
show
Bug introduced by
It seems like bootIfNotBooted() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
48
49 30
        return $this->repository;
50
    }
51
}
52