Completed
Push — master ( 01d8d1...58ca4d )
by Simon
01:47
created

DateServiceTest::testGetTomorrow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Firesphere\PartialUserforms\Tests;
4
5
use Firesphere\PartialUserforms\Services\DateService;
6
use SilverStripe\Dev\SapphireTest;
7
8
class DateServiceTest extends SapphireTest
9
{
10
11
    public function testGetTomorrow()
12
    {
13
        $tomorrow = DateService::getTomorrow();
14
15
        $this->assertEquals(date('d', strtotime('+1 day')), $tomorrow->Format('dd'));
0 ignored issues
show
Bug introduced by
The method Format does only exist in SilverStripe\ORM\FieldType\DBDatetime, but not in Firesphere\PartialUserforms\Services\DateService.

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...
16
    }
17
}