Issues (168)

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/generator/VirtualEntity.php (10 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
//[PHPCOMPRESSOR(remove,start)]
3
/**
4
 * Created by Vitaly Iegorov <[email protected]>.
5
 * on 22.03.16 at 15:46
6
 */
7
namespace samsoncms\api\generator;
8
9
use samsoncms\api\Entity;
10
use samsoncms\api\Field;
11
use samsoncms\api\generator\metadata\VirtualMetadata;
12
13
/**
14
 * Virtual entity class generator.
15
 *
16
 * @package samsoncms\api\generator
17
 */
18
class VirtualEntity extends RealEntity
19
{
20
    /**
21
     * Class uses generation part.
22
     *
23
     * @param VirtualMetadata $metadata Entity metadata
24
     */
25
    protected function createUses($metadata)
26
    {
27
        $this->generator
28
            ->newLine('use samsonframework\core\ViewInterface;')
29
            ->newLine('use samsonframework\orm\QueryInterface;')
30
            ->newLine();
31
    }
32
33
    /**
34
     * Class definition generation part.
35
     *
36
     * @param VirtualMetadata $metadata Entity metadata
37
     */
38
    protected function createDefinition($metadata)
39
    {
40
        /**
41
         * TODO: Parent problem
42
         * Should be changed to merging fields instead of extending with OOP for structure_relation support
43
         * or creating traits and using them on shared parent entities.
44
         */
45
        $parentClass = null !== $metadata->parent
46
            ? $metadata->parent->entityClassName
47
            : '\\'.\samsoncms\api\Entity::class;
48
49
        $this->generator
50
            ->multiComment(array('"' . $metadata->entityRealName . '" database entity class'))
51
            ->defClass($this->className, $parentClass)
52
            ->newLine('use \samsoncms\api\generated\TableTrait;')
53
            ->newLine();
54
    }
55
56
    /**
57
     * Class constants generation part.
58
     *
59
     * @param VirtualMetadata $metadata Entity metadata
60
     */
61
    protected function createConstants($metadata)
62
    {
63
        $this->generator
64
            ->commentVar('string', 'Entity full class name, use ::class instead')
65
            ->defClassConst('ENTITY', $metadata->entityClassName)
66
            ->commentVar('string', 'Entity manager full class name')
67
            ->defClassConst('MANAGER', $metadata->entityClassName . 'Query')
68
            ->commentVar('string', 'Entity database identifier')
69
            ->defClassConst('IDENTIFIER', $metadata->entityID)
70
            ->commentVar('string', 'Not transliterated entity name')
71
            ->defClassConst('NAME', $metadata->entityRealName);
72
73
        // Create all entity fields constants storing each additional field metadata
74
        foreach ($metadata->fields as $fieldID => $fieldName) {
75
            $this->generator
76
                ->commentVar('string', $metadata->fieldDescriptions[$fieldID] . ' variable name')
77
                ->defClassConst('F_' . $fieldName, $fieldName)
78
                ->commentVar('string', $metadata->fieldDescriptions[$fieldID] . ' additional field identifier')
79
                ->defClassConst('F_' . $fieldName . '_ID', $fieldID);
80
        }
81
    }
82
83
    /**
84
     * Class static fields generation part.
85
     *
86
     * @param VirtualMetadata $metadata Entity metadata
87
     */
88 View Code Duplication
    protected function createStaticFields($metadata)
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...
89
    {
90
        $this->generator
91
            ->commentVar('array', '@deprecated Old ActiveRecord data')
92
            ->defClassVar('$_sql_select', 'public static ', $metadata->arSelect)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...ericMetadata::$arSelect has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
93
            ->commentVar('array', '@deprecated Old ActiveRecord data')
94
            ->defClassVar('$_attributes', 'public static ', $metadata->arAttributes)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...Metadata::$arAttributes has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
95
            ->commentVar('array', '@deprecated Old ActiveRecord data')
96
            ->defClassVar('$_map', 'public static ', $metadata->arMap)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...GenericMetadata::$arMap has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
97
            ->commentVar('array', '@deprecated Old ActiveRecord data')
98
            ->defClassVar('$_sql_from', 'public static ', $metadata->arFrom)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...enericMetadata::$arFrom has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
99
            ->commentVar('array', '@deprecated Old ActiveRecord data')
100
            ->defClassVar('$_own_group', 'public static ', $metadata->arGroup)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...nericMetadata::$arGroup has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
101
            ->commentVar('array', '@deprecated Old ActiveRecord data')
102
            ->defClassVar('$_relation_alias', 'public static ', $metadata->arRelationAlias)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...adata::$arRelationAlias has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
103
            ->commentVar('array', '@deprecated Old ActiveRecord data')
104
            ->defClassVar('$_relation_type', 'public static ', $metadata->arRelationType)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...tadata::$arRelationType has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
105
            ->commentVar('array', '@deprecated Old ActiveRecord data')
106
            ->defClassVar('$_relations', 'public static ', $metadata->arRelations)
0 ignored issues
show
Deprecated Code introduced by
The property samsoncms\api\generator\...cMetadata::$arRelations has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
107
            ->commentVar('array', 'Collection of navigation identifiers')
108
            ->defClassVar('$navigationIDs', 'protected static', array($metadata->entityID))
109
            ->defClassVar('$fieldIDs', 'public static', $metadata->fields)
110
            ->commentVar('array', 'Collection of additional fields value column names')
111
            ->defClassVar('$fieldValueColumns', 'public static', $metadata->allFieldValueColumns)
112
        ;
113
    }
114
115
    /**
116
     * Class fields generation part.
117
     *
118
     * @param VirtualMetadata $metadata Entity metadata
119
     */
120 View Code Duplication
    protected function createFields($metadata)
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...
121
    {
122
        foreach ($metadata->fields as $fieldID => $fieldName) {
123
            $this->generator
124
                ->commentVar($metadata->types[$fieldID], $metadata->fieldDescriptions[$fieldID])
125
                ->defClassVar('$' . $fieldName, 'public');
126
        }
127
    }
128
129
    /**
130
     * Class methods generation part.
131
     *
132
     * @param VirtualMetadata $metadata Entity metadata
133
     */
134
    protected function createMethods($metadata)
135
    {
136
        $methods = [];
137
        // Generate Query::where() analog for specific field.
138
        foreach ($metadata->fields as $fieldID => $fieldName) {
139
            try {
140
                // We need only gallery fields
141
                if ($metadata->allFieldCmsTypes[$fieldID] === Field::TYPE_GALLERY) {
142
                    $galleryName = preg_replace('/Gallery$/i', '', $fieldName) . 'Gallery';
143
144
                    $code = "\n\t" . '/**';
145
                    $code .= "\n\t" . ' * Get ' . $fieldName . '(#' . $fieldID . ') gallery collection instance.';
146
                    $code .= "\n\t" . ' * @param ViewInterface $renderer Render instance';
147
                    $code .= "\n\t" . ' *';
148
                    $code .= "\n\t" . ' * @return GalleryCollection Gallery collection instance';
149
                    $code .= "\n\t" . ' */';
150
                    $code .= "\n\t" . 'public function create' . ucfirst($galleryName) . '(ViewInterface $renderer)';
151
                    $code .= "\n\t" . '{';
152
                    $code .= "\n\t\t" . '$gallery = (new GalleryCollection($renderer, $this->query))->materialID($this->id);';
153
                    $code .= "\n\t\t" . 'if(null !== ($materialFieldID = (new MaterialFieldQuery($this->query))->materialID($this->id)->fieldID('.$fieldID.')->first())) {';
154
                    $code .= "\n\t\t\t" . '$gallery->materialFieldID($materialFieldID->id);';
155
                    $code .= "\n\t\t" . '}';
156
                    $code .= "\n\t\t" . 'return $gallery;';
157
                    $code .= "\n\t" . '}';
158
159
                    $methods[] = $code;
160
                }
161
            } catch (\Exception $e) {
162
                throw new \Exception($metadata->entity . ' cms field type for [' . $fieldName . '] not found');
163
            }
164
        }
165
166
        // Add method text to generator
167
        $this->generator->text(implode("\n", $methods));
168
    }
169
}
170
//[PHPCOMPRESSOR(remove,end)]
171