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.

ArticleBundle/Twig/ArticleTwigExtension.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
3
namespace Kunstmaan\ArticleBundle\Twig;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
8
use Symfony\Component\Routing\RouterInterface;
9
use Twig\Extension\AbstractExtension;
10
use Twig\TwigFunction;
11
12
/**
13
 * Extension for article bundle.
14
 *
15
 * @final since 5.4
16
 */
17
class ArticleTwigExtension extends AbstractExtension
18
{
19
    /**
20
     * @var EntityManagerInterface
21
     */
22
    private $em;
23
24
    /**
25
     * @var RouterInterface
26
     */
27
    private $router;
28
29
    /**
30
     * ArticleTwigExtension constructor.
31
     *
32
     * @param EntityManagerInterface $em
33
     * @param RouterInterface        $router
34
     */
35
    public function __construct(EntityManagerInterface $em, RouterInterface $router)
36
    {
37
        $this->em = $em;
38
        $this->router = $router;
39
40
        if (\func_num_args() > 2) {
41
            @trigger_error(sprintf('Passing the "request_stack" service as the third argument in "%s" is deprecated in KunstmaanArticleBundle 5.1 and will be removed in KunstmaanArticleBundle 6.0. Remove the "request_stack" argument from your service definition.', __METHOD__), E_USER_DEPRECATED);
42
        }
43
    }
44
45
    /**
46
     * Returns a list of functions to add to the existing list.
47
     *
48
     * @return array An array of functions
0 ignored issues
show
Consider making the return type a bit more specific; maybe use TwigFunction[].

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...
49
     */
50
    public function getFunctions()
51
    {
52
        return array(
53
            new TwigFunction(
54
                'get_article_tag_path', array($this, 'getArticleTagRouterPath')
55
            ),
56
            new TwigFunction(
57
                'get_article_category_path', array($this, 'getArticleCategoryRouterPath')
58
            ),
59
            new TwigFunction(
60
                'get_article_categories', array($this, 'getCategories')
61
            ),
62
            new TwigFunction(
63
                'get_article_tags', array($this, 'getTags')
64
            ),
65
        );
66
    }
67
68
    /**
69
     * Get tags array for view.
70
     *
71
     * @param Request $request
72
     * @param string  $className
73
     *
74
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,boolean|array>.

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...
75
     */
76 View Code Duplication
    public function getTags(Request $request, $className)
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...
77
    {
78
        $context = array();
79
80
        $tagRepository = $this->em->getRepository($className);
81
        $context['tags'] = $tagRepository->findBy(array(), array('name' => 'ASC'));
82
83
        $searchTag = $request->get('tag') ? explode(',', $request->get('tag')) : null;
84
        if ($searchTag) {
85
            $context['activeTag'] = true;
86
            $context['activeTags'] = $searchTag;
87
        }
88
89
        return $context;
90
    }
91
92
    /**
93
     * Get categories array for view.
94
     *
95
     * @param Request $request
96
     * @param string  $className
97
     *
98
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,boolean|array>.

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...
99
     */
100 View Code Duplication
    public function getCategories(Request $request, $className)
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...
101
    {
102
        $context = array();
103
104
        $categoryRepository = $this->em->getRepository($className);
105
        $context['categories'] = $categoryRepository->findBy(array(), array('name' => 'ASC'));
106
107
        $searchCategory = $request->get('category') ? explode(',', $request->get('category')) : null;
108
        if ($searchCategory) {
109
            $context['activeCategory'] = true;
110
            $context['activeCategories'] = $searchCategory;
111
        }
112
113
        return $context;
114
    }
115
116
    /**
117
     * @param string $slug
118
     * @param string $tag
119
     * @param string $locale
120
     * @param array  $parameters
121
     * @param int    $referenceType
122
     *
123
     * @return string
124
     */
125
    public function getArticleTagRouterPath($slug, $tag, $locale, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
126
    {
127
        $routeName = sprintf('_slug_tag_%s', $locale);
128
129
        return $this->getArticleRouterPath($routeName, 'tag', $slug, $tag, $locale, $parameters, $referenceType);
130
    }
131
132
    /**
133
     * @param string $slug
134
     * @param string $category
135
     * @param string $locale
136
     * @param array  $parameters
137
     * @param int    $referenceType
138
     *
139
     * @return string
140
     */
141
    public function getArticleCategoryRouterPath($slug, $category, $locale, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
142
    {
143
        $routeName = sprintf('_slug_category_%s', $locale);
144
145
        return $this->getArticleRouterPath($routeName, 'category', $slug, $category, $locale, $parameters, $referenceType);
146
    }
147
148
    /**
149
     * @return string
150
     */
151
    public function getName()
152
    {
153
        return 'article_twig_extension';
154
    }
155
156
    /**
157
     * @param string $routeName
158
     * @param string $type
159
     * @param string $slug
160
     * @param string $tagOrCategory
161
     * @param string $locale
162
     * @param array  $parameters
163
     * @param int    $referenceType
164
     *
165
     * @return string
166
     */
167
    protected function getArticleRouterPath($routeName, $type, $slug, $tagOrCategory, $locale, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
168
    {
169
        if (!$this->articleRouteExists($type, $locale)) {
170
            $routeName = '_slug';
171
        }
172
        if (!isset($parameters[$type])) {
173
            $parameters[$type] = $tagOrCategory;
174
        }
175
        if (!isset($parameters['url'])) {
176
            $parameters['url'] = $slug;
177
        }
178
        if (!isset($parameters['_locale'])) {
179
            $parameters['_locale'] = $locale;
180
        }
181
182
        return $this->router->generate($routeName, $parameters, $referenceType);
183
    }
184
185
    /**
186
     * @param string $type
187
     * @param string $locale
188
     *
189
     * @return bool
190
     */
191
    protected function articleRouteExists($type, $locale)
192
    {
193
        $routeName = sprintf('_slug_%s_%s', $type, $locale);
194
195
        try {
196
            return !\is_null($this->router->getRouteCollection()->get($routeName));
197
        } catch (\Exception $e) {
198
            return false;
199
        }
200
    }
201
}
202