Issues (3099)

Security Analysis    not enabled

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/Kunstmaan/TaggingBundle/Entity/TagManager.php (1 issue)

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 Kunstmaan\TaggingBundle\Entity;
4
5
use Doctrine\ORM\Query\Expr;
6
use Doctrine\ORM\Query\ResultSetMappingBuilder;
7
use DoctrineExtensions\Taggable\Taggable as BaseTaggable;
8
use DoctrineExtensions\Taggable\TagManager as BaseTagManager;
9
use Kunstmaan\NodeBundle\Entity\AbstractPage;
10
11
class TagManager extends BaseTagManager
12
{
13
    const TAGGING_HYDRATOR = 'taggingHydrator';
14
15
    /**
16
     * @param BaseTaggable $resource
17
     */
18 2
    public function loadTagging(BaseTaggable $resource)
19
    {
20 2
        if ($resource instanceof LazyLoadingTaggableInterface) {
21
            $resource->setTagLoader(function (Taggable $taggable) {
22 1
                parent::loadTagging($taggable);
23 1
            });
24
25 1
            return;
26
        }
27
28 1
        parent::loadTagging($resource);
29 1
    }
30
31
    /**
32
     * @param BaseTaggable $resource
33
     */
34
    public function saveTagging(BaseTaggable $resource)
35
    {
36
        $tags = clone $resource->getTags();
37
        parent::saveTagging($resource);
38
        if (\count($tags) !== \count($resource->getTags())) {
39
            // parent::saveTagging uses getTags by reference and removes elements, so it ends up empty :-/
40
            // this causes all tags to be deleted when an entity is persisted more than once in a request
41
            // Restore:
42
            $this->replaceTags($tags->toArray(), $resource);
43
        }
44
    }
45
46
    /**
47
     * Gets all tags for the given taggable resource
48
     *
49
     * @param BaseTaggable $resource Taggable resource
50
     *
51
     * @return array
52
     */
53 2
    public function getTagging(BaseTaggable $resource)
54
    {
55 2
        $em = $this->em;
56
57 2
        $config = $em->getConfiguration();
58 2
        if (\is_null($config->getCustomHydrationMode(self::TAGGING_HYDRATOR))) {
59 2
            $config->addCustomHydrationMode(self::TAGGING_HYDRATOR, 'Doctrine\ORM\Internal\Hydration\ObjectHydrator');
60
        }
61
62
        return $em
63 2
            ->createQueryBuilder()
64
65 2
            ->select('t')
66 2
            ->from($this->tagClass, 't')
67
68 2
            ->innerJoin('t.tagging', 't2', Expr\Join::WITH, 't2.resourceId = :id AND t2.resourceType = :type')
69 2
            ->setParameter('id', $resource->getTaggableId())
70 2
            ->setParameter('type', $resource->getTaggableType())
71
72 2
            ->getQuery()
73 2
            ->getResult(self::TAGGING_HYDRATOR);
74
    }
75
76
    /**
77
     * @param $id
78
     *
79
     * @return mixed|null
80
     *
81
     * @throws \Doctrine\ORM\NonUniqueResultException
82
     */
83 2
    public function findById($id)
84
    {
85 2
        if (!isset($id) || \is_null($id)) {
86 1
            return null;
87
        }
88 1
        $builder = $this->em->createQueryBuilder();
89
90
        $tag = $builder
91 1
            ->select('t')
92 1
            ->from($this->tagClass, 't')
93
94 1
            ->where($builder->expr()->eq('t.id', $id))
95
96 1
            ->getQuery()
97 1
            ->getOneOrNullResult();
98
99 1
        return $tag;
100
    }
101
102
    /**
103
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use object[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
104
     */
105 1
    public function findAll()
106
    {
107 1
        $tagsRepo = $this->em->getRepository('KunstmaanTaggingBundle:Tag');
108
109 1
        return $tagsRepo->findAll();
110
    }
111
112
    /**
113
     * @param Taggable $item
114
     * @param $class
115
     * @param $locale
116
     * @param int $nbOfItems
117
     *
118
     * @return array|null
119
     */
120 3
    public function findRelatedItems(Taggable $item, $class, $locale, $nbOfItems = 1)
121
    {
122 3
        $instance = new $class();
123 3
        if (!($instance instanceof Taggable)) {
124 1
            return null;
125
        }
126
127 2
        $em = $this->em;
128 2
        $rsm = new ResultSetMappingBuilder($em);
129 2
        $rsm->addRootEntityFromClassMetadata($class, 'i');
130
131 2
        $meta = $em->getClassMetadata($class);
132 2
        $tableName = $meta->getTableName();
133
134 2
        $escapedClass = str_replace('\\', '\\\\', $class);
135
136
        $query = <<<EOD
137 2
            SELECT i.*, COUNT(i.id) as number
138 2
            FROM {$tableName} i
139
            LEFT JOIN kuma_taggings t
140
            ON t.resource_id = i.id
141 2
            AND t.resource_type = '{$instance->getTaggableType()}'
142
            WHERE t.tag_id IN (
143
                SELECT tg.tag_id
144
                FROM kuma_taggings tg
145 2
                WHERE tg.resource_id = {$item->getId()}
146 2
                AND tg.resource_type = '{$item->getTaggableType()}'
147
            )
148 2
            AND i.id <> {$item->getId()}
149
EOD;
150
151 2
        if ($item instanceof AbstractPage) {
152
            $query .= <<< EOD
153 1
                AND i.id IN (
154
                    SELECT nodeversion.refId
155
                    FROM kuma_nodes as node
156
                    INNER JOIN kuma_node_translations as nodetranslation
157
                    ON node.id = nodetranslation.node
158 1
                    AND nodetranslation.lang = '{$locale}'
159
                    INNER JOIN kuma_node_versions as nodeversion
160
                    ON nodetranslation.publicNodeVersion = nodeversion.id
161 1
                    AND nodeversion.refEntityname = '{$escapedClass}'
162
                    AND node.deleted = 0
163
                    AND nodetranslation.online = 1
164
                )
165
EOD;
166
        }
167
168
        $query .= <<<EOD
169 2
            GROUP BY
170
                i.id
171
            HAVING
172
                number > 0
173
            ORDER BY
174
                number DESC
175 2
            LIMIT {$nbOfItems};
176
EOD;
177
178 2
        return $em->createNativeQuery($query, $rsm)->getResult();
179
    }
180
}
181