Issues (7)

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.

tests/Indexer/FileIndexerTest.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 JK\SamBundle\Tests\Indexer;
4
5
use Exception;
6
use JK\SamBundle\Watcher\Indexer\FileIndexer;
7
use PHPUnit\Framework\TestCase;
8
use SplFileInfo;
9
use Symfony\Component\Finder\Finder;
10
11
class FileIndexerTest extends TestCase
12
{
13
    /**
14
     * An invalid directory should throw an Exception.
15
     */
16 View Code Duplication
    public function testIndexException()
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...
17
    {
18
        $indexer = new FileIndexer();
19
        $exceptionRaised = false;
20
21
        try {
22
            $indexer->index([
23
                __DIR__.'/assets'
24
            ]);
25
        } catch (Exception $exception) {
26
            $exceptionRaised = true;
27
        }
28
        $this->assertTrue($exceptionRaised);
29
    }
30
31
    /**
32
     * The files in the given directory to index should be added to the index during indexing.
33
     */
34 View Code Duplication
    public function testIndex()
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...
35
    {
36
        $indexer = new FileIndexer();
37
        $indexer->index([
38
            $this->getAssetsDirectory()
39
        ]);
40
        $finder = new Finder();
41
        $finder
42
            ->files()
43
            ->in($this->getAssetsDirectory())
44
        ;
45
46
        foreach ($finder as $fileInfo) {
47
            $this->assertTrue($indexer->has($fileInfo->getRealPath()));
48
            $this->assertInstanceOf(SplFileInfo::class, $indexer->get($fileInfo->getRealPath()));
49
        }
50
    }
51
52
    /**
53
     * The files in the given directory to index should be added to the index during indexing.
54
     */
55 View Code Duplication
    public function testIndexFilteredByExtensions()
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...
56
    {
57
        $indexer = new FileIndexer();
58
        $indexer->index([
59
            $this->getAssetsDirectory()
60
        ], [
61
            'txt'
62
        ]);
63
        $finder = new Finder();
64
        $finder
65
            ->files()
66
            ->in($this->getAssetsDirectory())
67
            ->name('*.txt')
68
        ;
69
70
        foreach ($finder as $fileInfo) {
71
            $this->assertTrue($indexer->has($fileInfo->getRealPath()));
72
            $this->assertInstanceOf(SplFileInfo::class, $indexer->get($fileInfo->getRealPath()));
73
        }
74
    }
75
76
    /**
77
     * Adding a invalid file should throw an exception.
78
     */
79 View Code Duplication
    public function testAddException()
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...
80
    {
81
        $indexer = new FileIndexer();
82
        $exceptionRaised = false;
83
84
        try {
85
            $indexer->add(new SplFileInfo('/some_path/is_wrong'));
86
        } catch (Exception $exception) {
87
            $exceptionRaised = true;
88
        }
89
        $this->assertTrue($exceptionRaised);
90
    }
91
92
    /**
93
     * Adding a invalid file should throw an exception.
94
     */
95 View Code Duplication
    public function testGetException()
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...
96
    {
97
        $indexer = new FileIndexer();
98
        $exceptionRaised = false;
99
100
        try {
101
            $indexer->get('/some_path/is_wrong');
102
        } catch (Exception $exception) {
103
            $exceptionRaised = true;
104
        }
105
        $this->assertTrue($exceptionRaised);
106
    }
107
108
    /**
109
     * The reindex should only put in the change set the modified files.
110
     */
111
    public function testReIndex()
112
    {
113
        $modifiedFile = $this->getAssetsDirectory().'/test.scss';
114
        $indexer = new FileIndexer();
115
116
        // index for the first time
117
        $indexer->index([
118
            $this->getAssetsDirectory()
119
        ], [
120
            'scss'
121
        ]);
122
123
        // modify a file
124
        touch($modifiedFile);
125
126
        // reindex
127
        $indexer->index([
128
            $this->getAssetsDirectory()
129
        ]);
130
131
        // one file must be found in the change set
132
        $this->assertCount(1, $indexer->getChangedEntries());
133
        $this->assertTrue($indexer->hasChangedEntries());
134
        $this->assertEquals($modifiedFile, $indexer->get($modifiedFile)->getRealPath());
135
136
    }
137
138
    protected function getAssetsDirectory()
139
    {
140
        return realpath(__DIR__.'/../fixtures/assets');
141
    }
142
}
143