Issues (5)

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/MessageFileLanguage.php (3 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
 * Copyright (c) 2012-2015 Marc TEYSSIER
4
 * 
5
 * See the file LICENSE.txt for copying permission.
6
 */
7
namespace Mouf\Utils\I18n\Fine\Translator;
8
9
/**
10
 * The FineMessageLanguage class represents a PHP resource file that can be loaded / saved / modified.
11
 * There are many files for on language. Files are write with the start information of the key. Function used the separator ., - or _. 
12
 */
13
class MessageFileLanguage {
14
15
	/**
16
	 * The path to the folder to be loaded
17
	 * @var string
18
	 */
19
	private $folder;
20
21
	/**
22
	 * The array of messages in the folder loaded.
23
	 * @var array<string, string>
24
	 */
25
	private $msg = [];
26
27
	/**
28
	 * Language load
29
	 * @var string
30
	 */
31
	private $language = null;
32
	
33
	/**
34
	 * Loads all message for a language
35
	 * @param string $folder
36
	 * @param string $language
37
	 */
38
	public function __construct($folder, $language) {
39
		$this->folder = $folder;
40
		$this->language = $language;
41
42
		if(file_exists($folder."messages_".$language.".php")) {
43
			$this->msg = include($folder."messages_".$language.".php");
44
		}
45
	}
46
47
	/**
48
	 * Saves the file for current language
49
	 */
50
	public function save() {
51
		if($this->msg) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->msg of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
52
			ksort($this->msg);
53
			
54
			$file = $this->folder."messages_".$this->language.".php";
55
56
			$old = umask(00002);
57
58
			if (file_exists($file) && !is_writable($file)) {
59
				throw new FileTranslatorException('Cannot write to file "'.$file.'".');
60
			} elseif (!file_exists($file)) {
61
				if (!is_dir($this->folder)) {
62
					$result = mkdir($this->folder, 0775, true);
63
					if (!$result) {
64
						throw new FileTranslatorException('Cannot create directory "'.$this->folder.'".');
65
					}
66
				}
67
				if (!is_writable($this->folder)) {
68
					throw new FileTranslatorException('Cannot write to directory "'.$this->folder.'".');
69
				}
70
			}
71
72
73
			$fp = fopen($file, "w");
74
			fwrite($fp, "<?php\n");
75
			fwrite($fp, 'return ');
76
			fwrite($fp, var_export($this->msg, true));
77
			fwrite($fp, ";\n");
78
			
79
			fclose($fp);
80
			umask($old);
81
		}
82
	}
83
84
	/**
85
	 * Delete file of language (Delete language too)
86
	 * @param $language string Language to delete
87
	 */
88
	private function deleteFile() {
89
		if(file_exists($this->folder."messages_".$this->language.".php")) {
90
			unlink($this->folder."messages_".$this->language.".php");
91
		}
92
	}
93
	
94
	/**
95
	 * Set message for a key
96
	 * @param $key string Message key
97
	 * @param $message string Message
98
	 */
99
	public function setMessage($key, $message) {
100
		$this->msg[$key] = $message;
101
	}
102
103
	/**
104
	 * Sets messages
105
	 * 
106
	 * @param $translations array<string, string> To set many messages in one time. The array is key message.
107
	 */
108
	public function setMessages(array $translations) {
109
		foreach ($translations as $key => $message) {
110
			if($message) {
111
				$this->msg[$key] = $message;
112
			}
113
		}
114
	}
115
	
116
	/**
117
	 * Returns a message for the key $key.
118
	 * @var $key string Key of translation search.
119
	 */
120
	public function getMessage($key) {
121
		if (isset($this->msg[$key])) {
122
			return $this->msg[$key];
123
		} else {
124
			return null;
125
		}
126
	}
127
128
	/**
129
	 * Sets the message
130
	 * @var $key Remove a message for key
131
	 */
132
	public function deleteMessage($key) {
133
		if(isset($this->msg[$key])) {
134
			unset($this->msg[$key]);
135
		}
136
		if(!$this->msg) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->msg of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
137
			$this->deleteFile();
138
		}
139
	}
140
	
141
	/**
142
	 * Returns all messages for this file.
143
	 * @return array<string, string> Return the array of message (key, value)
0 ignored issues
show
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (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...
144
	 */
145
	public function getAllMessages() {
146
		return $this->msg;
147
	}
148
}
149