| 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 |
||
| 61 | public function testChanges() { |
||
| 62 | $entry = new ChangelogEntry( '1.0' ); |
||
| 63 | $changes = array( |
||
| 64 | new ChangeEntry( |
||
| 65 | array( |
||
| 66 | 'subheading' => 'A', |
||
| 67 | 'content' => '14', |
||
| 68 | ) |
||
| 69 | ), |
||
| 70 | new ChangeEntry( |
||
| 71 | array( |
||
| 72 | 'subheading' => 'B', |
||
| 73 | 'content' => '2', |
||
| 74 | ) |
||
| 75 | ), |
||
| 76 | new ChangeEntry( |
||
| 77 | array( |
||
| 78 | 'subheading' => 'B', |
||
| 79 | 'content' => '8', |
||
| 80 | ) |
||
| 81 | ), |
||
| 82 | new ChangeEntry( |
||
| 83 | array( |
||
| 84 | 'subheading' => 'C', |
||
| 85 | 'content' => '6', |
||
| 86 | ) |
||
| 87 | ), |
||
| 88 | ); |
||
| 89 | |||
| 90 | $this->assertSame( array(), $entry->getChanges() ); |
||
| 91 | $this->assertSame( array(), $entry->getChangesBySubheading() ); |
||
| 92 | $this->assertSame( array(), $entry->getChangesBySubheading( 'B' ) ); |
||
| 93 | |||
| 94 | $this->assertSame( $entry, $entry->setChanges( $changes ) ); |
||
| 95 | $this->assertSame( $changes, $entry->getChanges() ); |
||
| 96 | $this->assertSame( |
||
| 97 | array( |
||
| 98 | 'A' => array( $changes[0] ), |
||
| 99 | 'B' => array( $changes[1], $changes[2] ), |
||
| 100 | 'C' => array( $changes[3] ), |
||
| 101 | ), |
||
| 102 | $entry->getChangesBySubheading() |
||
| 103 | ); |
||
| 104 | $this->assertSame( array( $changes[1], $changes[2] ), $entry->getChangesBySubheading( 'B' ) ); |
||
| 105 | |||
| 106 | $c1 = new ChangeEntry( |
||
| 107 | array( |
||
| 108 | 'subheading' => 'B', |
||
| 109 | 'content' => '5', |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | $c2 = new ChangeEntry( |
||
| 113 | array( |
||
| 114 | 'subheading' => 'B', |
||
| 115 | 'content' => '5', |
||
| 116 | ) |
||
| 117 | ); |
||
| 118 | $c3 = new ChangeEntry( |
||
| 119 | array( |
||
| 120 | 'subheading' => 'X', |
||
| 121 | 'content' => '1', |
||
| 122 | ) |
||
| 123 | ); |
||
| 124 | $this->assertSame( $entry, $entry->insertEntry( $c1 ) ); |
||
| 125 | $this->assertSame( $entry, $entry->insertEntry( $c2, array( 'ordering' => array( 'content' ) ) ) ); |
||
| 126 | $this->assertSame( $entry, $entry->insertEntry( $c3 ) ); |
||
| 127 | $this->assertSame( array( $c2, $changes[0], $changes[1], $c1, $changes[2], $changes[3], $c3 ), $entry->getChanges() ); |
||
| 128 | $this->assertSame( |
||
| 129 | array( |
||
| 130 | 'B' => array( $c2, $changes[1], $c1, $changes[2] ), |
||
| 131 | 'A' => array( $changes[0] ), |
||
| 132 | 'C' => array( $changes[3] ), |
||
| 133 | 'X' => array( $c3 ), |
||
| 134 | ), |
||
| 135 | $entry->getChangesBySubheading() |
||
| 136 | ); |
||
| 137 | $this->assertSame( array( $c2, $changes[1], $c1, $changes[2] ), $entry->getChangesBySubheading( 'B' ) ); |
||
| 138 | } |
||
| 139 | |||
| 200 |
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: