Issues (6)

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/Units/ComparatorInterfaceTestCase.php (2 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
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Comparable\Tests\Units;
12
13
use Cubiche\Core\Comparable\Comparator;
14
use Cubiche\Core\Comparable\ComparatorInterface;
15
use Cubiche\Core\Visitor\Tests\Units\VisiteeInterfaceTestCase;
16
17
/**
18
 * Comparator Interface Test Case Class.
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 * @author Karel Osorio Ramírez <[email protected]>
22
 */
23
abstract class ComparatorInterfaceTestCase extends VisiteeInterfaceTestCase
24
{
25
    /**
26
     * Test class.
27
     */
28
    public function testClass()
29
    {
30
        $this
31
            ->testedClass
32
                ->implements(ComparatorInterface::class)
33
        ;
34
    }
35
36
    /**
37
     * Test compare.
38
     *
39
     * @param mixed $a
40
     * @param mixed $b
41
     * @param int   $expected
42
     *
43
     * @dataProvider compareDataProvider
44
     */
45 View Code Duplication
    public function testCompare($a, $b, $expected)
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...
46
    {
47
        $this
48
            ->assert('The comparision is right')
49
                /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */
50
                ->given($comparator = $this->newDefaultTestedInstance())
51
                ->then($this->comparision($comparator, $a, $b, $expected));
52
53
        $this
54
            ->assert('The comparator is a callable')
55
                ->given($result1 = $comparator->compare($a, $b))
56
                ->when($result2 = $comparator($a, $b))
57
                ->then()
58
                    ->variable($result1)
59
                        ->isEqualTo($result2);
60
    }
61
62
    /**
63
     * Test reverse method.
64
     *
65
     * @param mixed $a
66
     * @param mixed $b
67
     * @param int   $expected
68
     *
69
     * @dataProvider compareDataProvider
70
     */
71
    public function testReverse($a, $b, $expected)
72
    {
73
        $this
74
            ->assert('Reverse is a comparator')
75
                /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */
76
                ->given($comparator = $this->newDefaultTestedInstance())
77
                ->when($reverse = $comparator->reverse())
78
                    ->then()
79
                        ->object($reverse)
80
                            ->isInstanceOf(ComparatorInterface::class)
81
        ;
82
83
        $this
84
            ->assert('Reverse result is the inverse result')
85
                ->then($this->comparision($reverse, $a, $b, -1 * $expected))
86
        ;
87
    }
88
89
    /**
90
     * Test otherwise method.
91
     *
92
     * @param callable $otherwise
93
     * @param mixed    $a
94
     * @param mixed    $b
95
     * @param int      $expected
96
     *
97
     * @dataProvider otherwiseDataProvider
98
     */
99 View Code Duplication
    public function testOtherwise(callable $otherwise, $a, $b, $expected)
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...
100
    {
101
        $this
102
            ->assert('The otherwise result is a comparator')
103
                /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */
104
                ->given($comparator = $this->newDefaultTestedInstance())
105
                ->when($otherwiseComparator = $comparator->otherwise($otherwise))
106
                    ->object($otherwiseComparator)
107
                        ->isInstanceOf(ComparatorInterface::class)
108
        ;
109
110
        $this
111
            ->assert('The otherwise comparator result is right')
112
                ->let($expected = $this->sign($expected))
113
                ->then(
114
                    $this->comparision($otherwiseComparator, $a, $b, $expected == 0 ? $otherwise($a, $b) : $expected)
115
                )
116
        ;
117
    }
118
119
    /**
120
     * @return array
121
     */
122
    abstract protected function compareDataProvider();
123
124
    /**
125
     * @return array
126
     */
127
    protected function otherwiseDataProvider()
128
    {
129
        foreach ($this->compareDataProvider() as $key => $data) {
130
            yield $key => \array_merge(array($this->newDefaultOtherwiseComparator()), $data);
131
        }
132
    }
133
134
    /**
135
     * @return callable
136
     */
137
    abstract protected function newDefaultOtherwiseComparator();
138
139
    /**
140
     * @param ComparatorInterface $comparator
141
     * @param mixed               $a
142
     * @param mixed               $b
143
     * @param int                 $expected
144
     */
145
    protected function comparision(ComparatorInterface $comparator, $a, $b, $expected)
146
    {
147
        $this
148
            ->given($comparator)
149
            ->when($result = $comparator->compare($a, $b))
150
            ->then()
151
                ->integer($this->sign($result))
152
                    ->isEqualTo($this->sign($expected))
153
        ;
154
    }
155
156
    /**
157
     * @param float|int $number
158
     *
159
     * @return int
160
     */
161
    protected function sign($number)
162
    {
163
        return $number >= 0 ? ($number == 0 ? 0 : 1) : -1;
164
    }
165
}
166