Issues (58)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/ORMContext.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2014-2018 James Ekow Abaka Ainooson
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace ntentan\nibii;
28
29
use ntentan\atiaa\DbContext;
30
use ntentan\kaikai\Cache;
31
use ntentan\nibii\interfaces\DriverAdapterFactoryInterface;
32
use ntentan\nibii\interfaces\ModelFactoryInterface;
33
use ntentan\nibii\interfaces\ValidatorFactoryInterface;
34
35
/**
36
 * A global class with information and utilities required by the rest of the ORM system.
37
 */
38
class ORMContext
0 ignored issues
show
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
39
{
40
    private static $instance;
41
    private $cache;
42
    private $modelFactory;
43
    private $modelValidatorFactory;
44
    private $driverAdapterFactory;
45
46 36
    private function __construct(ModelFactoryInterface $modelFactory, DriverAdapterFactoryInterface $driverAdapterFactory, ValidatorFactoryInterface $modelValidatorFactory, Cache $cache)
47
    {
48 36
        $this->modelFactory = $modelFactory;
49 36
        $this->cache = $cache;
50 36
        $this->driverAdapterFactory = $driverAdapterFactory;
51 36
        $this->modelValidatorFactory = $modelValidatorFactory;
52 36
    }
53
54 36
    public static function initialize(ModelFactoryInterface $modelFactory, DriverAdapterFactoryInterface $driverAdapterFactory, ValidatorFactoryInterface $modelValidatorFactory, Cache $cache): self
55
    {
56 36
        self::$instance = new self($modelFactory, $driverAdapterFactory, $modelValidatorFactory, $cache);
57
58 36
        return self::$instance;
59
    }
60
61
    /**
62
     * A helper for loading a method described as a string.
63
     *
64
     * @param string $path Model name as string
65
     *
66
     * @throws NibiiException
67
     *
68
     * @return \nibii\RecordWrapper
69
     */
70 6
    public function load($path)
71
    {
72
        try {
73 6
            return $this->modelFactory->createModel($path, null);
74
        } catch (\ntentan\panie\exceptions\ResolutionException $e) {
0 ignored issues
show
The class ntentan\panie\exceptions\ResolutionException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
75
            throw new
76
            NibiiException("Failed to load model [$path]. The class [$className] could not be found.");
77
        }
78
    }
79
80
    /**
81
     * @param RecordWrapper $instance
82
     */
83 36
    public function getModelTable($instance)
0 ignored issues
show
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...
84
    {
85 36
        return $this->modelFactory->getModelTable($instance);
86
    }
87
88 36
    public function getDriverAdapter()
0 ignored issues
show
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...
89
    {
90 36
        return $this->driverAdapterFactory->createDriverAdapter();
91
    }
92
93
    /**
94
     * @param string $class
95
     */
96 28
    public function getModelName($class)
97
    {
98 28
        return $class;
99
    }
100
101 36
    public static function getInstance() : self
102
    {
103 36
        if (self::$instance === null) {
104
            throw new NibiiException('A context has not yet been initialized');
105
        }
106
107 36
        return self::$instance;
108
    }
109
110 28
    public function getCache()
111
    {
112 28
        return $this->cache;
113
    }
114
115
    public function getConfig()
0 ignored issues
show
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...
116
    {
117
        return $this->config;
0 ignored issues
show
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
118
    }
119
120 28
    public function getModelDescription($model) : ModelDescription
121
    {
122 28
        return new ModelDescription($model);
123
    }
124
125 10
    public function getModelValidatorFactory() : ValidatorFactoryInterface
126
    {
127 10
        return $this->modelValidatorFactory;
128
    }
129
130 12
    public function getModelFactory() : ModelFactoryInterface
131
    {
132 12
        return $this->modelFactory;
133
    }
134
135
    /**
136
     * @return \ntentan\atiaa\DbContext
0 ignored issues
show
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
137
     */
138 36
    public function getDbContext()
139
    {
140 36
        return DbContext::getInstance();
141
    }
142
143
    public function __destruct()
144
    {
145
        self::$instance = null;
146
    }
147
}
148