| Conditions | 1 |
| Paths | 1 |
| Total Lines | 80 |
| 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 |
||
| 43 | public function testEntries() { |
||
| 44 | $changelog = new Changelog(); |
||
| 45 | $entries = array( |
||
| 46 | 4 => new ChangelogEntry( '4.0' ), |
||
| 47 | 3 => new ChangelogEntry( '3.0' ), |
||
| 48 | 2 => new ChangelogEntry( '2.0' ), |
||
| 49 | 1 => new ChangelogEntry( '1.0' ), |
||
| 50 | ); |
||
| 51 | |||
| 52 | $this->assertSame( array(), $changelog->getEntries() ); |
||
| 53 | $this->assertSame( null, $changelog->getLatestEntry() ); |
||
| 54 | $this->assertSame( array(), $changelog->getVersions() ); |
||
| 55 | $this->assertSame( null, $changelog->findEntryByVersion( '2.0' ) ); |
||
| 56 | $this->assertSame( |
||
| 57 | array(), |
||
| 58 | $changelog->findEntriesByVersions( |
||
| 59 | array( |
||
| 60 | '>=' => '2.0', |
||
| 61 | '<' => '4.0', |
||
| 62 | ) |
||
| 63 | ) |
||
| 64 | ); |
||
| 65 | |||
| 66 | $e = $changelog->addEntry(); |
||
| 67 | $this->assertInstanceOf( ChangelogEntry::class, $e ); |
||
| 68 | $this->assertSame( '0.0.1-dev', $e->getVersion() ); |
||
| 69 | |||
| 70 | $this->assertSame( array( $e ), $changelog->getEntries() ); |
||
| 71 | $this->assertSame( $e, $changelog->getLatestEntry() ); |
||
| 72 | $this->assertSame( array( '0.0.1-dev' ), $changelog->getVersions() ); |
||
| 73 | $this->assertSame( null, $changelog->findEntryByVersion( '2.0' ) ); |
||
| 74 | $this->assertSame( |
||
| 75 | array(), |
||
| 76 | $changelog->findEntriesByVersions( |
||
| 77 | array( |
||
| 78 | '>=' => '2.0', |
||
| 79 | '<' => '4.0', |
||
| 80 | ) |
||
| 81 | ) |
||
| 82 | ); |
||
| 83 | |||
| 84 | $this->assertSame( $changelog, $changelog->setEntries( $entries ) ); |
||
| 85 | $this->assertSame( array_values( $entries ), $changelog->getEntries() ); |
||
| 86 | $this->assertSame( $entries[4], $changelog->getLatestEntry() ); |
||
| 87 | $this->assertSame( array( '4.0', '3.0', '2.0', '1.0' ), $changelog->getVersions() ); |
||
| 88 | $this->assertSame( $entries[2], $changelog->findEntryByVersion( '2.0' ) ); |
||
| 89 | $this->assertSame( |
||
| 90 | array( $entries[3], $entries[2] ), |
||
| 91 | $changelog->findEntriesByVersions( |
||
| 92 | array( |
||
| 93 | '>=' => '2.0', |
||
| 94 | '<' => '4.0', |
||
| 95 | ) |
||
| 96 | ) |
||
| 97 | ); |
||
| 98 | |||
| 99 | $e1 = $changelog->addEntry(); |
||
| 100 | $this->assertInstanceOf( ChangelogEntry::class, $e1 ); |
||
| 101 | $this->assertSame( '4.0-p1', $e1->getVersion() ); |
||
| 102 | $e2 = $changelog->addEntry(); |
||
| 103 | $this->assertInstanceOf( ChangelogEntry::class, $e2 ); |
||
| 104 | $this->assertSame( '4.0-p2', $e2->getVersion() ); |
||
| 105 | $e2->setVersion( '4.0-dev+pl_123' ); |
||
| 106 | $e3 = $changelog->addEntry(); |
||
| 107 | $this->assertInstanceOf( ChangelogEntry::class, $e3 ); |
||
| 108 | $this->assertSame( '4.0-dev+pl_124', $e3->getVersion() ); |
||
| 109 | $this->assertSame( array_merge( array( $e3, $e2, $e1 ), array_values( $entries ) ), $changelog->getEntries() ); |
||
| 110 | $this->assertSame( $e3, $changelog->getLatestEntry() ); |
||
| 111 | $this->assertSame( array( '4.0-dev+pl_124', '4.0-dev+pl_123', '4.0-p1', '4.0', '3.0', '2.0', '1.0' ), $changelog->getVersions() ); |
||
| 112 | $this->assertSame( $entries[2], $changelog->findEntryByVersion( '2.0' ) ); |
||
| 113 | $this->assertSame( |
||
| 114 | array( $e3, $e2, $entries[3], $entries[2] ), |
||
| 115 | $changelog->findEntriesByVersions( |
||
| 116 | array( |
||
| 117 | '>=' => '2.0', |
||
| 118 | '<' => '4.0', |
||
| 119 | ) |
||
| 120 | ) |
||
| 121 | ); |
||
| 122 | } |
||
| 123 | |||
| 145 |
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: