Issues (127)

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.

components/composite/controller.php (13 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
namespace Amarkal\UI;
4
5
/**
6
 * Implements a Composite UI component.
7
 */
8
class Component_composite
9
extends AbstractComponent
0 ignored issues
show
The extends keyword must be on the same line as the class name
Loading history...
10
implements ValueComponentInterface, 
0 ignored issues
show
The implements keyword must be on the same line as the class name
Loading history...
The first item in a multi-line implements list must be on the line following the implements keyword
Loading history...
11
           DisableableComponentInterface,
0 ignored issues
show
Expected 4 spaces before interface name; 11 found
Loading history...
12
           FilterableComponentInterface,
0 ignored issues
show
Expected 4 spaces before interface name; 11 found
Loading history...
13
           ValidatableComponentInterface
0 ignored issues
show
Expected 4 spaces before interface name; 11 found
Loading history...
14
{
15
    /**
16
     * The list of child components.
17
     * 
18
     * @var UI\AbstractComponent[] 
19
     */
20
    private $components;
21
    
22
    public $component_type = 'composite';
23
    
24
    /**
25
     * The __set magic method is overridden here to apply value & name changes to 
26
     * child components.
27
     */
28
    public function __set( $name, $value )
29
    {
30
        parent::__set($name, $value);
31
        
32
        if( 'value' === $name )
33
        {
34
            $this->set_value($value);
35
        }
36
37
        if( 'name' === $name )
38
        {
39
            $this->set_name($value);
40
        }
41
    }
42
    
43
    /**
44
     * Apply the value to each of the child components.
45
     * 
46
     * @param array $value
47
     * @return void
48
     */
49
    public function set_value( array $value )
50
    {
51
        foreach($value as $n => $v)
52
        {
53
            $component = $this->get_component($n);
54
            $component->value = $v;
55
        }
56
    }
57
58
    /**
59
     * Apply the new name to each of the child components.
60
     *
61
     * @param string $name
62
     * @return void
63
     */
64
    public function set_name( $name )
0 ignored issues
show
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
        foreach($this->components as $c)
67
        {
68
            $c->name_template = str_replace('{{parent_name}}', $this->get_name(), $c->composite_name_template);
69
        }
70
    }
71
    
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function default_model() 
76
    {
77
        return array(
78
            'name'          => '',
79
            'parent_name'   => '',
80
            'id'            => '',
81
            'disabled'      => false,
82
            'template'      => null,
83
            'components'    => array(),
84
            'default'       => array(),
85
            'filter'        => array($this, 'filter'),
86
            'validation'    => array($this, 'validation'),
87
            'show'          => null
88
        );
89
    }
90
    
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function required_arguments()
95
    {
96
        return array('name','components','template');
97
    }
98
    
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function get_template_path() 
103
    {
104
        return __DIR__.'/template.phtml';
105
    }
106
    
107
    /**
108
     * Parse the template by converting the name tokens into UI components.
109
     * 
110
     * @return string The parsed template
111
     */
112
    public function parse_template()
113
    {
114
        $self = $this;
115
        return preg_replace_callback('/\{\{([a-zA-Z\d-_]+)\}\}/', function($a) use($self) {
116
            $component = $self->get_component($a[1]);
117
            return $component->render();
118
        }, $this->model['template']);
119
    }
120
    
121
    /**
122
     * If this is the root composite component, this will return the component's 
123
     * name. If this is a child composite component, this will return the
124
     * component's name as a key in the parent's array, i.e 'parent_name[child_name]'
125
     * 
126
     * @return string
127
     */
128
    public function get_name()
129
    {
130
        if('' !== $this->parent_name)
0 ignored issues
show
The property parent_name does not exist on object<Amarkal\UI\Component_composite>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
131
        {
132
            return "{$this->parent_name}[{$this->name}]";
0 ignored issues
show
The property parent_name does not exist on object<Amarkal\UI\Component_composite>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property name does not exist on object<Amarkal\UI\Component_composite>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
133
        }
134
        return $this->name;
0 ignored issues
show
The property name does not exist on object<Amarkal\UI\Component_composite>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
135
    }
136
137
    public function filter($v)
138
    {
139 View Code Duplication
        foreach($this->components as $component)
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...
140
        {
141
            if($component instanceof FilterableComponentInterface &&
142
               \is_callable($component->filter))
143
            {
144
                $n = $component->name;
145
                $v[$n] = $component->filter($v[$n]);
146
            }
147
        }
148
        
149
        return $v;
150
    }
151
152
    public function validation($v,&$e)
153
    {
154 View Code Duplication
        foreach($this->components as $component)
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...
155
        {
156
            if($component instanceof ValidatableComponentInterface &&
157
               \is_callable($component->validation))
158
            {
159
                $n = $component->name;
160
                if(!$component->validation($v[$n],$e))
161
                {
162
                    return false;
163
                }
164
            }
165
        }
166
        return true;
167
    }
168
169
    /**
170
     * Get a child component by name.
171
     * 
172
     * @param string $name
173
     * @return UI\AbstractComponent
174
     * @throws \RuntimeException If there's no child component corresponding to the given name
175
     */
176
    public function get_component( $name )
177
    {
178
        if(!array_key_exists($name, $this->components))
179
        {
180
            throw new \RuntimeException("Composite sub-component not found with name $name");
181
        }
182
        return $this->components[$name];
183
    }
184
    
185
    /**
186
     * Instantiate child UI components when created.
187
     */
188
    protected function on_created()
189
    {
190
        foreach( $this->model['components'] as $args )
191
        {
192
            $this->components[$args['name']] = $this->create_component($args);
193
        }
194
    }
195
    
196
    /**
197
     * 
198
     * @param type $args
199
     * @return type
200
     */
201
    private function create_component( $args )
202
    {
203
        $type = $args['type'];
204
        
205
        if('composite' === $type)
206
        {
207
            $args['parent_name'] = $this->get_name();
208
        }
209
        
210
        $c = \Amarkal\UI\ComponentFactory::create( $type, $args );
211
        
212
        // Apply the composite name template
213
        $c->name_template = str_replace('{{parent_name}}', $this->get_name(), $c->composite_name_template);
214
        
215
        return $c;
216
    }
217
}