Issues (10)

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/OpenGraphGeneratorBuilder.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 Novaway\Component\OpenGraph;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Doctrine\Common\Annotations\CachedReader;
7
use Doctrine\Common\Annotations\Reader;
8
use Doctrine\Common\Cache\FilesystemCache;
9
use Metadata\Cache\FileCache;
10
use Metadata\MetadataFactory;
11
use Novaway\Component\OpenGraph\Builder\DefaultDriverFactory;
12
13
class OpenGraphGeneratorBuilder
14
{
15
    /** @var Reader */
16
    private $annotationReader;
17
18
    /** @var array */
19
    private $metadataDirectories;
20
21
    /** @var string */
22
    private $cacheDirectory;
23
24
    /** @var DefaultDriverFactory */
25
    private $driverFactory;
26
27
    /** @var bool */
28
    private $debug;
29
30
    /** @var bool */
31
    private $includeInterfaceMetadata;
32
33
34
    /**
35
     * Create builder instance
36
     *
37
     * @return static
38
     */
39
    public static function create()
40
    {
41
        return new static();
42
    }
43
44
    /**
45
     * Constructor
46
     */
47
    public function __construct()
48
    {
49
        $this->driverFactory = new DefaultDriverFactory();
50
51
        $this->debug = false;
52
        $this->includeInterfaceMetadata = false;
53
        $this->metadataDirectories = [];
54
    }
55
56
    /**
57
     * Create open graph object
58
     */
59
    public function build()
60
    {
61
        $annotationReader = $this->annotationReader;
62
        if (null === $annotationReader) {
63
            $annotationReader = new AnnotationReader();
64
            if (null !== $this->cacheDirectory) {
65
                $cacheDirectory = sprintf('%s/annotations', $this->cacheDirectory);
66
67
                $this->createDirectory($cacheDirectory);
68
                $annotationReader = new CachedReader($annotationReader, new FilesystemCache($cacheDirectory));
69
            }
70
        }
71
72
        $metadataDriver  = $this->driverFactory->createDriver($this->metadataDirectories, $annotationReader);
73
74
        $metadataFactory = new MetadataFactory($metadataDriver, null, $this->debug);
75
        $metadataFactory->setIncludeInterfaces($this->includeInterfaceMetadata);
76
77
        if (null !== $this->cacheDirectory) {
78
            $directory = sprintf('%s/metadata', $this->cacheDirectory);
79
80
            $this->createDirectory($directory);
81
            $metadataFactory->setCache(new FileCache($directory));
82
        }
83
84
        return new OpenGraphGenerator($metadataFactory);
85
    }
86
87
    /**
88
     * Set debug
89
     *
90
     * @param bool $debug
91
     * @return $this
92
     */
93
    public function setDebug($debug)
94
    {
95
        $this->debug = $debug;
96
97
        return $this;
98
    }
99
100
    /**
101
     * Include the metadata from the interfaces
102
     *
103
     * @param bool $include
104
     * @return $this
105
     */
106
    public function setIncludeInterfaceMetadata($include)
107
    {
108
        $this->includeInterfaceMetadata = $include;
109
110
        return $this;
111
    }
112
113
    /**
114
     * Set annotation reader
115
     *
116
     * @param Reader $reader
117
     * @return OpenGraphGeneratorBuilder
118
     */
119
    public function setAnnotationReader(Reader $reader)
120
    {
121
        $this->annotationReader = $reader;
122
123
        return $this;
124
    }
125
126
    /**
127
     * Set cache directory
128
     *
129
     * @param string $directory
130
     * @return OpenGraphGeneratorBuilder
131
     */
132
    public function setCacheDirectory($directory)
133
    {
134
        if (!is_dir($directory)) {
135
            $this->createDirectory($directory);
136
        }
137
138
        if (!is_writable($directory)) {
139
            throw new \InvalidArgumentException(sprintf('The cache directory "%s" is not writable.', $dir));
140
        }
141
142
        $this->cacheDirectory = $directory;
143
144
        return $this;
145
    }
146
147
    /**
148
     * Sets a map of namespace prefixes to directories.
149
     *
150
     * @param array $namespacePrefixToDirMap
151
     * @return OpenGraphGeneratorBuilder
152
     * @throws \InvalidArgumentException
153
     */
154
    public function setMetadataDirs(array $namespacePrefixToDirMap)
155
    {
156
        foreach ($namespacePrefixToDirMap as $dir) {
157
            if (!is_dir($dir)) {
158
                throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist.', $dir));
159
            }
160
        }
161
162
        $this->metadataDirectories = $namespacePrefixToDirMap;
163
164
        return $this;
165
    }
166
167
    /**
168
     * Adds a directory where the generator will look for class metadata.
169
     *
170
     * @param string $dir
171
     * @param string $namespacePrefix
172
     * @return OpenGraphGeneratorBuilder
173
     * @throws \InvalidArgumentException
174
     */
175 View Code Duplication
    public function addMetadataDir($dir, $namespacePrefix = '')
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...
176
    {
177
        if (!is_dir($dir)) {
178
            throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist.', $dir));
179
        }
180
181
        if (isset($this->metadataDirectories[$namespacePrefix])) {
182
            throw new \InvalidArgumentException(sprintf('There is already a directory configured for the namespace prefix "%s". Please use replaceMetadataDir() to override directories.', $namespacePrefix));
183
        }
184
185
        $this->metadataDirectories[$namespacePrefix] = $dir;
186
187
        return $this;
188
    }
189
190
    /**
191
     * Adds a map of namespace prefixes to directories.
192
     *
193
     * @param array $namespacePrefixToDirMap
194
     * @return OpenGraphGeneratorBuilder
195
     */
196
    public function addMetadataDirs(array $namespacePrefixToDirMap)
197
    {
198
        foreach ($namespacePrefixToDirMap as $prefix => $dir) {
199
            $this->addMetadataDir($dir, $prefix);
200
        }
201
202
        return $this;
203
    }
204
205
    /**
206
     * Similar to addMetadataDir(), but overrides an existing entry.
207
     *
208
     * @param string $dir
209
     * @param string $namespacePrefix
210
     * @return OpenGraphGeneratorBuilder
211
     * @throws \InvalidArgumentException
212
     */
213 View Code Duplication
    public function replaceMetadataDir($dir, $namespacePrefix = '')
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...
214
    {
215
        if (!is_dir($dir)) {
216
            throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist.', $dir));
217
        }
218
219
        if (!isset($this->metadataDirectories[$namespacePrefix])) {
220
            throw new \InvalidArgumentException(sprintf('There is no directory configured for namespace prefix "%s". Please use addMetadataDir() for adding new directories.', $namespacePrefix));
221
        }
222
223
        $this->metadataDirectories[$namespacePrefix] = $dir;
224
225
        return $this;
226
    }
227
228
    /**
229
     * Create directory
230
     *
231
     * @param string $directory
232
     */
233
    private function createDirectory($directory)
234
    {
235
        if (is_dir($directory)) {
236
            return;
237
        }
238
239
        if (false === @mkdir($directory, 0777, true)) {
240
            throw new \RuntimeException(sprintf('Could not create directory "%s".', $dir));
241
        }
242
    }
243
}
244