We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 |
||
| 46 | class Dewidow_Fix_Test extends Node_Fix_Testcase { |
||
| 47 | /** |
||
| 48 | * Sets up the fixture, for example, opens a network connection. |
||
| 49 | * This method is called before a test is executed. |
||
| 50 | */ |
||
| 51 | protected function setUp() { // @codingStandardsIgnoreLine |
||
| 52 | parent::setUp(); |
||
| 53 | |||
| 54 | $this->fix = new Dewidow_Fix(); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Provide data for testing dewidowing. |
||
| 59 | * |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | public function provide_dewidow_data() { |
||
| 63 | return [ |
||
| 64 | [ 'bla foo b', 'bla foo b', 3, 2 ], |
||
| 65 | [ 'bla foo b', 'bla foo b', 3, 2 ], // don't replace thin space... |
||
| 66 | [ 'bla foo b', 'bla foo b', 3, 2 ], // ... or hair space. |
||
| 67 | [ 'bla foo bar', 'bla foo bar', 2, 2 ], |
||
| 68 | [ 'bla foo bär...', 'bla foo bär...', 3, 3 ], |
||
| 69 | [ 'bla foo bär…!', 'bla foo bär…!', 3, 3 ], |
||
| 70 | [ 'bla foo bär­!', 'bla foo bär!', 3, 3 ], |
||
| 71 | [ 'bla foo b­är!', 'bla foo bär!', 3, 3 ], |
||
| 72 | [ 'bla foo b​är!', 'bla foo bär!', 3, 3 ], |
||
| 73 | [ 'bla foo bär...', 'bla foo bär...', 3, 3 ], |
||
| 74 | [ 'bla föö​bar s', 'bla föö​bar s', 3, 2 ], |
||
| 75 | [ 'bla foo​bar s', 'bla foo​bar s', 2, 2 ], |
||
| 76 | [ 'bla foo­bar', 'bla foo­bar', 3, 3 ], // ­ not matched. |
||
| 77 | [ 'bla foo­bar bar', 'bla foo­bar bar', 3, 3 ], // ­ not matched, but syllable after is. |
||
| 78 | [ 'bla foo​bar bar', 'bla foo​bar bar', 3, 3 ], |
||
| 79 | [ 'bla foo bar bar', 'bla foo bar bar', 3, 3 ], // widow not replaced because the would pull too many letters from previous. |
||
| 80 | ]; |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Test apply. |
||
| 85 | * |
||
| 86 | * @covers ::apply |
||
| 87 | * |
||
| 88 | * @dataProvider provide_dewidow_data |
||
| 89 | * |
||
| 90 | * @param string $html HTML input. |
||
| 91 | * @param string $result Expected result. |
||
| 92 | * @param int $max_pull Maximum number of pulled characters. |
||
| 93 | * @param int $max_length Maximum word length for dewidowing. |
||
| 94 | */ |
||
| 95 | public function test_apply( $html, $result, $max_pull, $max_length ) { |
||
| 96 | $this->s->set_dewidow( true ); |
||
| 97 | $this->s->set_max_dewidow_pull( $max_pull ); |
||
| 98 | $this->s->set_max_dewidow_length( $max_length ); |
||
| 99 | |||
| 100 | $this->assertFixResultSame( $html, $result ); |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Test dewidow. |
||
| 105 | * |
||
| 106 | * @covers ::apply |
||
| 107 | * |
||
| 108 | * @dataProvider provide_dewidow_data |
||
| 109 | * |
||
| 110 | * @param string $html HTML input. |
||
| 111 | * @param string $result Expected result. |
||
| 112 | * @param int $max_pull Maximum number of pulled characters. |
||
| 113 | * @param int $max_length Maximum word length for dewidowing. |
||
| 114 | */ |
||
| 115 | public function test_apply_off( $html, $result, $max_pull, $max_length ) { |
||
| 116 | $this->s->set_dewidow( false ); |
||
| 117 | $this->s->set_max_dewidow_pull( $max_pull ); |
||
| 118 | $this->s->set_max_dewidow_length( $max_length ); |
||
| 119 | |||
| 120 | $this->assertFixResultSame( $html, $html ); |
||
| 121 | } |
||
| 122 | } |
||
| 123 |