Passed
Branch master (3fa968)
by Johnny
03:32 queued 01:42
created

HttpTestCase::maxScore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
require '../vendor/autoload.php';
4
5
use Redbox\Testsuite\Test;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Test. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Redbox\Testsuite\TestSuite;
7
8
/**
9
 * JUST A SPEC DEMO FOR MY SELF
10
 */
11
class HttpTestCase extends Test
12
{
13
   
14
    public function minScore()
15
    {
16
        return 3;
17
    }
18
    
19
    public function maxScore()
20
    {
21
        return 10;
22
    }
23
    
24
    
25
    public function run()
26
    {
27
        echo "RUNNING 1\n";
28
        $this->score->setScore(($this->maxScore() - $this->minScore()));
0 ignored issues
show
Bug introduced by
The method setScore() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $this->score->/** @scrutinizer ignore-call */ 
29
                      setScore(($this->maxScore() - $this->minScore()));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        
30
        return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the return type mandated by Redbox\Testsuite\Test::run() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
31
    }
32
}
33
34
class ExtendedHttpTest extends HttpTestCase
35
{
36
    public function run()
37
    {
38
        echo "RUNNING 2\n";
39
        $this->score->setScore(5);
40
        
41
        return true;
42
    }
43
}
44
45
$basic = new HttpTestCase();
46
$extended = new ExtendedHttpTest();
47
48
/**
49
 * Create a test suite
50
 */
51
$suite = new TestSuite();
52
$suite->attach([$basic, $extended]);
53
//$suite->attach([HttpTestCase::class, ExtendedHttpTest::class]);
54
55
56
/**
57
 * Score should be
58
 *
59
 * Test 1 -> Score == 7
60
 * Test 2 -> Score == 5
61
 * ===================+
62
 * Total suite score 12
63
 */
64
$suite->run();
65
66
echo "Total suite score: ".$suite->score()."\n";