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.

NodeBundle/Helper/Services/PageCreatorService.php (6 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\NodeBundle\Helper\Services;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\ORMException;
7
use Kunstmaan\AdminBundle\Repository\UserRepository;
8
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
9
use Kunstmaan\NodeBundle\Entity\Node;
10
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
11
use Kunstmaan\NodeBundle\Repository\NodeRepository;
12
use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface;
13
use Kunstmaan\SeoBundle\Entity\Seo;
14
use Kunstmaan\SeoBundle\Repository\SeoRepository;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
17
/**
18
 * Service to create new pages.
19
 */
20
class PageCreatorService
21
{
22
    /** @var EntityManagerInterface */
23
    protected $entityManager;
24
25
    /** @var ACLPermissionCreatorService */
26
    protected $aclPermissionCreatorService;
27
28
    /** @var string */
29
    protected $userEntityClass;
30
31
    public function __construct(EntityManagerInterface $em = null, ACLPermissionCreatorService $aclPermissionCreatorService = null, string $userEntityClass = null)
32
    {
33
        if (null === $em) {
34
            @trigger_error(sprintf('Not injecting the required dependencies in the constructor of "%s" is deprecated since KunstmaanNodeBundle 5.7 and will be required in KunstmaanNodeBundle 6.0.', __CLASS__), E_USER_DEPRECATED);
35
        }
36
37
        $this->entityManager = $em;
38
        $this->aclPermissionCreatorService = $aclPermissionCreatorService;
39
        $this->userEntityClass = $userEntityClass;
40
    }
41
42
    /**
43
     * @deprecated since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.
44
     */
45
    public function setEntityManager($entityManager)
46
    {
47
        @trigger_error(sprintf('Using the "%s" method is deprecated since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.', __METHOD__), E_USER_DEPRECATED);
48
49
        $this->entityManager = $entityManager;
50
    }
51
52
    /**
53
     * @deprecated since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.
54
     */
55
    public function setACLPermissionCreatorService($aclPermissionCreatorService)
56
    {
57
        @trigger_error(sprintf('Using the "%s" method is deprecated since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.', __METHOD__), E_USER_DEPRECATED);
58
59
        $this->aclPermissionCreatorService = $aclPermissionCreatorService;
60
    }
61
62
    /**
63
     * @deprecated since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.
64
     */
65
    public function setUserEntityClass($userEntityClass)
66
    {
67
        @trigger_error(sprintf('Using the "%s" method is deprecated since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.', __METHOD__), E_USER_DEPRECATED);
68
69
        $this->userEntityClass = $userEntityClass;
70
    }
71
72
    /**
73
     * Sets the Container. This is still here for backwards compatibility.
74
     *
75
     * The ContainerAwareInterface has been removed so the container won't be injected automatically.
76
     * This function is just there for code that calls it manually.
77
     *
78
     * @param ContainerInterface $container a ContainerInterface instance
0 ignored issues
show
Should the type for parameter $container not be null|ContainerInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
79
     *
80
     * @deprecated since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.
81
     *
82
     * @api
83
     */
84
    public function setContainer(ContainerInterface $container = null)
85
    {
86
        @trigger_error(sprintf('Using the "%s" method is deprecated since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.', __METHOD__), E_USER_DEPRECATED);
87
88
        $this->setEntityManager($container->get('doctrine.orm.entity_manager'));
0 ignored issues
show
It seems like $container is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
Deprecated Code introduced by
The method Kunstmaan\NodeBundle\Hel...ice::setEntityManager() has been deprecated with message: since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
89
        $this->setACLPermissionCreatorService($container->get('kunstmaan_node.acl_permission_creator_service'));
0 ignored issues
show
Deprecated Code introduced by
The method Kunstmaan\NodeBundle\Hel...missionCreatorService() has been deprecated with message: since KunstmaanNodeBundle 5.7 and will be removed in KunstmaanNodeBundle 6.0. Inject the required dependencies in the constructor instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
90
        $this->setUserEntityClass($container->getParameter('fos_user.model.user.class'));
91
    }
92
93
    /**
94
     * @param HasNodeInterface $pageTypeInstance the page
95
     * @param array            $translations     Containing arrays. Sample:
96
     *                                           [
97
     *                                           [   "language" => "nl",
98
     *                                           "callback" => function($page, $translation) {
99
     *                                           $translation->setTitle('NL titel');
100
     *                                           }
101
     *                                           ],
102
     *                                           [   "language" => "fr",
103
     *                                           "callback" => function($page, $translation) {
104
     *                                           $translation->setTitle('FR titel');
105
     *                                           }
106
     *                                           ]
107
     *                                           ]
108
     *                                           Perhaps it's cleaner when you create one array and append another array for each language.
109
     * @param array            $options          Possible options:
110
     *                                           parent: type node, nodetransation or page.
111
     *                                           page_internal_name: string. name the page will have in the database.
112
     *                                           set_online: bool. if true the page will be set as online after creation.
113
     *                                           hidden_from_nav: bool. if true the page will not be show in the navigation
114
     *                                           creator: username
115
     *
116
     * Automatically calls the ACL + sets the slugs to empty when the page is an Abstract node.
117
     *
118
     * @return Node the new node for the page
119
     *
120
     * @throws \InvalidArgumentException
121
     */
122
    public function createPage(HasNodeInterface $pageTypeInstance, array $translations, array $options = array())
123
    {
124
        if (\is_null($options)) {
125
            $options = array();
126
        }
127
128
        if (\is_null($translations) || (\count($translations) == 0)) {
129
            throw new \InvalidArgumentException('There has to be at least 1 translation in the translations array');
130
        }
131
132
        $em = $this->entityManager;
133
134
        /** @var NodeRepository $nodeRepo */
135
        $nodeRepo = $em->getRepository(Node::class);
136
        /** @var UserRepository $userRepo */
137
        $userRepo = $em->getRepository($this->userEntityClass);
138
        /* @var SeoRepository $seoRepo */
139
        try {
140
            $seoRepo = $em->getRepository(Seo::class);
141
        } catch (ORMException $e) {
142
            $seoRepo = null;
143
        }
144
145
        $pagecreator = \array_key_exists('creator', $options) ? $options['creator'] : 'pagecreator';
146
147
        if ($pagecreator instanceof $this->userEntityClass) {
148
            $creator = $pagecreator;
149
        } else {
150
            $creator = $userRepo->findOneBy(array('username' => $pagecreator));
151
        }
152
153
        $parent = isset($options['parent']) ? $options['parent'] : null;
154
155
        $pageInternalName = isset($options['page_internal_name']) ? $options['page_internal_name'] : null;
156
157
        $setOnline = isset($options['set_online']) ? $options['set_online'] : false;
158
159
        // We need to get the language of the first translation so we can create the rootnode.
160
        // This will also create a translationnode for that language attached to the rootnode.
161
        $first = true;
162
        $rootNode = null;
163
164
        /* @var \Kunstmaan\NodeBundle\Repository\NodeTranslationRepository $nodeTranslationRepo*/
165
        $nodeTranslationRepo = $em->getRepository(NodeTranslation::class);
166
167
        foreach ($translations as $translation) {
168
            $language = $translation['language'];
169
            $callback = $translation['callback'];
170
171
            $translationNode = null;
172
            if ($first) {
173
                $first = false;
174
175
                $em->persist($pageTypeInstance);
176
                $em->flush($pageTypeInstance);
177
178
                // Fetch the translation instead of creating it.
179
                // This returns the rootnode.
180
                $rootNode = $nodeRepo->createNodeFor($pageTypeInstance, $language, $creator, $pageInternalName);
181
182
                if (\array_key_exists('hidden_from_nav', $options)) {
183
                    $rootNode->setHiddenFromNav($options['hidden_from_nav']);
184
                }
185
186
                if (!\is_null($parent)) {
187
                    if ($parent instanceof HasPagePartsInterface) {
188
                        $parent = $nodeRepo->getNodeFor($parent);
0 ignored issues
show
$parent is of type object<Kunstmaan\PagePar...\HasPagePartsInterface>, but the function expects a object<Kunstmaan\NodeBun...ntity\HasNodeInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
189
                    }
190
                    $rootNode->setParent($parent);
191
                }
192
193
                $em->persist($rootNode);
194
                $em->flush($rootNode);
195
196
                $translationNode = $rootNode->getNodeTranslation($language, true);
197
            } else {
198
                // Clone the $pageTypeInstance.
199
                $pageTypeInstance = clone $pageTypeInstance;
200
201
                $em->persist($pageTypeInstance);
202
                $em->flush($pageTypeInstance);
203
204
                // Create the translationnode.
205
                $translationNode = $nodeTranslationRepo->createNodeTranslationFor($pageTypeInstance, $language, $rootNode, $creator);
206
            }
207
208
            // Make SEO.
209
            $seo = null;
210
211
            if (!\is_null($seoRepo)) {
212
                $seo = $seoRepo->findOrCreateFor($pageTypeInstance);
213
            }
214
215
            $callback($pageTypeInstance, $translationNode, $seo);
216
217
            // Overwrite the page title with the translated title
218
            $pageTypeInstance->setTitle($translationNode->getTitle());
219
            $em->persist($pageTypeInstance);
220
            $em->persist($translationNode);
221
            $em->flush($pageTypeInstance);
222
            $em->flush($translationNode);
223
224
            $translationNode->setOnline($setOnline);
225
226
            if (!\is_null($seo)) {
227
                $em->persist($seo);
228
                $em->flush($seo);
229
            }
230
231
            $em->persist($translationNode);
232
            $em->flush($translationNode);
233
        }
234
235
        // ACL
236
        $this->aclPermissionCreatorService->createPermission($rootNode);
0 ignored issues
show
It seems like $rootNode defined by null on line 162 can be null; however, Kunstmaan\NodeBundle\Hel...ice::createPermission() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
237
238
        return $rootNode;
239
    }
240
}
241