Issues (116)

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.

spec/Analytics/ReportSpec.php (3 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 spec\Scriptotek\Alma\Analytics;
4
5
use PhpSpec\ObjectBehavior;
6
use Scriptotek\Alma\Analytics\Report;
7
use Scriptotek\Alma\Analytics\Row;
8
use Scriptotek\Alma\Client;
9
use Scriptotek\Alma\Exception\ResourceNotFound;
10
use spec\Scriptotek\Alma\SpecHelper;
11
12
class ReportSpec extends ObjectBehavior
13
{
14
    public function let(Client $almaClient)
15
    {
16
        $this->beConstructedWith($almaClient, '/test/path');
17
    }
18
19
    public function it_is_initializable()
20
    {
21
        $this->shouldHaveType(Report::class);
22
    }
23
24
    public function it_supports_setting_headers(Client $almaClient)
25
    {
26
        $this->beConstructedWith($almaClient, '/test/path', ['a', 'b']);
27
28
        $this->headers->shouldBe(['a', 'b']);
0 ignored issues
show
The property headers does not exist on object<spec\Scriptotek\Alma\Analytics\ReportSpec>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
29
    }
30
31
    public function it_supports_setting_filter(Client $almaClient)
32
    {
33
        $this->beConstructedWith($almaClient, '/test/path', ['a', 'b'], 'la la la');
34
35
        $this->filter->shouldBe('la la la');
0 ignored issues
show
The property filter does not exist on object<spec\Scriptotek\Alma\Analytics\ReportSpec>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
36
    }
37
38
    public function it_parses_column_headers(Client $almaClient)
39
    {
40
        $almaClient->getXML('/analytics/reports?path=%2Ftest%2Fpath&limit=1000')
41
            ->shouldBeCalledTimes(1)
42
            ->willReturn(SpecHelper::getDummyData('analytics_response.xml'));
43
44
        // $this->getHeaders()->shouldHaveCount(11);
45
        $this->getHeaders()->shouldContain('Event Start Date and Time');
46
47
        $firstRow = $this->current();
48
        $firstRow->shouldHaveType(Row::class);
49
        $firstRow['Event Start Date and Time']->shouldBe('2017-08-29T15:43:53');
50
    }
51
52
    public function it_supports_resumption(Client $almaClient)
53
    {
54
        $path = '/test/path';
0 ignored issues
show
$path 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...
55
56
        // To speed up tests
57
        Report::$retryDelayTime = 0;
58
59
        $almaClient->getXML('/analytics/reports?path=%2Ftest%2Fpath&limit=1000')
60
            ->shouldBeCalledTimes(1)
61
            ->willReturn(SpecHelper::getDummyData('analytics_response_part1.xml'));
62
63
        $almaClient->getXML('/analytics/reports?limit=1000&token=9672D715A8E2EAAA6F30DD22FC52BE4CCAE35E29D921E0AC8BE8C6734C9E1571B4E48EEFCA4046EFF8CD7D1662C2D0A7677D3AD05EDC3CA7F06182E34E9D7A2F')
64
            ->shouldBeCalledTimes(3)
65
            ->willReturn(
66
67
                // If Analytics is having a bad day, we might get a "still loading" response
68
                // See: https://bitbucket.org/uwlib/uwlib-alma-analytic-tools/wiki/Understanding_Analytic_GET_Requests#!analytic-still-loading
69
                SpecHelper::getDummyData('analytics_still_loading_response.xml'),
70
                SpecHelper::getDummyData('analytics_response_part2.xml'),
71
                SpecHelper::getDummyData('analytics_response_part3.xml')
72
            );
73
74
        $this->shouldHaveCount(150 + 150 + 88);
75
    }
76
77
    public function it_might_not_exist(Client $almaClient)
78
    {
79
        $almaClient->getXML('/analytics/reports?path=%2Ftest%2Fpath&limit=1000')
80
            ->shouldBeCalledTimes(1)
81
            ->willThrow(new ResourceNotFound('Path not found (/test/path)'));
82
83
        $this->exists()->shouldReturn(false);
84
    }
85
}
86