Completed
Push — master ( c5047e...3a177f )
by Gabriel
03:52
created

StaticMethodsTrait::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Nip\Records\Locator\ModelLocator\Traits;
4
5
use Nip\Records\Locator\Exceptions\InvalidModelException;
6
use Nip\Records\RecordManager;
7
8
/**
9
 * Trait StaticMethodsTrait
10
 * @package Nip\Records\Locator\ModelLocator\Traits
11
 */
12
trait StaticMethodsTrait
13
{
14
    /**
15
     * @var self
16
     */
17
    static protected $instance;
18
19
    /**
20
     * @param $entityManager
21
     * @return RecordManager
22
     */
23 6
    public static function get($entityManager)
24
    {
25 6
        return self::instance()->getManager($entityManager);
0 ignored issues
show
Bug introduced by
It seems like getManager() 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...
26
    }
27
28
    /**
29
     * @param string $alias
30
     * @param RecordManager $entityManager
31
     * @return void`
0 ignored issues
show
Documentation introduced by
The doc-type void` could not be parsed: Unknown type name "void`" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
32
     */
33 1
    public static function set($alias, $entityManager)
34
    {
35 1
        self::instance()->getModelRegistry()->set($alias, $entityManager);
0 ignored issues
show
Bug introduced by
It seems like getModelRegistry() 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...
36 1
    }
37
38
    /**
39
     * Singleton
40
     *
41
     * @return self
42
     */
43 6
    public static function instance()
44
    {
45 6
        if (!(self::$instance instanceof self)) {
46 1
            self::$instance = new self();
47
        }
48 6
        return self::$instance;
49
    }
50
}
51