Issues (3099)

Security Analysis    not enabled

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/Command/Exporter/ExportCommandHandler.php (2 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
namespace Kunstmaan\TranslatorBundle\Service\Command\Exporter;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Kunstmaan\TranslatorBundle\Entity\Translation;
7
use Kunstmaan\TranslatorBundle\Model\Export\ExportCommand;
8
use Kunstmaan\TranslatorBundle\Model\Export\ExportFile;
9
use Kunstmaan\TranslatorBundle\Repository\TranslationRepository;
10
use Kunstmaan\TranslatorBundle\Service\Command\AbstractCommandHandler;
11
use Symfony\Component\HttpFoundation\Response;
12
13
/**
14
 * Parses an ExportCommand
15
 */
16
class ExportCommandHandler extends AbstractCommandHandler
17
{
18
    /**
19
     * @var Exporter
20
     */
21
    private $exporter;
22
23
    /**
24
     * @var TranslationRepository
25
     */
26
    private $translationRepository;
27
28
    /**
29
     * Execute an export command.
30
     * Get all translations per domain and sort on file.
31
     * A File has a domain locale, an extensions, with keywords and a ArrayCollection with translations.
32
     *
33
     * @param ExportCommand $exportCommand
34
     *
35
     * @return int total number of files imported
0 ignored issues
show
Should the return type not be integer|null?

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...
36
     */
37
    public function executeExportCommand(ExportCommand $exportCommand)
38
    {
39
        $exportFiles = $this->getExportFiles($exportCommand);
40
        $this->fillExportFilesContent($exportFiles);
41
    }
42
43
    /**
44
     * Execute an export to CSV command.
45
     *
46
     * @param ExportCommand $exportCommand
47
     *
48
     * @return string|Response
49
     */
50
    public function executeExportCSVCommand(ExportCommand $exportCommand)
51
    {
52
        $translations = $this->getTranslations($exportCommand);
53
        /** @var CSVFileExporter $exporter */
54
        $exporter = $this->exporter->getExporterByExtension($exportCommand->getFormat());
55
        $exporter->setLocales($this->determineLocalesToImport($exportCommand));
56
57
        return $exporter->export($translations);
58
    }
59
60
    /**
61
     * Convert an exportCommand into an array of translations
62
     *
63
     * @param ExportCommand $exportCommand
64
     *
65
     * @return array an array of translations
66
     */
67
    public function getTranslations(ExportCommand $exportCommand)
68
    {
69
        $locales = $this->determineLocalesToImport($exportCommand);
70
        $domains = $this->determineDomainsToImport($exportCommand);
71
72
        $translations = [];
73
        /** @var Translation $translation */
74
        foreach ($this->translationRepository->getTranslationsByLocalesAndDomains($locales, $domains) as $translation) {
75
            // Sort by translation key.
76
            $translations[$translation->getKeyword()][$translation->getLocale()] = $translation;
77
        }
78
79
        return $translations;
80
    }
81
82
    /**
83
     * Convert an exportCommand into an array of ExportFiles
84
     *
85
     * @param ExportCommand $exportCommand
86
     *
87
     * @return ArrayCollection an array of ExportFiles (without filecontent filled in)
88
     */
89 1
    public function getExportFiles(ExportCommand $exportCommand)
90
    {
91 1
        $locales = $this->determineLocalesToImport($exportCommand);
92 1
        $domains = $this->determineDomainsToImport($exportCommand);
93
94 1
        $translations = $this->translationRepository->getTranslationsByLocalesAndDomains($locales, $domains);
95
96 1
        $translationFiles = new ArrayCollection();
97
98
        /** @var Translation $translation */
99 1
        foreach ($translations as $translation) {
100 1
            $exportFileKey = $translation->getDomain() . '.' . $translation->getLocale() . '.' . $exportCommand->getFormat();
101
102 1
            if (!$translationFiles->containsKey($exportFileKey)) {
103 1
                $exportFile = new ExportFile();
104 1
                $exportFile->setExtension($exportCommand->getFormat());
105 1
                $exportFile->setDomain($translation->getDomain());
106 1
                $exportFile->setLocale($translation->getLocale());
107 1
                $translationFiles->set($exportFileKey, $exportFile);
108
            }
109
110 1
            $translationFiles->get($exportFileKey)->addTranslation($translation);
111
        }
112
113 1
        return $translationFiles;
114
    }
115
116
    /**
117
     * @param ArrayCollection $exportFiles
118
     */
119
    public function fillExportFilesContent(ArrayCollection $exportFiles)
120
    {
121
        foreach ($exportFiles as $exportFile) {
122
            $exportFile->fillArray();
123
            $content = $this->exporter->getExportedContent($exportFile);
124
            $exportFile->setContent($content);
125
        }
126
    }
127
128
    /**
129
     * Returns an array with all languages that needs to be imported (from the given ExportCommand)
130
     * If non is given, all managed locales will be used (defined in config)
131
     *
132
     * @param ExportCommand $exportCommand
133
     *
134
     * @return array all locales to import by the given ExportCommand
135
     */
136 1
    public function determineLocalesToImport(ExportCommand $exportCommand)
137
    {
138 1
        if ($exportCommand->getLocales() === false) {
139
            return $this->managedLocales;
140
        }
141
142 1
        return $this->parseRequestedLocales($exportCommand->getLocales());
0 ignored issues
show
$exportCommand->getLocales() is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
143
    }
144
145
    /**
146
     * @param ExportCommand $exportCommand
147
     *
148
     * @return array
149
     */
150 1
    public function determineDomainsToImport(ExportCommand $exportCommand)
151
    {
152 1
        if ($exportCommand->getDomains() === false) {
153
            return [];
154
        }
155
156 1
        return $this->parseRequestedDomains($exportCommand->getDomains());
157
    }
158
159
    /**
160
     * @param $exporter
161
     */
162
    public function setExporter($exporter)
163
    {
164
        $this->exporter = $exporter;
165
    }
166
167
    /**
168
     * @param $translationRepository
169
     */
170 1
    public function setTranslationRepository($translationRepository)
171
    {
172 1
        $this->translationRepository = $translationRepository;
173 1
    }
174
}
175