Issues (569)

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.

tests/integration/WriteFileTest.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
namespace Robo;
3
4
use PHPUnit\Framework\TestCase;
5
use Robo\Traits\TestTasksTrait;
6
7
class WriteFileTest extends TestCase
8
{
9
    use TestTasksTrait;
10
    use Task\File\loadTasks;
11
12
    protected $fixtures;
13
14
    public function setUp()
15
    {
16
        $this->fixtures = new Fixtures();
17
        $this->initTestTasksTrait();
18
        $this->fixtures->createAndCdToSandbox();
19
    }
20
21
    public function tearDown()
22
    {
23
        $this->fixtures->cleanup();
24
    }
25
26 View Code Duplication
    public function writeFewLines()
27
    {
28
        // write lines with WriteToFile task
29
        $result = $this->taskWriteToFile('blogpost.md')
0 ignored issues
show
The method line does only exist in Robo\Task\File\Write, but not in Robo\Collection\CollectionBuilder.

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...
30
           ->line('****')
31
           ->line('hello world')
32
           ->line('****')
33
           ->run();
34
        $this->assertTrue($result->wasSuccessful(), $result->getMessage());
35
        $this->assertFileExists('blogpost.md');
36
        $contents = file_get_contents('blogpost.md');
37
        $expreded = <<<HERE
0 ignored issues
show
$expreded is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
****
39
hello world
40
****
41
42
HERE;
43
        $this->assertContains($expected, $contents);
0 ignored issues
show
The variable $expected does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
44
    }
45
46
    public function appendToFile()
47
    {
48
        $result = $this->taskWriteToFile('a.txt')
0 ignored issues
show
The method append does only exist in Robo\Task\File\Write, but not in Robo\Collection\CollectionBuilder.

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...
49
           ->append()
50
           ->line('hello world')
51
           ->run();
52
        $this->assertTrue($result->wasSuccessful(), $result->getMessage());
53
        $this->assertFileExists('a.txt');
54
        $contents = file_get_contents('a.txt');
55
        $expected = <<<HERE
56
Ahello world
57
58
HERE;
59
        $this->assertContains($expected, $contents);
60
    }
61
62
    public function testWouldChange()
63
    {
64
        $writeTask = $this->taskWriteToFile('a.txt')
0 ignored issues
show
The method append does only exist in Robo\Task\File\Write, but not in Robo\Collection\CollectionBuilder.

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...
65
           ->append();
66
        $this->assertEquals(false, $writeTask->wouldChange(), "No changes to test file.");
67
        $writeTask->line('hello world');
68
        $this->assertEquals(true, $writeTask->wouldChange(), "Test file would change.");
69
    }
70
71 View Code Duplication
    public function insertFile()
72
    {
73
        $result = $this->taskWriteToFile('a.txt')
0 ignored issues
show
The method line does only exist in Robo\Task\File\Write, but not in Robo\Collection\CollectionBuilder.

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...
74
            ->line('****')
75
            ->textFromFile('b.txt')
76
            ->line("C")
77
            ->run();
78
        $this->assertTrue($result->wasSuccessful(), $result->getMessage());
79
        $this->assertFileExists('a.txt');
80
        $contents = file_get_contents('a.txt');
81
        $expected = <<<HERE
82
****
83
BC
84
85
HERE;
86
        $this->assertContains($expected, $contents);
87
    }
88
89
    public function appendIfMatch()
90
    {
91
        // append lines with WriteToFile task, but only if pattern does not match
92
        $result = $this->taskWriteToFile('blogpost.md')
0 ignored issues
show
The method line does only exist in Robo\Task\File\Write, but not in Robo\Collection\CollectionBuilder.

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...
93
           ->line('****')
94
           ->line('hello world')
95
           ->line('****')
96
           ->appendUnlessMatches('/hello/', 'Should not add this')
97
           ->appendUnlessMatches('/goodbye/', 'Should add this')
98
           ->appendIfMatches('/hello/', ' and should also add this')
99
           ->appendIfMatches('/goodbye/', ' but should not add this')
100
           ->appendIfMatches('/should/', '!')
101
           ->run();
102
        $this->assertTrue($result->wasSuccessful(), $result->getMessage());
103
        $this->assertFileExists('blogpost.md');
104
        $contents = file_get_contents('blogpost.md');
105
        $expected = <<<HERE
106
****
107
hello world
108
****
109
Should add this and should also add this!
110
HERE;
111
        $this->assertContains($expected, $contents);
112
    }
113
114
    public function replaceInFile()
115
    {
116
        $result = $this->taskReplaceInFile('a.txt')
0 ignored issues
show
The method from does only exist in Robo\Task\File\Replace, but not in Robo\Collection\CollectionBuilder.

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...
117
            ->from('A')
118
            ->to('B')
119
            ->run();
120
        $this->assertTrue($result->wasSuccessful(), $result->getMessage());
121
        $this->assertFileExists('a.txt');
122
        $contents = file_get_contents('a.txt');
123
        $this->assertContains('B', $contents);
124
125
    }
126
127
    public function replaceMultipleInFile()
128
    {
129
        $result = $this->taskReplaceInFile('box/robo.txt')
0 ignored issues
show
The method from does only exist in Robo\Task\File\Replace, but not in Robo\Collection\CollectionBuilder.

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...
130
            ->from(array('HELLO', 'ROBO'))
131
            ->to(array('Hello ', 'robo.li!'))
132
            ->run();
133
        $this->assertTrue($result->wasSuccessful(), $result->getMessage());
134
        $this->assertFileExists('box/robo.txt');
135
        $contents = file_get_contents('box/robo.txt');
136
        $this->assertContains('Hello robo.li!', $contents);
137
    }
138
}
139
140