Issues (28)

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/Objects/PopoloObject.php (3 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 EveryPolitician\EveryPoliticianPopolo\Objects;
4
5
use \DateTime;
6
use \EveryPolitician\EveryPoliticianPopolo\Traits\ArrayGetterTrait;
7
8
class PopoloObject
9
{
10
    use ArrayGetterTrait;
11
12
    protected $properties = [];
13
    protected $baseProperties = [
14
        'keyForHash',
15
    ];
16
    protected $data;
17
    protected $allPopolo;
18
19
    /**
20
     * Creates a new instance
21
     */
22 255
    public function __construct($data, $allPopolo)
23
    {
24 255
        $this->data = $data;
25 255
        $this->allPopolo = $allPopolo;
26 255
    }
27
28
    /**
29
     * Getter for public attributes
30
     *
31
     * @param string $prop the attribute to get
32
     *
33
     * @return mixed
34
     */
35 255 View Code Duplication
    public function __get($prop)
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...
36 1
    {
37 255
        $properties = array_merge($this->baseProperties, $this->properties);
38 255
        if (in_array($prop, $properties)) {
39 255
            $getter = 'get'.ucfirst($prop);
40 255
            return $this->$getter();
41 1
        }
42 3
        trigger_error('Undefined property: '.__CLASS__.'::$'.$prop, E_USER_ERROR);
43
    }
44
45 222
    protected function getKeyForHash()
46
    {
47 222
        return $this->getId();
48
    }
49
50
    protected function getId()
51
    {
52
        return null;
53
    }
54
55 27
    private function getRelatedObjects($popoloArray)
56
    {
57 27
        return $this->arrGet($this->data, $popoloArray, []);
58
    }
59
60 33
    protected function getDate($attr, $default = null)
61
    {
62 33
        $d = $this->arrGet($this->data, $attr);
63 33
        if ($d) {
64 30
            return new DateTime($d);
65 1
        }
66 3
        return $default;
67
    }
68
69 28
    private function getRelatedValues($popoloArray, $infoTypeKey, $infoType, $infoValueKey)
70 1
    {
71
        /* Get a value from one of the Popolo related objects
72
         *
73
         * For example, if you have a person with related links, like
74
         * this:
75
         *
76
         *     {
77
         *         "name": "Dale Cooper",
78
         *         "links": [
79
         *             {
80
         *                 "note": "wikipedia",
81
         *                 "url": "https://en.wikipedia.org/wiki/Dale_Cooper"
82
         *             }
83
         *         ]
84
         *     }
85
         *
86
         * When calling this method to get the Wikipedia URL, you would use:
87
         *
88
         *     popoloArray  = 'links'
89
         *     infoTypeKey  = 'note'
90
         *     infoType     = 'wikipedia'
91
         *     infoValueKey = 'url'
92
         *
93
         * ... so the following would work:
94
         *
95
         *     $this->getRelatedValue('links', 'note', 'wikipedia', 'url')
96
         *     # => 'https://en.wikipedia.org/wiki/Dale_Cooper'
97
         */
98 27
        $relatedValues = [];
99 27
        $relatedObjects = $this->getRelatedObjects($popoloArray);
100 28
        foreach ($relatedObjects as $o) {
101 21
            if ($o[$infoTypeKey] === $infoType) {
102 21
                $relatedValues[] = $o[$infoValueKey];
103 7
            }
104 9
        }
105 27
        return $relatedValues;
106
    }
107
108 12
    public function identifierValues($scheme)
109
    {
110 12
        return $this->getRelatedValues('identifiers', 'scheme', $scheme, 'identifier');
111
    }
112
113 12
    public function identifierValue($scheme)
114
    {
115 12
        $identifierValues = $this->identifierValues($scheme);
116 12
        return (count($identifierValues) > 0) ? $identifierValues[0] : null;
117
    }
118
119 12
    public function linkValues($note)
120
    {
121 12
        return $this->getRelatedValues('links', 'note', $note, 'url');
122
    }
123
124 9
    public function linkValue($note)
125
    {
126 9
        $linkValues = $this->linkValues($note);
127 9
        return (count($linkValues) > 0) ? $linkValues[0] : null;
128
    }
129
130 12
    public function contactDetailValues($contactType)
131
    {
132 12
        return $this->getRelatedValues('contact_details', 'type', $contactType, 'value');
133
    }
134
135 12
    public function contactDetailValue($contactType)
136
    {
137 12
        $contactDetailValues = $this->contactDetailValues($contactType);
138 12
        return (count($contactDetailValues) > 0) ? $contactDetailValues[0] : null;
139
    }
140
141 42 View Code Duplication
    public function equals($other)
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...
142
    {
143 42
        if (is_object($other) && get_class($other) == get_class($this)) {
144 39
            return $this->id == $other->id;
0 ignored issues
show
The property id does not exist on object<EveryPolitician\E...o\Objects\PopoloObject>. 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...
145
        }
146
        // TODO: Throw a custom exception here
147 3
        throw new \BadMethodCallException;
148
    }
149
150 51
    public function getRelatedObjectArr($popoloArray)
151
    {
152 51
        return $this->arrGet($this->data, $popoloArray, []);
153
    }
154
}
155