GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6bc7cf...be821e )
by James Ekow Abaka
05:06
created

Context::getModelTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace ntentan\nibii;
4
5
use ntentan\panie\Container;
6
7
/**
8
 * A collection of utility methods used as helpers for loading
9
 * models.
10
 */
11
class Context {
12
    
13
    private $container;
14
    private $dbContext;
15
    private static $instance;
16
    
17 36
    public function __construct(Container $container) {
18 36
        $this->container = $container;
19 36
        $this->dbContext = $container->resolve(\ntentan\atiaa\DbContext::class);
20
        $this->container->bind(interfaces\ModelJoinerInterface::class)
21
             ->to(Resolver::class);
22
        $this->container->bind(interfaces\TableNameResolverInterface::class)
23
             ->to(Resolver::class);
24
        $this->container->bind(interfaces\ModelClassResolverInterface::class)
25
             ->to(Resolver::class);
26
        self::$instance = $this;
27
    }
28
29
    /**
30
     * A helper for loading a method described as a string.
31
     * @param string $path Model name as string 
32
     * @return \nibii\RecordWrapper
33
     * @throws NibiiException
34
     */
35
    public function load($path) {
36
        try {
37
            return$this->container->resolve(self::getClassName($path));
38
        } catch (\ntentan\panie\exceptions\ResolutionException $e) {
39
            throw new
40
            NibiiException("Failed to load model [$path]. Please specify a valid database driver.");
41
        }
42
    }
43
44
    /**
45
     * Returns a class name for junction models needed to perform joint queries.
46
     * @param string $classA
47
     * @param string $classB
48
     * @return string
49
     */
50
    public function joinModels($classA, $classB) {
51
        return$this->container->singleton(interfaces\ModelJoinerInterface::class)
52
            ->getJunctionClassName($classA, $classB);
53
    }
54
55
    public function getModelTable($instance) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
56
        return$this->container->singleton(interfaces\TableNameResolverInterface::class)
57
            ->getTableName($instance);
58
    }
59
60
    public function getClassName($model, $context = null) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
61
        return$this->container->singleton(interfaces\ModelClassResolverInterface::class)
62
            ->getModelClassName($model, $context);
63
    }
64
65
    public function getModelName($class) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
66
        return $class;
67
    }
68
    
69
    public static function getInstance() {
70
        if(self::$instance === null) throw new NibiiException("A context has not yet been initialized");
71
        return self::$instance;
72
    }
73
    
74
    public function getContainer() {
75
        return $this->container;
76
    }
77
    
78
    public function getDbContext() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
79
        return $this->dbContext;
80
    }
81
    
82 36
    public function __destruct() {
83 36
        self::$instance = null;
84 36
    }
85
86
}
87