Issues (2)

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/FileInfo.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 FileNamingResolver;
4
5
/**
6
 * An IMMUTABLE object which represents abstract or real file or directory (folder)
7
 *
8
 * @author Victor Bocharsky <[email protected]>
9
 */
10
class FileInfo extends \SplFileInfo
11
{
12
    const SEPARATOR_DIRECTORY = DIRECTORY_SEPARATOR;
13
    const SEPARATOR_EXTENSION = '.';
14
15
    /**
16
     * Returns base name of file without extension (or base name of directory).
17
     *
18
     * @param string $suffix
19
     *
20
     * @return string
21
     */
22 13
    public function getBasename($suffix = null)
23
    {
24 13
        if (null === $suffix) {
25 13
            $suffix = static::SEPARATOR_EXTENSION.$this->getExtension();
26 13
        }
27
28 13
        return parent::getBasename((string)$suffix);
29
    }
30
31
    /**
32
     * Checks whether a file / directory exists.
33
     *
34
     * @return bool
35
     */
36 1
    public function isExists()
37
    {
38 1
        return file_exists($this->toString());
39
    }
40
41
    /**
42
     * Creates full pathname to the file / directory based on its path, basename and extension
43
     *
44
     * @param string $path Directory path to the file (or directory)
45
     * @param string $basename Base name of file without extension (or base name of directory)
46
     * @param string $extension [OPTIONAL] File extension (empty for directory)
47
     *
48
     * @return string
49
     */
50 13
    public static function createPathname($path, $basename, $extension = '')
51
    {
52
        $pathname = ''
53 13
            .static::purifyPath($path)
54 13
            .static::SEPARATOR_DIRECTORY
55 13
            .static::purifyBasename($basename)
56 13
        ;
57 13
        if ($extension) {
58
            $pathname .= ''
59
                .static::SEPARATOR_EXTENSION
60 13
                .static::purifyExtension($extension)
61 13
            ;
62 13
        }
63
64 13
        return $pathname;
65
    }
66
67
    /**
68
     * @param string $path
69
     *
70
     * @return string
71
     */
72 16
    public static function purifyPath($path)
73
    {
74 16
        $path = (string)$path;
75 16
        $path = trim($path);
76 16
        $path = rtrim($path, '\\/');
77
78 16
        return $path;
79
    }
80
81
    /**
82
     * @param string $basename
83
     *
84
     * @return string
85
     */
86 14
    public static function purifyBasename($basename)
87
    {
88 14
        $basename = (string)$basename;
89 14
        $basename = trim($basename);
90 14
        $basename = trim($basename, '\\/');
91
92 14
        return $basename;
93
    }
94
95
    /**
96
     * @param string $extension
97
     *
98
     * @return string
99
     */
100 14
    public static function purifyExtension($extension)
101
    {
102 14
        $extension = (string)$extension;
103 14
        $extension = trim($extension);
104 14
        $extension = ltrim($extension, '.');
105
106 14
        return $extension;
107
    }
108
109
    /**
110
     * Changes directory path to the file / directory.
111
     *
112
     * @param string $path
113
     *
114
     * @return FileInfo
115
     */
116 10
    public function changePath($path)
117
    {
118 10
        $pathname = $this->createPathname($path, $this->getBasename(), $this->getExtension());
119
120 10
        return new static($pathname);
121
    }
122
123
    /**
124
     * Changes base name of file without extension (or base name of directory).
125
     *
126
     * @param string $basename
127
     *
128
     * @return FileInfo
129
     */
130 10
    public function changeBasename($basename)
131
    {
132 10
        $pathname = $this->createPathname($this->getPath(), $basename, $this->getExtension());
133
134 10
        return new static($pathname);
135
    }
136
137
    /**
138
     * Changes file extension.
139
     *
140
     * @param string $extension
141
     *
142
     * @return FileInfo
143
     */
144 1
    public function changeExtension($extension)
145
    {
146 1
        $pathname = $this->createPathname($this->getPath(), $this->getBasename(), $extension);
147
148 1
        return new static($pathname);
149
    }
150
151
    /**
152
     * @param string $basePath
153
     *
154
     * @return string
155
     */
156 1 View Code Duplication
    public function getPathRelativeTo($basePath)
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...
157
    {
158 1
        $basePath = $this->purifyPath($basePath).static::SEPARATOR_DIRECTORY;
159
160 1
        $relativePath = $this->getPath();
161 1
        $prefix = mb_substr($relativePath, 0, mb_strlen($basePath));
162 1
        if ($prefix === $basePath) {
163 1
            $relativePath = mb_substr($relativePath, mb_strlen($prefix));
164 1
        }
165
166 1
        return $relativePath;
167
    }
168
169
    /**
170
     * @param string $basePathname
171
     *
172
     * @return string
173
     */
174 5 View Code Duplication
    public function getPathnameRelativeTo($basePathname)
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...
175
    {
176 5
        $basePathname = $this->purifyPath($basePathname).static::SEPARATOR_DIRECTORY;
177
178 5
        $relativePathname = $this->getPathname();
179 5
        $prefix = mb_substr($relativePathname, 0, mb_strlen($basePathname));
180 5
        if ($prefix === $basePathname) {
181 5
            $relativePathname = mb_substr($relativePathname, mb_strlen($prefix));
182 5
        }
183
184 5
        return $relativePathname;
185
    }
186
187
    /**
188
     * Converts object to a string representation.
189
     *
190
     * @return string
191
     */
192 11
    public function toString()
193
    {
194 11
        return (string)$this;
195
    }
196
}
197