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

DateServiceTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 10
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGetTomorrow() 0 6 1
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
}