| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
| 66 | public function testChanges() { |
||
| 67 | $entry = new ChangelogEntry( '1.0' ); |
||
| 68 | $changes = array( |
||
| 69 | new ChangeEntry( |
||
| 70 | array( |
||
| 71 | 'subheading' => 'A', |
||
| 72 | 'content' => '14', |
||
| 73 | ) |
||
| 74 | ), |
||
| 75 | new ChangeEntry( |
||
| 76 | array( |
||
| 77 | 'subheading' => 'B', |
||
| 78 | 'content' => '2', |
||
| 79 | ) |
||
| 80 | ), |
||
| 81 | new ChangeEntry( |
||
| 82 | array( |
||
| 83 | 'subheading' => 'B', |
||
| 84 | 'content' => '8', |
||
| 85 | ) |
||
| 86 | ), |
||
| 87 | new ChangeEntry( |
||
| 88 | array( |
||
| 89 | 'subheading' => 'C', |
||
| 90 | 'content' => '6', |
||
| 91 | ) |
||
| 92 | ), |
||
| 93 | ); |
||
| 94 | |||
| 95 | $this->assertSame( array(), $entry->getChanges() ); |
||
| 96 | $this->assertSame( array(), $entry->getChangesBySubheading() ); |
||
| 97 | $this->assertSame( array(), $entry->getChangesBySubheading( 'B' ) ); |
||
| 98 | |||
| 99 | $this->assertSame( $entry, $entry->setChanges( $changes ) ); |
||
| 100 | $this->assertSame( $changes, $entry->getChanges() ); |
||
| 101 | $this->assertSame( |
||
| 102 | array( |
||
| 103 | 'A' => array( $changes[0] ), |
||
| 104 | 'B' => array( $changes[1], $changes[2] ), |
||
| 105 | 'C' => array( $changes[3] ), |
||
| 106 | ), |
||
| 107 | $entry->getChangesBySubheading() |
||
| 108 | ); |
||
| 109 | $this->assertSame( array( $changes[1], $changes[2] ), $entry->getChangesBySubheading( 'B' ) ); |
||
| 110 | |||
| 111 | $c1 = new ChangeEntry( |
||
| 112 | array( |
||
| 113 | 'subheading' => 'B', |
||
| 114 | 'content' => '5', |
||
| 115 | ) |
||
| 116 | ); |
||
| 117 | $c2 = new ChangeEntry( |
||
| 118 | array( |
||
| 119 | 'subheading' => 'B', |
||
| 120 | 'content' => '5', |
||
| 121 | ) |
||
| 122 | ); |
||
| 123 | $c3 = new ChangeEntry( |
||
| 124 | array( |
||
| 125 | 'subheading' => 'X', |
||
| 126 | 'content' => '1', |
||
| 127 | ) |
||
| 128 | ); |
||
| 129 | $this->assertSame( $entry, $entry->insertEntry( $c1 ) ); |
||
| 130 | $this->assertSame( $entry, $entry->insertEntry( $c2, array( 'ordering' => array( 'content' ) ) ) ); |
||
| 131 | $this->assertSame( $entry, $entry->insertEntry( $c3 ) ); |
||
| 132 | $this->assertSame( array( $c2, $changes[0], $changes[1], $c1, $changes[2], $changes[3], $c3 ), $entry->getChanges() ); |
||
| 133 | $this->assertSame( |
||
| 134 | array( |
||
| 135 | 'B' => array( $c2, $changes[1], $c1, $changes[2] ), |
||
| 136 | 'A' => array( $changes[0] ), |
||
| 137 | 'C' => array( $changes[3] ), |
||
| 138 | 'X' => array( $c3 ), |
||
| 139 | ), |
||
| 140 | $entry->getChangesBySubheading() |
||
| 141 | ); |
||
| 142 | $this->assertSame( array( $c2, $changes[1], $c1, $changes[2] ), $entry->getChangesBySubheading( 'B' ) ); |
||
| 143 | } |
||
| 144 | |||
| 205 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: