Conditions | 2 |
Paths | 2 |
Total Lines | 59 |
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 |
||
75 | public function testSaveUpdateDeleteItem() |
||
76 | { |
||
77 | $search = $this->object->filter()->slice( 0, 1 ); |
||
78 | |||
79 | if( ( $item = $this->object->search( $search )->first() ) === null ) { |
||
80 | throw new \RuntimeException( 'No item found' ); |
||
81 | } |
||
82 | |||
83 | $item->setId( null ); |
||
84 | $item->setDomain( 'unittest' ); |
||
85 | $resultSaved = $this->object->save( $item ); |
||
86 | $itemSaved = $this->object->get( $item->getId() ); |
||
87 | |||
88 | $itemExp = clone $itemSaved; |
||
89 | $itemExp->setDomain( 'unittest2' ); |
||
90 | $resultUpd = $this->object->save( $itemExp ); |
||
91 | $itemUpd = $this->object->get( $itemExp->getId() ); |
||
92 | |||
93 | $this->object->delete( $itemSaved->getId() ); |
||
94 | |||
95 | |||
96 | $this->assertTrue( $item->getId() !== null ); |
||
97 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
98 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
99 | $this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
||
100 | $this->assertEquals( $item->getType(), $itemSaved->getType() ); |
||
101 | $this->assertEquals( $item->getRefId(), $itemSaved->getRefId() ); |
||
102 | $this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
||
103 | $this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
||
104 | $this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
||
105 | $this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
||
106 | $this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
||
107 | $this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeCreated() ); |
||
108 | $this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeModified() ); |
||
109 | |||
110 | $this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
||
111 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
112 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
113 | |||
114 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
115 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
116 | $this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
||
117 | $this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
||
118 | $this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() ); |
||
119 | $this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
||
120 | $this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
||
121 | $this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
||
122 | $this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
||
123 | |||
124 | $this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
||
125 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
126 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
127 | |||
128 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
||
129 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
||
130 | |||
131 | $this->expectException( '\\Aimeos\\MShop\\Exception' ); |
||
132 | $this->object->get( $itemSaved->getId() ); |
||
133 | } |
||
134 | |||
202 |
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: