Issues (1704)

Branch: master

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.

AnalyticsBundle/Helper/AnalyticsViewHelper.php (8 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 Victoire\Bundle\AnalyticsBundle\Helper;
4
5
use Doctrine\ORM\EntityManager;
6
use Victoire\Bundle\BlogBundle\Entity\Article;
7
use Victoire\Bundle\PageBundle\Helper\PageHelper;
8
use Victoire\Bundle\ViewReferenceBundle\Connector\ViewReferenceRepository;
9
10
/**
11
 * Analytics View helper
12
 * ref: victoire_analytics.view_helper.
13
 */
14
class AnalyticsViewHelper
15
{
16
    protected $viewReferenceRepository;
17
    protected $entityManager;
18
    protected $pageHelper;
19
20
    /**
21
     * AnalyticsViewHelper constructor.
22
     *
23
     * @param ViewReferenceRepository $viewReferenceRepository
24
     * @param EntityManager           $entityManager
25
     * @param PageHelper              $pageHelper
26
     */
27
    public function __construct(ViewReferenceRepository $viewReferenceRepository, EntityManager $entityManager, PageHelper $pageHelper)
0 ignored issues
show
You have injected the EntityManager via parameter $entityManager. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
28
    {
29
        $this->entityManager = $entityManager;
30
        $this->viewReferenceRepository = $viewReferenceRepository;
31
        $this->pageHelper = $pageHelper;
32
    }
33
34
    /**
0 ignored issues
show
Doc comment for parameter "$viewNamespace" missing
Loading history...
Doc comment for parameter "$number" missing
Loading history...
35
     * Get the most read views by type.
36
     *
37
     * @return View[]
38
     **/
39
    public function getMostReadByViewType($viewNamespace, $number)
40
    {
41
        $views = [];
42
43
        switch ($viewNamespace) {
44
            case 'Victoire\Bundle\PageBundle\Entity\Page':
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
45
46
                $viewReferences = [];
47
                $repo = $this->entityManager->getRepository($viewNamespace);
48
                //get pages and viewReferenceIds
49
                foreach ($repo->getAll()->run() as $key => $page) {
50
                    $viewReference = $this->viewReferenceRepository->getOneReferenceByParameters(
51
                        [
52
                            'viewNamespace' => $viewNamespace,
53
                            'viewId'        => $page->getId(),
54
                        ]
55
                    );
56
                    $viewReferences[$viewReference->getId()] = $viewReference;
57
                }
58
                //get pager
59
                $browseEvents = $this->entityManager->getRepository('Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent')
60
                    ->getMostVisitedFromReferences(array_keys($viewReferences), $number)
61
                    ->getQuery()
62
                    ->getResult();
63
                //Now we get the most visited references, we'll get views with PageHelper
64
                foreach ($browseEvents as $browseEvent) {
65
                    $views[] = $this->pageHelper->findPageByReference(
66
                        $viewReferences[$browseEvent->getViewReferenceId()]
67
                    );
68
                }
69
70
                break;
71
72
            default:
73
                // code...
74
                break;
75
        }
76
77
        return $views;
78
    }
79
80
    /**
0 ignored issues
show
Doc comment for parameter "$blog" missing
Loading history...
Doc comment for parameter "$number" missing
Loading history...
Doc comment for parameter "$excludeUnpublished" missing
Loading history...
81
     * Get the most read articles by blog.
82
     *
83
     * @return Article[]
84
     **/
85
    public function getMostReadArticlesByBlog($blog, $number, $excludeUnpublished = true)
86
    {
87
        $viewReferences = [];
88
        //get articles and viewReferenceIds
89
        $articles = $this->entityManager->getRepository('Victoire\Bundle\BlogBundle\Entity\Article')
90
                    ->getAll($excludeUnpublished)
91
                    ->filterByBlog($blog)
92
                    ->run();
93
94
        foreach ($articles as $key => $article) {
95
            if ($viewReference = $this->viewReferenceRepository->getOneReferenceByParameters(
96
                [
97
                    'entityNamespace' => 'Victoire\Bundle\BlogBundle\Entity\Article',
98
                    'entityId'        => $article->getId(),
99
                ]
100
            )) {
101
                $viewReferences[$viewReference->getId()] = $viewReference;
102
            }
103
        }
104
        //get pager
105
        $browseEvents = $this->entityManager->getRepository('Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent')
106
            ->getMostVisitedFromReferences(array_keys($viewReferences), $number)
107
            ->getQuery()
108
            ->getResult();
109
110
        $views = [];
111
        //Now we get the most visited references, we'll get views with PageHelper
112
        foreach ($browseEvents as $browseEvent) {
113
            $views[] = $this->pageHelper->findPageByReference(
114
                $viewReferences[$browseEvent->getViewReferenceId()]
115
            );
116
        }
117
118
        return $views;
119
    }
120
121
    /**
122
     * Get number of unique visitor for a viewReference.
123
     *
124
     * @param string $viewReferenceId
125
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
126
    public function getVisitorCountForViewReference($viewReferenceId)
127
    {
128
        $viewCount = $this->entityManager->getRepository('Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent')
129
            ->getNumberOfEventForViewReferenceId($viewReferenceId)
130
            ->getQuery()
131
            ->getSingleScalarResult();
132
133
        return $viewCount;
134
    }
135
}
136