Issues (51)

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.

code/model/NutriHolder.php (28 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
class NutriHolder extends DataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    private static $singular_name = 'Nutritional Information Profile';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
6
    public function i18n_singular_name()
7
    {
8
        return self::$singular_name;
9
    }
10
11
    private static $plural_name = 'Nutritional Information Profiles';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
12
    public function i18n_plural_name()
13
    {
14
        return self::$plural_name;
15
    }
16
17
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
        'ProfileName' => 'Varchar(50)',
19
        'ServingCount' => 'Int',
20
        'Container' => 'Varchar(10)',
21
        'ServingSize' => 'Varchar(15)',
22
        'AdditionalInfo' => 'Varchar(100)',
23
        'HidePerServeColumn' => 'Boolean',
24
        'HidePer100gColumn' => 'Boolean',
25
        'HidePerDVColumn' => 'Boolean'
26
    );
27
28
29
    private static $has_many = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
        'NutriRows' => 'NutriRow',
31
        'Products' => 'ProductGroup',
32
        'ProductVariations' => 'ProductVariation'
33
    );
34
35
    /**
36
     * @inherited
37
     */
38
    private static $casting = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
39
        'Title' => "Varchar",
40
        'Per100Unit' => "Varchar"
41
    );
42
43
    /**
44
     * Returns the unit for the 'Per 100' column of nutritional information. It tries
45
     * to get the unit from the ServingSize field, and if no match returns 'g'
46
     * @return String
47
     */
48
    public function Per100Unit()
49
    {
50
        return $this->getPer100Unit();
51
    }
52
53
    public function getPer100Unit()
54
    {
55
        $string = trim($this->ServingSize);
0 ignored issues
show
The property ServingSize does not exist on object<NutriHolder>. 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...
56
        $matches = array();
57
        $matchResult = preg_match('/ ?([A-Z]|[a-z]){1,7}/', $string, $matches);
58
        if (!$matchResult) {
59
            return "g";
60
        }
61
        return trim($matches[0]);
62
    }
63
64
    /**
65
     * @return String
66
     */
67
    public function Title()
68
    {
69
        return $this->getTitle();
70
    }
71
    public function getTitle()
72
    {
73
        $string = $this->ProfileName;
0 ignored issues
show
The property ProfileName does not exist on object<NutriHolder>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
74
        if (!$string) {
75
            $string = 'Profile #'.$this->ID.' (please customise) ';
76
        }
77
        $string .= ': ';
78
        $string .= "serving: ".$this->ServingCount."; ";
0 ignored issues
show
The property ServingCount does not exist on object<NutriHolder>. 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...
79
        $string .= "size: ".$this->ServingSize."; ";
0 ignored issues
show
The property ServingSize does not exist on object<NutriHolder>. 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...
80
        $string .= "container: ".$this->Container."; ";
0 ignored issues
show
The property Container does not exist on object<NutriHolder>. 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...
81
        return $string;
82
    }
83
84
    private static $summary_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
85
        'Title' => 'Title',
86
    );
87
88
    private static $searchable_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $searchable_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
89
        'ProfileName' => 'PartialMatchFilter',
90
        'ServingCount' => 'ExactMatchFilter',
91
        'Container' => 'PartialMatchFilter',
92
        'ServingSize' => 'ExactMatchFilter',
93
        'AdditionalInfo' => 'PartialMatchFilter',
94
        'AdditionalInfo' => 'PartialMatchFilter'
95
    );
96
97
    public function getCMSFields()
98
    {
99
        $fields = parent::getCMSFields();
100
101
        $config = GridFieldConfig_RelationEditor::create();
102
        $config->addComponent(new GridFieldSortableRows('SortOrder'));
103
104
        $fields->addFieldsToTab(
105
            'Root.Main',
106
            array(
107
                NumericField::create('ServingCount', 'Servings per package')
108
                    ->setRightTitle('The number of servings in the jar/bucket/bottle/conatiner'),
109
                TextField::create('Container', 'The product container')
110
                    ->setRightTitle('The conatiner for the product e.g. Jar, Bottle, Bucket'),
111
                TextField::create('ServingSize', 'The size of each serving')
112
                    ->setRightTitle('The size of each serving e.g., 3g, 30ml'),
113
                TextField::create('AdditionalInfo', 'Additional information')
114
                    ->setRightTitle('For example "Remove label with care."'),
115
            )
116
        );
117
118
        $productsGrid = $fields->dataFieldByName('Products');
119
        if ($productsGrid) {
120
            $productsFieldConfig = GridFieldConfig_RecordViewer::create();
121
            $productsGrid -> setConfig($productsFieldConfig);
0 ignored issues
show
The method setConfig() does not exist on FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
122
        }
123
124
        $productVariationsGrid = $fields->dataFieldByName('ProductVariations');
125
        if ($productVariationsGrid) {
126
            $productVariationsConfig = GridFieldConfig_RecordViewer::create();
127
            $productVariationsGrid -> setConfig($productVariationsConfig);
0 ignored issues
show
The method setConfig() does not exist on FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
128
        }
129
130
        $nutriRowsGridField = $fields->dataFieldByName('NutriRows');
131
132
        if ($nutriRowsGridField) {
133
            $nutriRowsFieldConfig = $nutriRowsGridField ->getConfig();
0 ignored issues
show
The method getConfig() does not exist on FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
134
            $nutriRowsFieldConfig
135
                ->addComponent(new GridFieldEditableColumns())
136
                ->addComponent(new GridFieldDeleteAction())
137
                ->addComponent(new GridFieldSortableRows('SortOrder'))
138
                ->getComponentByType('GridFieldEditableColumns')
139
140
                ->setDisplayFields(
141
                    array(
142
                        'Title' => array(
143
                            'title' => 'Item',
144
                            'field' => 'ReadonlyField'
145
                        ),
146
                        'PerServe'  => array(
147
                            "title" => "Per Serve",
148
                            "callback" => function ($record, $column, $grid) {
0 ignored issues
show
The parameter $grid 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...
149
                                return new TextField($column, "Serve");
150
                            }),
151
152
                        'Per100' => function ($record, $column, $grid) {
0 ignored issues
show
The parameter $grid 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...
153
                            return new TextField($column, "Per 100");
154
                        }
155
156
                    )
157
                );
158
        }
159
        $fields->removeFieldFromTab('Root.Main', 'SortOrder');
160
161
        return $fields;
162
    }
163
164
    /**
165
     * @return DataList
166
     */
167
    public function ShownNutriRows()
168
    {
169
        return $this->NutriRows()
0 ignored issues
show
The method NutriRows() does not exist on NutriHolder. Did you maybe mean ShownNutriRows()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
170
            ->exclude(array("Hide" => 1));
171
    }
172
173
    /**
174
     * @return DataList
0 ignored issues
show
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
175
     */
176
    public function NumberOfTableColums()
177
    {
178
        $tablesCols = 4;
179
        if ($this->HidePerServeColumn) {
0 ignored issues
show
The property HidePerServeColumn does not exist on object<NutriHolder>. 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...
180
            $tablesCols--;
181
        }
182
        if ($this->HidePer100gColumn) {
0 ignored issues
show
The property HidePer100gColumn does not exist on object<NutriHolder>. 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...
183
            $tablesCols--;
184
        }
185
        if ($this->HidePerDVColumn) {
0 ignored issues
show
The property HidePerDVColumn does not exist on object<NutriHolder>. 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...
186
            $tablesCols--;
187
        }
188
        return $tablesCols;
189
    }
190
}
191