Completed
Push — master ( 685463...a3ac99 )
by Benedikt
13:47
created

MatchTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 137
Duplicated Lines 22.63 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 31
loc 137
c 0
b 0
f 0
rs 10
wmc 8
lcom 1
cbo 5

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGamesAndChildren() 0 13 1
A testInit() 11 11 1
A testLevel() 0 4 1
A testMatchNumberAndLocalIdentifier() 0 8 1
A testPhaseAndParent() 0 22 1
A testRankingsA() 10 10 1
A testRankingsB() 10 10 1
A match() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 10/1/17
7
 * Time: 1:11 PM
8
 */
9
10
namespace Tfboe\FmLib\Tests\Unit\Entity\Traits;
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use PHPUnit\Framework\MockObject\MockObject;
15
use Tfboe\FmLib\Entity\GameInterface;
16
use Tfboe\FmLib\Entity\PhaseInterface;
17
use Tfboe\FmLib\Entity\Ranking;
18
use Tfboe\FmLib\Entity\Traits\Match;
19
use Tfboe\FmLib\Helpers\Level;
20
use Tfboe\FmLib\TestHelpers\UnitTestCase;
21
22
/**
23
 * Class TournamentTest
24
 * @package Tfboe\FmLib\Tests\Unit\Entity
25
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
26
 */
27
class MatchTest extends UnitTestCase
28
{
29
//<editor-fold desc="Public Methods">
30
  /**
31
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getGames
32
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getChildren
33
   * @uses   \Tfboe\FmLib\Entity\GameInterface
34
   * @uses   \Tfboe\FmLib\Entity\Traits\Match::init
35
   */
36
  public function testGamesAndChildren()
37
  {
38
    $match = $this->match();
39
    $match->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
40
    $game = $this->createMock(GameInterface::class);
41
    $game->method('getGameNumber')->willReturn(1);
42
    /** @var GameInterface $game */
43
    self::assertEquals($match->getGames(), $match->getChildren());
0 ignored issues
show
Bug introduced by
The method getGames does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
Bug introduced by
The method getChildren does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
44
    $match->getGames()->set($game->getGameNumber(), $game);
45
    self::assertEquals(1, $match->getGames()->count());
46
    self::assertEquals($game, $match->getGames()[1]);
47
    self::assertEquals($match->getGames(), $match->getChildren());
48
  }
49
50
  /**
51
   * @covers \Tfboe\FmLib\Entity\Traits\Match::init
52
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
53
   * @uses   \Tfboe\FmLib\Entity\Traits\Match::getGames
54
   * @uses   \Tfboe\FmLib\Entity\Traits\Match::getRankingsA
55
   * @uses   \Tfboe\FmLib\Entity\Traits\Match::getRankingsB
56
   */
57 View Code Duplication
  public function testInit()
0 ignored issues
show
Duplication introduced by
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...
58
  {
59
    $match = $this->match();
60
    $match->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
61
    self::assertInstanceOf(Collection::class, $match->getRankingsA());
0 ignored issues
show
Bug introduced by
The method getRankingsA does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
62
    self::assertInstanceOf(Collection::class, $match->getRankingsB());
0 ignored issues
show
Bug introduced by
The method getRankingsB does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
63
    self::assertInstanceOf(Collection::class, $match->getGames());
0 ignored issues
show
Bug introduced by
The method getGames does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
64
    self::assertEquals(0, $match->getRankingsA()->count());
65
    self::assertEquals(0, $match->getRankingsB()->count());
66
    self::assertEquals(0, $match->getGames()->count());
67
  }
68
69
  /**
70
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getLevel
71
   */
72
  public function testLevel()
73
  {
74
    self::assertEquals(Level::MATCH, $this->match()->getLevel());
0 ignored issues
show
Bug introduced by
The method getLevel does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
75
  }
76
77
  /**
78
   * @covers \Tfboe\FmLib\Entity\Traits\Match::setMatchNumber
79
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getMatchNumber
80
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getLocalIdentifier
81
   */
82
  public function testMatchNumberAndLocalIdentifier()
83
  {
84
    $match = $this->match();
85
    $matchNumber = 1;
86
    $match->setMatchNumber($matchNumber);
0 ignored issues
show
Bug introduced by
The method setMatchNumber does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
87
    self::assertEquals($matchNumber, $match->getMatchNumber());
0 ignored issues
show
Bug introduced by
The method getMatchNumber does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
88
    self::assertEquals($match->getMatchNumber(), $match->getLocalIdentifier());
0 ignored issues
show
Bug introduced by
The method getLocalIdentifier does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
89
  }
90
91
  /**
92
   * @covers \Tfboe\FmLib\Entity\Traits\Match::setPhase
93
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getPhase
94
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getParent
95
   * @uses   \Tfboe\FmLib\Entity\Traits\Match::getMatchNumber
96
   * @uses   \Tfboe\FmLib\Entity\Traits\Match::setMatchNumber
97
   */
98
  public function testPhaseAndParent()
99
  {
100
    $match = $this->match();
101
    $phase = $this->createStub(PhaseInterface::class, ["getMatches" => new ArrayCollection()]);
102
    $match->setMatchNumber(1);
0 ignored issues
show
Bug introduced by
The method setMatchNumber does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
103
    /** @var PhaseInterface $phase */
104
    $match->setPhase($phase);
0 ignored issues
show
Bug introduced by
The method setPhase does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
105
    self::assertEquals($phase, $match->getPhase());
0 ignored issues
show
Bug introduced by
The method getPhase does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
106
    self::assertEquals(1, $match->getPhase()->getMatches()->count());
107
    self::assertEquals($match, $match->getPhase()->getMatches()[$match->getMatchNumber()]);
0 ignored issues
show
Bug introduced by
The method getMatchNumber does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
108
    self::assertEquals($match->getPhase(), $match->getParent());
0 ignored issues
show
Bug introduced by
The method getParent does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
109
110
    $phase2 = $this->createStub(PhaseInterface::class, ["getMatches" => new ArrayCollection()]);
111
112
    /** @var PhaseInterface $phase2 */
113
    $match->setPhase($phase2);
114
    self::assertEquals($phase2, $match->getPhase());
115
    self::assertEquals(1, $match->getPhase()->getMatches()->count());
116
    self::assertEquals(0, $phase->getMatches()->count());
117
    self::assertEquals($match, $match->getPhase()->getMatches()[$match->getMatchNumber()]);
118
    self::assertEquals($match->getPhase(), $match->getParent());
119
  }
120
121
  /**
122
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getRankingsA
123
   * @uses   \Tfboe\FmLib\Entity\Ranking
124
   * @uses   \Tfboe\FmLib\Entity\Traits\Match::init
125
   */
126 View Code Duplication
  public function testRankingsA()
0 ignored issues
show
Duplication introduced by
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...
127
  {
128
    $match = $this->match();
129
    $match->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
130
    $ranking = new Ranking();
131
    $ranking->setUniqueRank(1);
132
    $match->getRankingsA()->set($ranking->getUniqueRank(), $ranking);
0 ignored issues
show
Bug introduced by
The method getRankingsA does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
133
    self::assertEquals(1, $match->getRankingsA()->count());
134
    self::assertEquals($ranking, $match->getRankingsA()[1]);
135
  }
136
137
  /**
138
   * @covers \Tfboe\FmLib\Entity\Traits\Match::getRankingsB
139
   * @uses   \Tfboe\FmLib\Entity\Ranking
140
   * @uses   \Tfboe\FmLib\Entity\Traits\Match::init
141
   */
142 View Code Duplication
  public function testRankingsB()
0 ignored issues
show
Duplication introduced by
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...
143
  {
144
    $match = $this->match();
145
    $match->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
146
    $ranking = new Ranking();
147
    $ranking->setUniqueRank(1);
148
    $match->getRankingsB()->set($ranking->getUniqueRank(), $ranking);
0 ignored issues
show
Bug introduced by
The method getRankingsB does only exist in Tfboe\FmLib\Entity\Traits\Match, but not in PHPUnit\Framework\MockObject\MockObject.

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...
149
    self::assertEquals(1, $match->getRankingsB()->count());
150
    self::assertEquals($ranking, $match->getRankingsB()[1]);
151
  }
152
//</editor-fold desc="Public Methods">
153
154
//<editor-fold desc="Private Methods">
155
  /**
156
   * @return Match|MockObject a new match
157
   */
158
  private function match(): MockObject
159
  {
160
    return $this->getMockForTrait(Match::class);
161
  }
162
//</editor-fold desc="Private Methods">
163
}