Issues (38)

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/Normalizer/ObjectNormalizer.php (4 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 xAPI package.
5
 *
6
 * (c) Christian Flothmann <[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 Xabbuh\XApi\Serializer\Symfony\Normalizer;
13
14
use Xabbuh\XApi\Model\Activity;
15
use Xabbuh\XApi\Model\IRI;
16
use Xabbuh\XApi\Model\Object as LegacyStatementObject;
17
use Xabbuh\XApi\Model\StatementId;
18
use Xabbuh\XApi\Model\StatementObject;
19
use Xabbuh\XApi\Model\StatementReference;
20
use Xabbuh\XApi\Model\SubStatement;
21
22
/**
23
 * Normalizes and denormalizes xAPI statement objects.
24
 *
25
 * @author Christian Flothmann <[email protected]>
26
 */
27
final class ObjectNormalizer extends Normalizer
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function normalize($object, $format = null, array $context = array())
33
    {
34
        if ($object instanceof Activity) {
35
            $activityData = array(
36
                'objectType' => 'Activity',
37
                'id' => $object->getId()->getValue(),
38
            );
39
40
            if (null !== $definition = $object->getDefinition()) {
41
                $activityData['definition'] = $this->normalizeAttribute($definition, $format, $context);
42
            }
43
44
            return $activityData;
45
        }
46
47
        if ($object instanceof StatementReference) {
48
            return array(
49
                'objectType' => 'StatementRef',
50
                'id' => $object->getStatementId()->getValue(),
51
            );
52
        }
53
54
        if ($object instanceof SubStatement) {
55
            $data = array(
56
                'objectType' => 'SubStatement',
57
                'actor' => $this->normalizeAttribute($object->getActor(), $format, $context),
58
                'verb' => $this->normalizeAttribute($object->getVerb(), $format, $context),
59
                'object' => $this->normalizeAttribute($object->getObject(), $format, $context),
60
            );
61
62 View Code Duplication
            if (null !== $result = $object->getResult()) {
0 ignored issues
show
This code seems to be duplicated across 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...
63
                $data['result'] = $this->normalizeAttribute($result, $format, $context);
64
            }
65
66 View Code Duplication
            if (null !== $statementContext = $object->getContext()) {
0 ignored issues
show
This code seems to be duplicated across 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...
67
                $data['context'] = $this->normalizeAttribute($statementContext, $format, $context);
68
            }
69
70
            return $data;
71
        }
72
73
        return null;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function supportsNormalization($data, $format = null)
80
    {
81
        return $data instanceof LegacyStatementObject || $data instanceof StatementObject;
0 ignored issues
show
The class Xabbuh\XApi\Model\Object does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function denormalize($data, $class, $format = null, array $context = array())
88
    {
89
        if (!isset($data['objectType']) || 'Activity' === $data['objectType']) {
90
            return $this->denormalizeActivity($data, $format, $context);
91
        }
92
93
        if (isset($data['objectType']) && ('Agent' === $data['objectType'] || 'Group' === $data['objectType'])) {
94
            return $this->denormalizeData($data, 'Xabbuh\XApi\Model\Actor', $format, $context);
95
        }
96
97
        if (isset($data['objectType']) && 'SubStatement' === $data['objectType']) {
98
            return $this->denormalizeSubStatement($data, $format, $context);
99
        }
100
101
        if (isset($data['objectType']) && 'StatementRef' === $data['objectType']) {
102
            return new StatementReference(StatementId::fromString($data['id']));
103
        }
104
105
        return null;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function supportsDenormalization($data, $type, $format = null)
112
    {
113
        return in_array($type, array(Activity::class, LegacyStatementObject::class, StatementObject::class, StatementReference::class, SubStatement::class), true);
114
    }
115
116
    private function denormalizeActivity(array $data, $format = null, array $context = array())
117
    {
118
        $definition = null;
119
120
        if (isset($data['definition'])) {
121
            $definition = $this->denormalizeData($data['definition'], 'Xabbuh\XApi\Model\Definition', $format, $context);
122
        }
123
124
        return new Activity(IRI::fromString($data['id']), $definition);
125
    }
126
127
    private function denormalizeSubStatement(array  $data, $format = null, array $context = array())
128
    {
129
        $actor = $this->denormalizeData($data['actor'], 'Xabbuh\XApi\Model\Actor', $format, $context);
130
        $verb = $this->denormalizeData($data['verb'], 'Xabbuh\XApi\Model\Verb', $format, $context);
131
132 View Code Duplication
        if (class_exists(StatementObject::class)) {
0 ignored issues
show
This code seems to be duplicated across 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...
133
            $object = $this->denormalizeData($data['object'], StatementObject::class, $format, $context);
134
        } else {
135
            $object = $this->denormalizeData($data['object'], LegacyStatementObject::class, $format, $context);
136
        }
137
138
        $result = null;
139
        $statementContext = null;
140
141
        if (isset($data['result'])) {
142
            $result = $this->denormalizeData($data['result'], 'Xabbuh\XApi\Model\Result', $format, $context);
143
        }
144
145
        if (isset($data['context'])) {
146
            $statementContext = $this->denormalizeData($data['context'], 'Xabbuh\XApi\Model\Context', $format, $context);
147
        }
148
149
        return new SubStatement($actor, $verb, $object, $result, $statementContext);
150
    }
151
}
152