Issues (94)

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/FileSystem/FileSystem.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 declare(strict_types=1);
2
3
namespace Limoncello\Application\FileSystem;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use DirectoryIterator;
22
use Limoncello\Application\Exceptions\FileSystemException;
23
use Limoncello\Contracts\FileSystem\FileSystemInterface;
24
use function call_user_func;
25
use function file_exists;
26
use function file_get_contents;
27
use function file_put_contents;
28
use function is_dir;
29
use function is_writable;
30
use function iterator_to_array;
31
use function mkdir;
32
use function rmdir;
33 5
use function symlink;
34
use function unlink;
35 5
36
/**
37
 * @package Limoncello\Application
38
 *
39
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
40
 */
41 3
class FileSystem implements FileSystemInterface
42
{
43 3
    /**
44 3
     * @inheritdoc
45
     */
46 3
    public function exists(string $path): bool
47
    {
48
        return file_exists($path);
49
    }
50
51
    /**
52 2
     * @inheritdoc
53
     */
54 2
    public function read(string $filePath): string
55 2
    {
56
        $content = file_get_contents($filePath);
57
        $content !== false ?: $this->throwEx(new FileSystemException());
58
59
        return $content;
60
    }
61 5
62
    /**
63 5
     * @inheritdoc
64 5
     */
65
    public function write(string $filePath, string $contents): void
66
    {
67
        $bytesWritten = file_put_contents($filePath, $contents);
68
        $bytesWritten !== false ?: $this->throwEx(new FileSystemException());
69
    }
70 2
71
    /**
72 2
     * @inheritdoc
73
     */
74
    public function delete(string $filePath): void
75 2
    {
76
        $isDeleted = file_exists($filePath) === false || unlink($filePath) === true;
77 2
        $isDeleted === true ?: $this->throwEx(new FileSystemException());
78 2
    }
79
80
    /**
81 2
     * @inheritdoc
82
     */
83 2
    public function scanFolder(string $folderPath): array
84
    {
85 2
        is_dir($folderPath) === true ?: $this->throwEx(new FileSystemException());
86
87
        $iterator = call_user_func(function () use ($folderPath) {
88
            foreach (new DirectoryIterator($folderPath) as $directoryIterator) {
89
                /** @var DirectoryIterator $directoryIterator */
90
                if ($directoryIterator->isDot() === false) {
91 3
                    yield $directoryIterator->getFilename() => $directoryIterator->getRealPath();
92
                }
93 3
            }
94
        });
95
96
        $result = iterator_to_array($iterator);
97
98
        return $result;
99 1
    }
100
101 1
    /**
102
     * @inheritdoc
103
     */
104
    public function isFolder(string $path): bool
105
    {
106
        return is_dir($path);
107 1
    }
108
109 1
    /**
110 1
     * @inheritdoc
111
     */
112
    public function isWritable(string $path): bool
113
    {
114
        return is_writable($path);
115
    }
116 3
117
    /**
118 3
     * @inheritdoc
119 3
     */
120
    public function createFolder(string $folderPath): void
121
    {
122
        $isCreated = mkdir($folderPath);
123
        $isCreated === true ?: $this->throwEx(new FileSystemException());
124
    }
125 3
126
    /**
127 3
     * @inheritdoc
128 3
     */
129
    public function deleteFolder(string $folderPath): void
130
    {
131 3
        $isDeleted = is_dir($folderPath) === true && rmdir($folderPath) === true;
132
        $isDeleted === true ?: $this->throwEx(new FileSystemException());
133
    }
134
135
    /**
136
     * @inheritdoc
137 1
     */
138
    public function deleteFolderRecursive(string $folderPath): void
139 1
    {
140 1
        foreach ($this->scanFolder($folderPath) as $path) {
141
            $this->isFolder($path) === true ? $this->deleteFolderRecursive($path) : $this->delete($path);
142
        }
143
144
        $this->deleteFolder($folderPath);
145
    }
146 2
147
    /**
148
     * @inheritdoc
149 2
     */
150
    public function symlink(string $targetPath, string $linkPath): void
151 2
    {
152
        $isCreated = symlink($targetPath, $linkPath) === true;
153
        $isCreated === true ?: $this->throwEx(new FileSystemException());
154
    }
155
156
    /**
157
     * @inheritdoc
158
     */
159 2
    public function requireFile(string $path)
160
    {
161 2
        /** @noinspection PhpIncludeInspection */
162
        $result = require $path;
163
164
        return $result;
165
    }
166
167
    /**
168
     * @param FileSystemException $exception
169
     *
170
     * @return void
0 ignored issues
show
Consider making the return type a bit more specific; maybe use NoType.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
171
     */
172
    protected function throwEx(FileSystemException $exception): void
173
    {
174
        throw $exception;
175
    }
176
}
177