Issues (387)

Branch: develop

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.

phpDocumentor/Compiler/Pass/PackageTreeBuilder.php (5 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
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Compiler\Pass;
17
18
use phpDocumentor\Compiler\CompilerPassInterface;
19
use phpDocumentor\Descriptor\Collection;
20
use phpDocumentor\Descriptor\DescriptorAbstract;
21
use phpDocumentor\Descriptor\PackageDescriptor;
22
use phpDocumentor\Descriptor\ProjectDescriptor;
23
use phpDocumentor\Descriptor\TagDescriptor;
24
25
/**
26
 * Rebuilds the package tree from the elements found in files.
27
 *
28
 * On every compiler pass is the package tree rebuild to aid in the process
29
 * of incremental updates.
30
 *
31
 * If the package tree were to be persisted then both locations needed to be
32
 * invalidated if a file were to change.
33
 */
34
class PackageTreeBuilder implements CompilerPassInterface
35
{
36
    const COMPILER_PRIORITY = 9001;
37
38
    public function getDescription(): string
39
    {
40
        return 'Build "packages" index';
41
    }
42
43
    public function execute(ProjectDescriptor $project): void
44
    {
45
        $rootPackageDescriptor = new PackageDescriptor();
46
        $rootPackageDescriptor->setName('\\');
47
        $project->getIndexes()->set('packages', new Collection());
48
        $project->getIndexes()->packages['\\'] = $rootPackageDescriptor;
0 ignored issues
show
The property packages does not exist on object<phpDocumentor\Descriptor\Collection>. 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...
49
50
        foreach ($project->getFiles() as $file) {
51
            $this->addElementsOfTypeToPackage($project, [$file], 'files');
52
            $this->addElementsOfTypeToPackage($project, $file->getConstants()->getAll(), 'constants');
53
            $this->addElementsOfTypeToPackage($project, $file->getFunctions()->getAll(), 'functions');
54
            $this->addElementsOfTypeToPackage($project, $file->getClasses()->getAll(), 'classes');
55
            $this->addElementsOfTypeToPackage($project, $file->getInterfaces()->getAll(), 'interfaces');
56
            $this->addElementsOfTypeToPackage($project, $file->getTraits()->getAll(), 'traits');
57
        }
58
    }
59
60
    /**
61
     * Adds the given elements of a specific type to their respective Package Descriptors.
62
     *
63
     * This method will assign the given elements to the package as registered in the package field of that
64
     * element. If a package does not exist yet it will automatically be created.
65
     *
66
     * @param DescriptorAbstract[] $elements Series of elements to add to their respective package.
67
     * @param string $type Declares which field of the package will be populated with the given
68
     * series of elements. This name will be transformed to a getter which must exist. Out of performance
69
     * considerations will no effort be done to verify whether the provided type is valid.
70
     */
71
    protected function addElementsOfTypeToPackage(ProjectDescriptor $project, array $elements, string $type): void
72
    {
73
        /** @var DescriptorAbstract $element */
74
        foreach ($elements as $element) {
75
            $packageName = '';
76
            $packageTags = $element->getTags()->get('package');
77
            if ($packageTags instanceof Collection) {
78
                $packageTag = $packageTags->getIterator()->current();
79
                if ($packageTag instanceof TagDescriptor) {
80
                    $packageName = $packageTag->getDescription();
81
                }
82
            }
83
84
            $subpackageCollection = $element->getTags()->get('subpackage');
85
            if ($subpackageCollection instanceof Collection && $subpackageCollection->count() > 0) {
86
                $subpackageTag = $subpackageCollection->getIterator()->current();
87
                if ($subpackageTag instanceof TagDescriptor) {
88
                    $packageName .= '\\' . $subpackageTag->getDescription();
89
                }
90
            }
91
92
            // ensure consistency by trimming the slash prefix and then re-appending it.
93
            $packageIndexName = '\\' . ltrim((string) $packageName, '\\');
94
            if (!isset($project->getIndexes()->packages[$packageIndexName])) {
0 ignored issues
show
The property packages does not exist on object<phpDocumentor\Descriptor\Collection>. 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...
95
                $this->createPackageDescriptorTree($project, (string) $packageName);
96
            }
97
98
            /** @var PackageDescriptor $package */
99
            $package = $project->getIndexes()->packages[$packageIndexName];
0 ignored issues
show
The property packages does not exist on object<phpDocumentor\Descriptor\Collection>. 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...
100
101
            // replace textual representation with an object representation
102
            $element->setPackage($package);
103
104
            // add element to package
105
            $getter = 'get' . ucfirst($type);
106
107
            /** @var Collection $collection */
108
            $collection = $package->{$getter}();
109
            $collection->add($element);
110
        }
111
    }
112
113
    /**
114
     * Creates a tree of PackageDescriptors based on the provided FQNN (package name).
115
     *
116
     * This method will examine the package name and create a package descriptor for each part of
117
     * the FQNN if it doesn't exist in the packages field of the current package (starting with the root
118
     * Package in the Project Descriptor),
119
     *
120
     * As an intended side effect this method also populates the *elements* index of the ProjectDescriptor with all
121
     * created PackageDescriptors. Each index key is prefixed with a tilde (~) so that it will not conflict with
122
     * other FQSEN's, such as classes or interfaces.
123
     *
124
     * @param string $packageName A FQNN of the package (and parents) to create.
125
     * @see ProjectDescriptor::getPackage() for the root package.
126
     * @see PackageDescriptor::getChildren() for the child packages of a given package.
127
     */
128
    protected function createPackageDescriptorTree(ProjectDescriptor $project, string $packageName): void
129
    {
130
        $parts = explode('\\', ltrim($packageName, '\\'));
131
        $fqnn = '';
132
133
        // this method does not use recursion to traverse the tree but uses a pointer that will be overridden with the
134
        // next item that is to be traversed (child package) at the end of the loop.
135
136
        /** @var PackageDescriptor $pointer */
137
        $pointer = $project->getIndexes()->packages['\\'];
0 ignored issues
show
The property packages does not exist on object<phpDocumentor\Descriptor\Collection>. 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...
138
        foreach ($parts as $part) {
139
            $fqnn .= '\\' . $part;
140
            if ($pointer->getChildren()->get($part)) {
141
                $pointer = $pointer->getChildren()->get($part);
142
                continue;
143
            }
144
145
            // package does not exist, create it
146
            $interimPackageDescriptor = new PackageDescriptor();
147
            $interimPackageDescriptor->setParent($pointer);
148
            $interimPackageDescriptor->setName($part);
149
            $interimPackageDescriptor->setFullyQualifiedStructuralElementName($fqnn);
150
151
            // add to the pointer's list of children
152
            $pointer->getChildren()->set($part ?: 'UNKNOWN', $interimPackageDescriptor);
153
154
            // add to index
155
            $project->getIndexes()->packages[$fqnn] = $interimPackageDescriptor;
0 ignored issues
show
The property packages does not exist on object<phpDocumentor\Descriptor\Collection>. 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...
156
157
            // move pointer forward
158
            $pointer = $interimPackageDescriptor;
159
        }
160
    }
161
}
162