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.

GeneratorBundle/Helper/GeneratorUtils.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
namespace Kunstmaan\GeneratorBundle\Helper;
4
5
use Doctrine\ORM\Mapping\ClassMetadata;
6
use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
use Symfony\Component\HttpKernel\Kernel;
11
12
/**
13
 * GeneratorUtils
14
 */
15
class GeneratorUtils
16
{
17
    /**
18
     * Cleans the prefix. Prevents a double underscore from happening.
19
     *
20
     * @param $prefixString
21
     *
22
     * @return string
0 ignored issues
show
Should the return type not be null|string?

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...
23
     */
24 9
    public static function cleanPrefix($prefixString)
25
    {
26 9
        $prefixString = trim($prefixString);
27 9
        if (empty($prefixString)) {
28 3
            return null;
29
        }
30
31 6
        $result = preg_replace('/_*$/i', '', strtolower($prefixString)) . '_';
32
33 6
        if ($result == '_') {
34 1
            return null;
35
        }
36
37 5
        return $result;
38
    }
39
40
    /**
41
     * Returns an array of fields. Fields can be both column fields and
42
     * association fields.
43
     *
44
     * @param ClassMetadata $metadata
45
     *
46
     * @return array $fields
47
     */
48
    public static function getFieldsFromMetadata(ClassMetadata $metadata)
49
    {
50
        $fields = (array) $metadata->fieldNames;
51
52
        // Remove the primary key field if it's not managed manually
53
        if (!$metadata->isIdentifierNatural()) {
54
            $fields = array_diff($fields, $metadata->identifier);
55
        }
56
57
        foreach ($metadata->associationMappings as $fieldName => $relation) {
58
            if ($relation['type'] !== ClassMetadata::ONE_TO_MANY) {
59
                $fields[] = $fieldName;
60
            }
61
        }
62
63
        return $fields;
64
    }
65
66
    /**
67
     * Prepend the string in the file
68
     *
69
     * @param string $string   Text to be added in front of the file
70
     * @param string $filename File to prepend in
71
     */
72 View Code Duplication
    public static function prepend($string, $filename)
73
    {
74
        $context = stream_context_create();
75
        $fp = fopen($filename, 'r', 1, $context);
76
        $tmpname = md5($string);
77
        file_put_contents($tmpname, $string);
78
        file_put_contents($tmpname, $fp, FILE_APPEND);
79
        fclose($fp);
80
        unlink($filename);
81
        rename($tmpname, $filename);
82
    }
83
84
    /**
85
     * Append the string in the file
86
     *
87
     * @param string $string   Text to be added in front of the file
88
     * @param string $filename File to prepend in
89
     */
90 View Code Duplication
    public static function append($string, $filename)
91
    {
92
        $context = stream_context_create();
93
        $fp = fopen($filename, 'r', 1, $context);
94
        $tmpname = md5($string);
95
        file_put_contents($tmpname, $fp);
96
        file_put_contents($tmpname, $string, FILE_APPEND);
97
        fclose($fp);
98
        unlink($filename);
99
        rename($tmpname, $filename);
100
    }
101
102
    /**
103
     * Find and replace the string in the file
104
     *
105
     * @param string $toReplace   Text to be replaced
106
     * @param string $replaceText Text as replacement
107
     * @param string $filename    File to replace in
108
     */
109
    public static function replace($toReplace, $replaceText, $filename)
110
    {
111
        $content = file_get_contents($filename);
112
        if ($content) {
113
            $content = str_replace($toReplace, $replaceText, $content);
114
            file_put_contents($filename, $content);
115
        }
116
    }
117
118 1
    public static function getFullSkeletonPath($pathInSkeleton)
119
    {
120 1
        $pathInSkeleton = trim($pathInSkeleton);
121
122
        // pathInSkeleton needs to be prepended by a /
123 1
        if (substr($pathInSkeleton, 0, 1) !== '/') {
124
            $pathInSkeleton = '/' . $pathInSkeleton;
125
        }
126
127
        // Can't have a / at the end.
128 1
        if (substr($pathInSkeleton, -1) == '/') {
129
            $pathInSkeleton = rtrim($pathInSkeleton, '/');
130
        }
131
132 1
        return __DIR__ . '/../Resources/SensioGeneratorBundle/skeleton' . $pathInSkeleton;
133
    }
134
135
    public static function ensureOptionsProvided(InputInterface $input, array $options)
136
    {
137
        foreach ($options as $option) {
138
            if (null === $input->getOption($option)) {
139
                throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
140
            }
141
        }
142
    }
143
144
    /**
145
     * Replaces '\' with '/'.
146
     *
147
     * @param $namespace
148
     *
149
     * @return string
150
     */
151
    public static function fixNamespace($namespace)
152
    {
153
        return str_replace('\\', '/', $namespace);
154
    }
155
156
    /**
157
     * Returns an inputAssistant.
158
     *
159
     * This probably isn't the cleanest way. It'd be nicer if we could make a KunstmaanGenerator class
160
     * which all generators inherit from. It then provides a bunch of helper functions and a uniform manner
161
     * in which the input options are handled.
162
     *
163
     * @param InputInterface     $input
164
     * @param OutputInterface    $output
165
     * @param QuestionHelper     $questionHelper
166
     * @param Kernel             $kernel
167
     * @param ContainerInterface $container
168
     *
169
     * @return InputAssistant
170
     */
171
    public static function getInputAssistant(InputInterface &$input, OutputInterface $output, QuestionHelper $questionHelper, Kernel $kernel, ContainerInterface $container)
172
    {
173
        return new InputAssistant($input, $output, $questionHelper, $kernel, $container);
174
    }
175
}
176