Conditions | 2 |
Paths | 2 |
Total Lines | 68 |
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 |
||
85 | public function testSave() |
||
86 | { |
||
87 | $manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
||
88 | $this->view->item = $manager->create(); |
||
89 | |||
90 | |||
91 | $param = array( |
||
92 | 'site' => 'unittest', |
||
93 | 'media' => [[ |
||
94 | 'media.id' => '', |
||
95 | 'media.type' => 'default', |
||
96 | 'media.languageid' => 'de', |
||
97 | 'media.label' => 'test', |
||
98 | 'attribute.lists.type' => 'default', |
||
99 | ]], |
||
100 | ); |
||
101 | |||
102 | $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
||
103 | $this->view->addHelper( 'param', $helper ); |
||
104 | |||
105 | $file = $this->getMockBuilder( \Psr\Http\Message\UploadedFileInterface::class )->getMock(); |
||
106 | $request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
||
107 | $request->expects( $this->any() )->method( 'getUploadedFiles' ) |
||
108 | ->will( $this->returnValue( ['media' => [0 => ['file' => $file]]] ) ); |
||
109 | |||
110 | $helper = new \Aimeos\MW\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' ); |
||
|
|||
111 | $this->view ->addHelper( 'request', $helper ); |
||
112 | |||
113 | |||
114 | $name = 'AdminJQAdmAttributeMediaSave'; |
||
115 | $this->context->getConfig()->set( 'controller/common/media/name', $name ); |
||
116 | |||
117 | $cntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Media\\Standard' ) |
||
118 | ->setConstructorArgs( array( $this->context ) ) |
||
119 | ->setMethods( array( 'add' ) ) |
||
120 | ->getMock(); |
||
121 | |||
122 | \Aimeos\Controller\Common\Media\Factory::inject( '\\Aimeos\\Controller\\Common\\Media\\' . $name, $cntlStub ); |
||
123 | |||
124 | $cntlStub->expects( $this->once() )->method( 'add' )->will( $this->returnArgument( 0 ) ); |
||
125 | |||
126 | |||
127 | $result = $this->object->save(); |
||
128 | |||
129 | |||
130 | $this->assertEmpty( $this->view->get( 'errors' ) ); |
||
131 | $this->assertEmpty( $result ); |
||
132 | $this->assertEquals( 1, count( $this->view->item->getListItems() ) ); |
||
133 | |||
134 | foreach( $this->view->item->getListItems( 'media' ) as $listItem ) |
||
135 | { |
||
136 | $this->assertEquals( 'media', $listItem->getDomain() ); |
||
137 | |||
138 | $refItem = $listItem->getRefItem(); |
||
139 | $this->assertEquals( 'de', $refItem->getLanguageId() ); |
||
140 | $this->assertEquals( 'test', $refItem->getLabel() ); |
||
141 | } |
||
142 | |||
143 | |||
144 | $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, ['site' => 'unittest', 'media' => []] ); |
||
145 | $this->view->addHelper( 'param', $helper ); |
||
146 | |||
147 | $result = $this->object->save(); |
||
148 | |||
149 | $this->assertEmpty( $this->view->get( 'errors' ) ); |
||
150 | $this->assertEmpty( $result ); |
||
151 | $this->assertEquals( 0, count( $this->view->item->getListItems() ) ); |
||
152 | } |
||
153 | |||
208 |
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: