Issues (20)

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/Migration/MigrationManager.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
/*
4
 * This file is part of the webmozart/json package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\Json\Migration;
13
14
use stdClass;
15
use Webmozart\Assert\Assert;
16
use Webmozart\Json\Versioning\JsonVersioner;
17
use Webmozart\Json\Versioning\SchemaUriVersioner;
18
19
/**
20
 * Migrates a JSON object between different versions.
21
 *
22
 * The JSON object is expected to have the property "version" set.
23
 *
24
 * @since  1.3
25
 *
26
 * @author Bernhard Schussek <[email protected]>
27
 */
28
class MigrationManager
29
{
30
    /**
31
     * @var JsonVersioner
32
     */
33
    private $versioner;
34
35
    /**
36
     * @var JsonMigration[]
37
     */
38
    private $migrationsBySourceVersion = array();
39
40
    /**
41
     * @var JsonMigration[]
42
     */
43
    private $migrationsByTargetVersion = array();
44
45
    /**
46
     * @var string[]
47
     */
48
    private $knownVersions = array();
49
50
    /**
51
     * Creates a new migration manager.
52
     *
53
     * @param JsonMigration[]    $migrations The migrations migrating a JSON
54
     *                                       object between individual versions
55
     * @param JsonVersioner|null $versioner  The versioner that should be used
56
     */
57 11
    public function __construct(array $migrations, JsonVersioner $versioner = null)
58
    {
59 11
        Assert::allIsInstanceOf($migrations, __NAMESPACE__.'\JsonMigration');
60
61 11
        $this->versioner = $versioner ?: new SchemaUriVersioner();
62
63 11
        foreach ($migrations as $migration) {
64 11
            $this->migrationsBySourceVersion[$migration->getSourceVersion()] = $migration;
65 11
            $this->migrationsByTargetVersion[$migration->getTargetVersion()] = $migration;
66 11
            $this->knownVersions[] = $migration->getSourceVersion();
67 11
            $this->knownVersions[] = $migration->getTargetVersion();
68
        }
69
70 11
        $this->knownVersions = array_unique($this->knownVersions);
71
72 11
        uksort($this->migrationsBySourceVersion, 'version_compare');
73 11
        uksort($this->migrationsByTargetVersion, 'version_compare');
74 11
        usort($this->knownVersions, 'version_compare');
75 11
    }
76
77
    /**
78
     * Migrates a JSON object to the given version.
79
     *
80
     * @param stdClass $data          The JSON object
81
     * @param string   $targetVersion The version string
82
     */
83 9
    public function migrate(stdClass $data, $targetVersion)
84
    {
85 9
        $sourceVersion = $this->versioner->parseVersion($data);
86
87 9
        if (version_compare($targetVersion, $sourceVersion, '>')) {
88 4
            $this->up($data, $sourceVersion, $targetVersion);
89 5
        } elseif (version_compare($targetVersion, $sourceVersion, '<')) {
90 4
            $this->down($data, $sourceVersion, $targetVersion);
91
        }
92 5
    }
93
94
    /**
95
     * Returns all versions known to the manager.
96
     *
97
     * @return string[] The known version strings
98
     */
99 2
    public function getKnownVersions()
100
    {
101 2
        return $this->knownVersions;
102
    }
103
104 4 View Code Duplication
    private function up($data, $sourceVersion, $targetVersion)
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...
105
    {
106 4
        while (version_compare($sourceVersion, $targetVersion, '<')) {
107 4
            if (!isset($this->migrationsBySourceVersion[$sourceVersion])) {
108 1
                throw new MigrationFailedException(sprintf(
109 1
                    'No migration found to upgrade from version %s to %s.',
110
                    $sourceVersion,
111
                    $targetVersion
112
                ));
113
            }
114
115 3
            $migration = $this->migrationsBySourceVersion[$sourceVersion];
116
117
            // Final version too high
118 3
            if (version_compare($migration->getTargetVersion(), $targetVersion, '>')) {
119 1
                throw new MigrationFailedException(sprintf(
120 1
                    'No migration found to upgrade from version %s to %s.',
121
                    $sourceVersion,
122
                    $targetVersion
123
                ));
124
            }
125
126 3
            $migration->up($data);
127
128 3
            $this->versioner->updateVersion($data, $migration->getTargetVersion());
129
130 3
            $sourceVersion = $migration->getTargetVersion();
131
        }
132 2
    }
133
134 4 View Code Duplication
    private function down($data, $sourceVersion, $targetVersion)
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...
135
    {
136 4
        while (version_compare($sourceVersion, $targetVersion, '>')) {
137 4
            if (!isset($this->migrationsByTargetVersion[$sourceVersion])) {
138 1
                throw new MigrationFailedException(sprintf(
139 1
                    'No migration found to downgrade from version %s to %s.',
140
                    $sourceVersion,
141
                    $targetVersion
142
                ));
143
            }
144
145 3
            $migration = $this->migrationsByTargetVersion[$sourceVersion];
146
147
            // Final version too low
148 3
            if (version_compare($migration->getSourceVersion(), $targetVersion, '<')) {
149 1
                throw new MigrationFailedException(sprintf(
150 1
                    'No migration found to downgrade from version %s to %s.',
151
                    $sourceVersion,
152
                    $targetVersion
153
                ));
154
            }
155
156 3
            $migration->down($data);
157
158 3
            $this->versioner->updateVersion($data, $migration->getSourceVersion());
159
160 3
            $sourceVersion = $migration->getSourceVersion();
161
        }
162 2
    }
163
}
164