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/deprecated/field/Table.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
 * Created by PhpStorm.
4
 * User: VITALYIEGOROV
5
 * Date: 09.12.15
6
 * Time: 09:57
7
 */
8
namespace samsoncms\api\field;
9
10
use samsoncms\api\CMS;
11
use samsoncms\api\Field;
12
use samsoncms\api\Material;
13
use samsoncms\api\MaterialField;
14
use samsoncms\api\query\FieldNavigation;
15
use samsoncms\api\query\MaterialNavigation;
16
use samsonframework\orm\Condition;
17
use samsonframework\orm\ConditionInterface;
18
use samsonframework\orm\QueryInterface;
19
20
/**
21
 * Material additional fields table.
22
 * @package samsoncms\api
23
 * @deprecated Use \samsoncms\api\query\EntityTable
24
 */
25
class Table
26
{
27
    /** @var array Collection of real row field names  */
28
    protected static $fieldsRealNames = array();
29
30
    /** @var integer Navigation identifier for table structure */
31
    protected $navigationID;
32
33
    /** @var integer Table parent material identifier */
34
    protected $materialID;
35
36
    /** @var Field[] Collection field instances that correspond table columns */
37
    protected $fields;
38
39
    /** @var QueryInterface Database query interface */
40
    protected $query;
41
42
    /** @var string Locale identifier */
43
    protected $locale;
44
45
    /** @var Row[] Fields table rows collection */
46
    protected $collection = array();
47
48
    /** @var string Row class name */
49
    protected $rowInstance = '\samsoncms\api\field\Row';
50
51
    /**
52
     * FieldsTable constructor.
53
     *
54
     * @param QueryInterface $query        Database query interface
55
     * @param int[]          $navigationID Navigation identifier for table structure
56
     * @param integer        $materialID   Table parent material identifier
57
     * @param string|null    $locale       Locale identifier
58
     */
59
    public function __construct(QueryInterface $query, $navigationID, $materialID, $locale = null)
60
    {
61
        $this->query = $query;
62
        $this->navigationID = $navigationID;
0 ignored issues
show
Documentation Bug introduced by
It seems like $navigationID of type array<integer,integer> is incompatible with the declared type integer of property $navigationID.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
63
        $this->materialID = $materialID;
64
        $this->locale = $locale;
65
66
        $this->find();
67
    }
68
69
    /**
70
     * Fill table with data from database.
71
     */
72
    protected function find()
73
    {
74
        // Get table Fields instances
75
        $this->fields = (new FieldNavigation())->byRelationID($this->navigationID);
0 ignored issues
show
Documentation Bug introduced by
It seems like (new \samsoncms\api\quer...ID($this->navigationID) of type array<integer,*> is incompatible with the declared type array<integer,object<samsoncms\api\Field>> of property $fields.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
76
77
        $collection = array();
78
        if (count($rowIDs = $this->rowIDs())) {
79
            /** @var MaterialField $fieldValue Get additional field value instances */
80
            foreach ($this->query->entity(CMS::MATERIAL_FIELD_RELATION_ENTITY)
0 ignored issues
show
The expression $this->query->entity(\sa...$this->fields))->exec() of type boolean|array<integer,ob...k\orm\RecordInterface>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
81
                         // Get only needed rows(materials)
82
                         ->where(Material::F_PRIMARY, $rowIDs)
83
                         ->where(Material::F_DELETION, 1)
84
                         // Get correct localizes field condition for columns
85
                         ->whereCondition($this->fieldsCondition($this->fields))
86
                         ->exec() as $fieldValue) {
87
                /** @var Field $field Try to find Field instance by identifier */
88
                $field = &$this->fields[$fieldValue[Field::F_PRIMARY]];
89
                if (null !== $field) {
90
                    /**
91
                     * As we generate camelCase names for fields we need to store
92
                     * original names to get their values and correctly set row
93
                     * fields.
94
                     */
95
                    $fieldName = null !== static::$fieldsRealNames[$field->Name]
0 ignored issues
show
The property Name does not seem to exist in samsoncms\api\Field.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
96
                        ? static::$fieldsRealNames[$field->Name] : $field->Name;
97
                    /**
98
                     * Store table row(material) as it primary, store columns(Fields)
99
                     * by field primary. Use correct column for value.
100
                     */
101
                    $collection[$fieldValue[Material::F_PRIMARY]][$fieldName]
102
                        = $fieldValue[$field->valueFieldName()];
103
                }
104
            }
105
106
            /** @var Material[] $materials */
107
            $materials = $this->query->entity(Material::class)->where(Material::F_PRIMARY, array_keys($collection))->exec();
108
109
110
            // Go through collection again and created specific rows
111
            foreach ($collection as $materialID => $fields) {
112
                $this->collection[$materialID] = new $this->rowInstance($materialID, array_merge($fields, array('created' => $materials[$materialID]->Created, 'modified' => $materials[$materialID]->Modyfied)));
113
            }
114
        }
115
116
        return $this->collection;
117
    }
118
119
    /** @return array Collection of table rows(materials) identifiers */
120
    protected function rowIDs()
121
    {
122
        // Get collection of nested materials
123
        return $this->query
124
            ->entity(Material::class)
125
            ->where(Material::F_DELETION, 1)
126
            ->where(Material::F_PRIMARY, (new MaterialNavigation())->idsByRelationID($this->navigationID))
127
            ->where(Material::F_PARENT, $this->materialID)
128
            ->orderBy(Material::F_PRIORITY)
129
            ->fields(Material::F_PRIMARY);
130
    }
131
132
    /**
133
     * Build correct localized field request for retrieving additional fields records.
134
     *
135
     * @param Field[] $fields Collection of additional fields
136
     *
137
     * @return Condition Built condition for query
138
     */
139
    protected function fieldsCondition($fields)
140
    {
141
        // Group fields by localization
142
        $localizedColumns = array();
143
        $notLocalizedColumns = array();
144
        /** @var Field $field Iterate table columns(fields) */
145
        foreach ($fields as $field) {
146
            if ($field->localized()) {
147
                $localizedColumns[] = $field->id;
148
            } else {
149
                $notLocalizedColumns[] = $field->id;
150
            }
151
        }
152
153
        // Create field condition
154
        $fieldsCondition = new Condition(ConditionInterface::DISJUNCTION);
155
        // Create localized condition
156
        if (count($localizedColumns)) {
157
            $localizedCondition = new Condition(ConditionInterface::CONJUNCTION);
158
            $localizedCondition->add(Field::F_PRIMARY, $localizedColumns)
159
                ->add(MaterialField::F_LOCALE, $this->locale);
160
161
            // Add this condition to condition group
162
            $fieldsCondition->addCondition($localizedCondition);
163
        }
164
165
        // Create not localized condition
166
        if (count($notLocalizedColumns)) {
167
            $fieldsCondition->add(Field::F_PRIMARY, $notLocalizedColumns);
168
        }
169
170
        return $fieldsCondition;
171
    }
172
173
    /** @return array Get field table column names collection */
174
    public function columns()
175
    {
176
        return array_column($this->fields, Field::F_IDENTIFIER);
177
    }
178
179
    /**
180
     * Get collection of table column values as array.
181
     *
182
     * @param string $fieldID Additional field identifier
183
     *
184
     * @return array Collection of table column values as array
185
     */
186
    public function values($fieldID)
187
    {
188
        return (null !== $this->fields[$fieldID]) ? array_column($this->collection, $fieldID) : array();
189
    }
190
191
    /**
192
     * Get field table as multidimensional array.
193
     *
194
     * @return Row[] Field table represented as array
195
     */
196
    public function toArray()
197
    {
198
        return $this->collection;
199
    }
200
}
201