Issues (30)

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.

Service/Export/ExportManager.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
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\TranslationsBundle\Service\Export;
13
14
use ONGR\TranslationsBundle\Document\Message;
15
use ONGR\TranslationsBundle\Document\Translation;
16
use ONGR\TranslationsBundle\Service\TranslationManager;
17
use Symfony\Component\Filesystem\Filesystem;
18
use Symfony\Component\HttpFoundation\ParameterBag;
19
use Symfony\Component\Yaml\Parser as YamlParser;
20
/**
21
 * Class Export.
22
 */
23
class ExportManager
24
{
25
    /**
26
     * @var TranslationManager
27
     */
28
    private $translationManager;
29
30
    /**
31
     * @var YmlExport
32
     */
33
    private $exporter;
34
35
    /**
36
     * @var array
37
     */
38
    private $locales;
39
40
    /**
41
     * @var Translation[]
42
     */
43
    private $refresh = [];
44
45
    /**
46
     * @var YamlParser
47
     */
48
    private $parser;
49
50
    /**
51
     * @param ParameterBag   $loadersContainer
0 ignored issues
show
There is no parameter named $loadersContainer. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
52
     * @param TranslationManager $translationManager
53
     * @param YmlExport          $exporter
54
     */
55
    public function __construct(
56
        TranslationManager $translationManager,
57
        YmlExport $exporter
58
    ) {
59
        $this->parser = new YamlParser();
60
        $this->translationManager = $translationManager;
61
        $this->exporter = $exporter;
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function getLocales()
68
    {
69
        return $this->locales;
70
    }
71
72
    /**
73
     * @param array $locales
74
     */
75
    public function setLocales($locales)
76
    {
77
        $this->locales = $locales;
78
    }
79
80
    /**
81
     * Exports translations from ES to files.
82
     *
83
     * @param array $domains To export.
84
     * @param bool  $force
85
     */
86
    public function export($domains = [], $force = null)
87
    {
88
        foreach ($this->formExportList($domains, $force) as $file => $translations) {
0 ignored issues
show
It seems like $force defined by parameter $force on line 86 can also be of type null; however, ONGR\TranslationsBundle\...nager::formExportList() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
89
            if (!file_exists($file)) {
90
                (new Filesystem())->touch($file);
91
            }
92
93
            $currentTranslations = $this->parser->parse(file_get_contents($file)) ?? [];
94
95
            $currentTranslations = $this->flatten($currentTranslations);
96
97
            $translations = array_replace_recursive($currentTranslations, $translations);
98
99
            $this->exporter->export($file, $translations);
100
        }
101
102
        $this->translationManager->save($this->refresh);
103
        $this->refresh = [];
104
    }
105
106
107
    /**
108
     * Flatten multidimensional array and concatenating keys
109
     *
110
     * @param $array
111
     * @return array
112
     */
113 View Code Duplication
    private function flatten($array, $prefix = '') {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
        $result = [];
115
        foreach($array as $key=>$value) {
116
            if(is_array($value)) {
117
                $result = $result + $this->flatten($value, $prefix . $key . '.');
118
            }
119
            else {
120
                $result[$prefix . $key] = $value;
121
            }
122
        }
123
        return $result;
124
    }
125
126
    /**
127
     * Get translations for export.
128
     *
129
     * @param array $domains To read from storage.
130
     * @param bool  $force   Determines if the message status is relevant.
131
     *
132
     * @return array
133
     */
134
    private function formExportList($domains, $force)
135
    {
136
        $output = [];
137
        $filters = array_filter([
138
            'messages.locale' => $this->getLocales(),
139
            'domain' => $domains
140
        ]);
141
142
        $translations = $this->translationManager->getAll($filters);
143
144
        /** @var Translation $translation */
145
        foreach ($translations as $translation) {
146
            $messages = $translation->getMessages();
147
148
            foreach ($messages as $key => $message) {
149
                if ($message->getStatus() === Message::DIRTY || $force) {
150
                    $path = sprintf(
151
                        '%s' . DIRECTORY_SEPARATOR . '%s.%s.%s',
152
                        $translation->getPath(),
153
                        'messages',
154
                        $message->getLocale(),
155
                        $translation->getFormat()
156
                    );
157
                    $output[$path][$translation->getKey()] = $message->getMessage();
158
159
                    $message->setStatus(Message::FRESH);
160
                    $this->refresh[] = $translation;
161
                }
162
            }
163
        }
164
165
        return $output;
166
    }
167
}
168