Issues (1)

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/LogFactory.php (1 issue)

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
 * @link https://github.com/old-town/old-town-log
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace OldTown\Log;
7
8
use OldTown\Log\Exception\DomainException;
9
use OldTown\Log\Exception\InvalidArgumentException;
10
use Psr\Log\LoggerInterface;
11
use ReflectionClass;
12
13
/**
14
 * Class LogFactory
15
 *
16
 * @package OldTown\Log
17
 */
18
abstract class LogFactory
19
{
20
    /**
21
     * Имя класса логеа по умолчнаию
22
     *
23
     * @var string
24
     */
25
    protected static $defaultLoggerClass = '\Psr\Log\NullLogger';
26
27
    /**
28
     * @var LoggerInterface
29
     */
30
    protected static $log;
31
32
    /**
33
     * Обязательные методы логера
34
     *
35
     * @var array|null
36
     */
37
    protected static $requiredLoggerMethods;
38
39
    /**
40
     * Возвращает логер
41
     *
42
     * @param null $param
43
     *
44
     * @return LoggerInterface
45
     *
46
     * @throws \OldTown\Log\Exception\InvalidArgumentException
47
     * @throws \OldTown\Log\Exception\DomainException
48
     */
49
    public static function getLog($param = null)
50
    {
51
        if (static::$log instanceof LoggerInterface) {
52
            return static::$log;
53
        }
54
        if (null === $param) {
55
            $defaultLogger = static::$defaultLoggerClass;
56
            static::$log = new $defaultLogger();
57
        } elseif ($param instanceof LoggerInterface) {
58
            static::$log = $param;
59
        } elseif (class_exists($param)) {
60
            static::$log = new $param();
61
        } else {
62
            $errMsg = 'Не удалось создасть логер';
63
            throw new InvalidArgumentException($errMsg);
64
        }
65
66
        if (!is_object(static::$log)) {
67
            $errMsg = 'Ошибка при создание логера';
68
            throw new InvalidArgumentException($errMsg);
69
        }
70
71
        static::validLogger(static::$log);
72
73
        return static::$log;
74
    }
75
76
    /**
77
     * Проверка логера на валидность
78
     *
79
     * @param $logger
80
     * @throws InvalidArgumentException
81
     * @throws DomainException
82
     */
83
    public static function validLogger($logger)
84
    {
85
        if (!is_object($logger)) {
86
            $errMsg = 'Логер должен быть объектом';
87
            throw new InvalidArgumentException($errMsg);
88
        }
89
90
        $loggerMethods = static::getRequiredLoggerMethods();
91
        foreach ($loggerMethods as $method) {
92
            if (!method_exists($logger, $method)) {
93
                $errMsg = "У логера должен быть метод {$method}";
94
                throw new DomainException($errMsg);
95
            }
96
        }
97
    }
98
99
    /**
100
     * Возвращает обязательные методы логера
101
     *
102
     * @return array
103
     */
104
    protected static function getRequiredLoggerMethods()
105
    {
106
        if (self::$requiredLoggerMethods) {
107
            return self::$requiredLoggerMethods;
108
        }
109
110
        $rLoggerInterface = new ReflectionClass(LoggerInterface::class);
111
        $loggerMethods = $rLoggerInterface->getMethods();
112
113
        self::$requiredLoggerMethods = [];
114
115
        foreach ($loggerMethods as $method) {
116
            $methodName = $method->getName();
0 ignored issues
show
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
117
            self::$requiredLoggerMethods[$methodName] = $methodName;
118
        }
119
120
121
        return self::$requiredLoggerMethods;
122
    }
123
}
124