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  | 
            ||
| 16 | trait PrinterContents  | 
            ||
| 17 | { | 
            ||
| 18 | /**  | 
            ||
| 19 | * Holds an instance of the style.  | 
            ||
| 20 | *  | 
            ||
| 21 | * Style is a class we use to interact with output.  | 
            ||
| 22 | *  | 
            ||
| 23 | * @var Style  | 
            ||
| 24 | */  | 
            ||
| 25 | private $style;  | 
            ||
| 26 | |||
| 27 | /**  | 
            ||
| 28 | * Holds the duration time of the test suite.  | 
            ||
| 29 | *  | 
            ||
| 30 | * @var Timer  | 
            ||
| 31 | */  | 
            ||
| 32 | private $timer;  | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * Holds the state of the test  | 
            ||
| 36 | * suite. The number of tests, etc.  | 
            ||
| 37 | *  | 
            ||
| 38 | * @var State  | 
            ||
| 39 | */  | 
            ||
| 40 | private $state;  | 
            ||
| 41 | |||
| 42 | /**  | 
            ||
| 43 | * If the test suite has ended before.  | 
            ||
| 44 | *  | 
            ||
| 45 | * @var bool  | 
            ||
| 46 | */  | 
            ||
| 47 | private $ended = false;  | 
            ||
| 48 | |||
| 49 | /**  | 
            ||
| 50 | * Creates a new instance of the listener.  | 
            ||
| 51 | *  | 
            ||
| 52 | * @param ConsoleOutput $output  | 
            ||
| 53 | *  | 
            ||
| 54 | * @throws \ReflectionException  | 
            ||
| 55 | */  | 
            ||
| 56 | 3 | public function __construct(ConsoleOutput $output = null)  | 
            |
| 73 | |||
| 74 | /**  | 
            ||
| 75 |      * {@inheritdoc} | 
            ||
| 76 | */  | 
            ||
| 77 | View Code Duplication | public function addError(Test $testCase, Throwable $throwable, float $time): void  | 
            |
| 85 | |||
| 86 | /**  | 
            ||
| 87 |      * {@inheritdoc} | 
            ||
| 88 | */  | 
            ||
| 89 | public function addWarning(Test $testCase, Warning $warning, float $time): void  | 
            ||
| 95 | |||
| 96 | /**  | 
            ||
| 97 |      * {@inheritdoc} | 
            ||
| 98 | */  | 
            ||
| 99 | public function addFailure(Test $testCase, AssertionFailedError $error, float $time): void  | 
            ||
| 116 | |||
| 117 | /**  | 
            ||
| 118 |      * {@inheritdoc} | 
            ||
| 119 | */  | 
            ||
| 120 | public function addIncompleteTest(Test $testCase, Throwable $t, float $time): void  | 
            ||
| 126 | |||
| 127 | /**  | 
            ||
| 128 |      * {@inheritdoc} | 
            ||
| 129 | */  | 
            ||
| 130 | public function addRiskyTest(Test $testCase, Throwable $t, float $time): void  | 
            ||
| 136 | |||
| 137 | /**  | 
            ||
| 138 |      * {@inheritdoc} | 
            ||
| 139 | */  | 
            ||
| 140 | public function addSkippedTest(Test $testCase, Throwable $t, float $time): void  | 
            ||
| 146 | |||
| 147 | /**  | 
            ||
| 148 |      * {@inheritdoc} | 
            ||
| 149 | */  | 
            ||
| 150 | public function startTestSuite(TestSuite $suite): void  | 
            ||
| 156 | |||
| 157 | /**  | 
            ||
| 158 |      * {@inheritdoc} | 
            ||
| 159 | */  | 
            ||
| 160 | public function endTestSuite(TestSuite $suite): void  | 
            ||
| 171 | |||
| 172 | /**  | 
            ||
| 173 |      * {@inheritdoc} | 
            ||
| 174 | */  | 
            ||
| 175 | 1 | public function startTest(Test $testCase): void  | 
            |
| 188 | |||
| 189 | /**  | 
            ||
| 190 |      * {@inheritdoc} | 
            ||
| 191 | */  | 
            ||
| 192 | View Code Duplication | public function endTest(Test $testCase, float $time): void  | 
            |
| 200 | |||
| 201 | /**  | 
            ||
| 202 | * Intentionally left blank as we output things on events of the listener.  | 
            ||
| 203 | *  | 
            ||
| 204 | * @param string $content  | 
            ||
| 205 | *  | 
            ||
| 206 | * @return void  | 
            ||
| 207 | */  | 
            ||
| 208 | public function write(string $content): void  | 
            ||
| 212 | |||
| 213 | /**  | 
            ||
| 214 | * Returns a test case from the given test.  | 
            ||
| 215 | *  | 
            ||
| 216 | * Note: This printer is do not work with normal Test classes - only  | 
            ||
| 217 | * with Test Case classes. Please report an issue if you think  | 
            ||
| 218 | * this should work any other way.  | 
            ||
| 219 | *  | 
            ||
| 220 | * @param Test $test  | 
            ||
| 221 | *  | 
            ||
| 222 | * @return TestCase  | 
            ||
| 223 | */  | 
            ||
| 224 | 1 | private function testCaseFromTest(Test $test): TestCase  | 
            |
| 232 | }  | 
            ||
| 233 | 
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..