Issues (26)

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/LogIteratorTest.php (9 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
/*
4
 * (c) Mantas Varatiejus <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace MVar\Apache2LogParser\Tests;
11
12
use MVar\Apache2LogParser\Exception\NoMatchesException;
13
use MVar\Apache2LogParser\LineParserInterface;
14
use MVar\Apache2LogParser\LogIterator;
15
16
class LogIteratorTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * Creates and returns instance of parser mock.
20
     *
21
     * @return \PHPUnit_Framework_MockObject_MockObject|LineParserInterface
22
     */
23
    protected function getParser()
24
    {
25
        return $this->getMock('\\MVar\\Apache2LogParser\\LineParserInterface');
26
    }
27
28
    /**
29
     * Test for log iterator.
30
     *
31
     * @param string $logfile
32
     * @param int    $rowsCount
33
     *
34
     * @dataProvider getTestIteratorData()
35
     */
36
    public function testIterator($logfile, $rowsCount)
37
    {
38
        $parser = $this->getParser();
39
        $expectedData = 'parsed_line';
40
41
        // Test if parser was called as many times as expected
42
        $parser->expects($this->exactly($rowsCount))
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in MVar\Apache2LogParser\LineParserInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
43
            ->method('parseLine')
44
            ->willReturn($expectedData);
45
46
        $iterator = new LogIterator($logfile, $parser);
0 ignored issues
show
It seems like $parser defined by $this->getParser() on line 38 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, MVar\LogParser\LogIterator::__construct() does only seem to accept object<MVar\LogParser\LineParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Deprecated Code introduced by
The class MVar\Apache2LogParser\LogIterator has been deprecated with message: Will be removed in 3.0. Use \MVar\LogParser\LogIterator instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
47
48
        foreach ($iterator as $line => $data) {
49
            $this->assertTrue(is_string($line));
50
            $this->assertEquals($data, $expectedData);
51
        }
52
    }
53
54
    /**
55
     * Test for iterator in case of empty lines in log.
56
     */
57
    public function testIteratorWithEmptyLines()
58
    {
59
        $parser = $this->getParser();
60
61
        $parser->expects($this->exactly(3))
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in MVar\Apache2LogParser\LineParserInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
62
            ->method('parseLine')
63
            ->will(
64
                $this->onConsecutiveCalls(
65
                    $this->returnValue('parsed_line'),
66
                    $this->throwException(new NoMatchesException()),
0 ignored issues
show
Deprecated Code introduced by
The class MVar\Apache2LogParser\Exception\NoMatchesException has been deprecated with message: Will be removed in 3.0. Use \MVar\LogParser\Exception\MatchException instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
67
                    $this->returnValue('parsed_line')
68
                )
69
            );
70
71
        $iterator = new LogIterator(__DIR__ . '/Fixtures/access.log', $parser, false);
0 ignored issues
show
It seems like $parser defined by $this->getParser() on line 59 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, MVar\LogParser\LogIterator::__construct() does only seem to accept object<MVar\LogParser\LineParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Deprecated Code introduced by
The class MVar\Apache2LogParser\LogIterator has been deprecated with message: Will be removed in 3.0. Use \MVar\LogParser\LogIterator instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
72
73
        $result = [];
74
        foreach ($iterator as $data) {
75
            $result[] = $data;
76
        }
77
78
        // Test if empty line was not parsed (NULL)
79
        $expectedResult = ['parsed_line', null, 'parsed_line'];
80
81
        $this->assertEquals($expectedResult, $result);
82
    }
83
84
    /**
85
     * Test for iterator in case of file handler exception.
86
     *
87
     * @expectedException \MVar\Apache2LogParser\Exception\ParserException
88
     * @expectedExceptionMessage Can not open log file
89
     */
90
    public function testIteratorFileException()
91
    {
92
        $iterator = new LogIterator(__DIR__ . '/Fixtures/non_existing_file.log', $this->getParser());
0 ignored issues
show
It seems like $this->getParser() targeting MVar\Apache2LogParser\Te...eratorTest::getParser() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, MVar\LogParser\LogIterator::__construct() does only seem to accept object<MVar\LogParser\LineParserInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Deprecated Code introduced by
The class MVar\Apache2LogParser\LogIterator has been deprecated with message: Will be removed in 3.0. Use \MVar\LogParser\LogIterator instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
93
        $iterator->rewind();
94
    }
95
96
    /**
97
     * Data provider for testIterator().
98
     *
99
     * @return array[]
100
     */
101
    public function getTestIteratorData()
102
    {
103
        $data = [];
104
105
        // Simple log
106
        $data[] = [__DIR__ . '/Fixtures/access.log', 2];
107
108
        // Compressed log
109
        $data[] = ['compress.zlib://file://' . __DIR__ . '/Fixtures/access_compressed.gz', 4];
110
111
        return $data;
112
    }
113
}
114