Completed
Push — master ( 1098fc...255b7f )
by Aimeos
02:28
created
admin/jsonadm/src/Admin/JsonAdm/Catalog/Standard.php 2 patches
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param \Psr\Http\Message\ResponseInterface $response Response object
111 111
 	 * @return \Psr\Http\Message\ResponseInterface Modified response object
112 112
 	 */
113
-	public function get( ServerRequestInterface $request, ResponseInterface $response )
113
+	public function get(ServerRequestInterface $request, ResponseInterface $response)
114 114
 	{
115 115
 		/** admin/jsonadm/partials/catalog/template-data
116 116
 		 * Relative path to the data partial template file for the catalog client
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 		 * @since 2016.07
128 128
 		 * @category Developer
129 129
 		 */
130
-		$this->getView()->assign( array( 'partial-data' => 'admin/jsonadm/partials/catalog/template-data' ) );
130
+		$this->getView()->assign(array('partial-data' => 'admin/jsonadm/partials/catalog/template-data'));
131 131
 
132
-		return parent::get( $request, $response );
132
+		return parent::get($request, $response);
133 133
 	}
134 134
 
135 135
 
@@ -140,14 +140,14 @@  discard block
 block discarded – undo
140 140
 	 * @param array $include List of resource types that should be fetched
141 141
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface
142 142
 	 */
143
-	protected function getChildItems( array $items, array $include )
143
+	protected function getChildItems(array $items, array $include)
144 144
 	{
145 145
 		$list = [];
146 146
 
147
-		if( in_array( 'catalog', $include ) )
147
+		if (in_array('catalog', $include))
148 148
 		{
149
-			foreach( $items as $item ) {
150
-				$list = array_merge( $list, [$item], $this->getChildItems( $item->getChildren(), $include ) );
149
+			foreach ($items as $item) {
150
+				$list = array_merge($list, [$item], $this->getChildItems($item->getChildren(), $include));
151 151
 			}
152 152
 		}
153 153
 
@@ -162,40 +162,40 @@  discard block
 block discarded – undo
162 162
 	 * @param \Psr\Http\Message\ResponseInterface $response Response object
163 163
 	 * @return \Psr\Http\Message\ResponseInterface Modified response object
164 164
 	 */
165
-	protected function getItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response )
165
+	protected function getItems(\Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response)
166 166
 	{
167
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog' );
167
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog');
168 168
 
169
-		if( ( $key = $view->param( 'aggregate' ) ) !== null )
169
+		if (($key = $view->param('aggregate')) !== null)
170 170
 		{
171
-			$search = $this->initCriteria( $manager->createSearch(), $view->param() );
172
-			$view->data = $manager->aggregate( $search, $key );
171
+			$search = $this->initCriteria($manager->createSearch(), $view->param());
172
+			$view->data = $manager->aggregate($search, $key);
173 173
 			return $response;
174 174
 		}
175 175
 
176
-		$include = ( ( $include = $view->param( 'include' ) ) !== null ? explode( ',', $include ) : [] );
177
-		$search = $this->initCriteria( $manager->createSearch(), $view->param() );
176
+		$include = (($include = $view->param('include')) !== null ? explode(',', $include) : []);
177
+		$search = $this->initCriteria($manager->createSearch(), $view->param());
178 178
 		$total = 1;
179 179
 
180
-		if( ( $id = $view->param( 'id' ) ) == null )
180
+		if (($id = $view->param('id')) == null)
181 181
 		{
182
-			$view->data = $manager->searchItems( $search, [], $total );
183
-			$view->listItems = $this->getListItems( $view->data, $include );
182
+			$view->data = $manager->searchItems($search, [], $total);
183
+			$view->listItems = $this->getListItems($view->data, $include);
184 184
 			$view->childItems = [];
185 185
 		}
186 186
 		else
187 187
 		{
188 188
 			$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST;
189
-			if( in_array( 'catalog', $include ) ) {
189
+			if (in_array('catalog', $include)) {
190 190
 				$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE;
191 191
 			}
192 192
 
193
-			$view->data = $manager->getTree( $id, $include, $level, $search );
194
-			$view->listItems = $this->getListItems( array( $id => $view->data ), $include );
195
-			$view->childItems = $this->getChildItems( $view->data->getChildren(), $include );
193
+			$view->data = $manager->getTree($id, $include, $level, $search);
194
+			$view->listItems = $this->getListItems(array($id => $view->data), $include);
195
+			$view->childItems = $this->getChildItems($view->data->getChildren(), $include);
196 196
 		}
197 197
 
198
-		$view->refItems = $this->getRefItems( $view->listItems );
198
+		$view->refItems = $this->getRefItems($view->listItems);
199 199
 		$view->total = $total;
200 200
 
201 201
 		return $response;
@@ -209,18 +209,18 @@  discard block
 block discarded – undo
209 209
 	 * @param array $include List of resource types that should be fetched
210 210
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface
211 211
 	 */
212
-	protected function getListItems( array $items, array $include )
212
+	protected function getListItems(array $items, array $include)
213 213
 	{
214
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' );
214
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists');
215 215
 
216 216
 		$search = $manager->createSearch();
217 217
 		$expr = array(
218
-			$search->compare( '==', 'catalog.lists.parentid', array_keys( $items ) ),
219
-			$search->compare( '==', 'catalog.lists.domain', $include ),
218
+			$search->compare('==', 'catalog.lists.parentid', array_keys($items)),
219
+			$search->compare('==', 'catalog.lists.domain', $include),
220 220
 		);
221
-		$search->setConditions( $search->combine( '&&', $expr ) );
221
+		$search->setConditions($search->combine('&&', $expr));
222 222
 
223
-		return $manager->searchItems( $search );
223
+		return $manager->searchItems($search);
224 224
 	}
225 225
 
226 226
 
@@ -231,32 +231,32 @@  discard block
 block discarded – undo
231 231
 	 * @param \stdClass $entry Object including "id" and "attributes" elements
232 232
 	 * @return \Aimeos\MShop\Common\Item\Iface New or updated item
233 233
 	 */
234
-	protected function saveEntry( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry )
234
+	protected function saveEntry(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry)
235 235
 	{
236
-		$targetId = ( isset( $entry->targetid ) ? $entry->targetid : null );
237
-		$refId = ( isset( $entry->refid ) ? $entry->refid : null );
236
+		$targetId = (isset($entry->targetid) ? $entry->targetid : null);
237
+		$refId = (isset($entry->refid) ? $entry->refid : null);
238 238
 
239
-		if( isset( $entry->id ) )
239
+		if (isset($entry->id))
240 240
 		{
241
-			$item = $manager->getItem( $entry->id );
242
-			$item = $this->addItemData( $manager, $item, $entry, $item->getResourceType() );
243
-			$item = $manager->saveItem( $item );
241
+			$item = $manager->getItem($entry->id);
242
+			$item = $this->addItemData($manager, $item, $entry, $item->getResourceType());
243
+			$item = $manager->saveItem($item);
244 244
 
245
-			if( isset( $entry->parentid ) && $targetId !== null ) {
246
-				$manager->moveItem( $item->getId(), $entry->parentid, $targetId, $refId );
245
+			if (isset($entry->parentid) && $targetId !== null) {
246
+				$manager->moveItem($item->getId(), $entry->parentid, $targetId, $refId);
247 247
 			}
248 248
 		}
249 249
 		else
250 250
 		{
251 251
 			$item = $manager->createItem();
252
-			$item = $this->addItemData( $manager, $item, $entry, $item->getResourceType() );
253
-			$manager->insertItem( $item, $targetId, $refId );
252
+			$item = $this->addItemData($manager, $item, $entry, $item->getResourceType());
253
+			$manager->insertItem($item, $targetId, $refId);
254 254
 		}
255 255
 
256
-		if( isset( $entry->relationships ) ) {
257
-			$this->saveRelationships( $manager, $item, $entry->relationships );
256
+		if (isset($entry->relationships)) {
257
+			$this->saveRelationships($manager, $item, $entry->relationships);
258 258
 		}
259 259
 
260
-		return $manager->getItem( $item->getId() );
260
+		return $manager->getItem($item->getId());
261 261
 	}
262 262
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -182,8 +182,7 @@  discard block
 block discarded – undo
182 182
 			$view->data = $manager->searchItems( $search, [], $total );
183 183
 			$view->listItems = $this->getListItems( $view->data, $include );
184 184
 			$view->childItems = [];
185
-		}
186
-		else
185
+		} else
187 186
 		{
188 187
 			$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST;
189 188
 			if( in_array( 'catalog', $include ) ) {
@@ -245,8 +244,7 @@  discard block
 block discarded – undo
245 244
 			if( isset( $entry->parentid ) && $targetId !== null ) {
246 245
 				$manager->moveItem( $item->getId(), $entry->parentid, $targetId, $refId );
247 246
 			}
248
-		}
249
-		else
247
+		} else
250 248
 		{
251 249
 			$item = $manager->createItem();
252 250
 			$item = $this->addItemData( $manager, $item, $entry, $item->getResourceType() );
Please login to merge, or discard this patch.
admin/jsonadm/tests/Admin/JsonAdm/Catalog/StandardTest.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 		$this->context = \TestHelperJadm::getContext();
23 23
 		$this->view = $this->context->getView();
24 24
 
25
-		$this->object = new \Aimeos\Admin\JsonAdm\Catalog\Standard( $this->context, $this->view, $templatePaths, 'catalog' );
25
+		$this->object = new \Aimeos\Admin\JsonAdm\Catalog\Standard($this->context, $this->view, $templatePaths, 'catalog');
26 26
 	}
27 27
 
28 28
 
@@ -30,142 +30,142 @@  discard block
 block discarded – undo
30 30
 	{
31 31
 		$params = array(
32 32
 			'filter' => array(
33
-				'==' => array( 'catalog.code' => 'cafe' )
33
+				'==' => array('catalog.code' => 'cafe')
34 34
 			),
35 35
 			'include' => 'text'
36 36
 		);
37
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
38
-		$this->view->addHelper( 'param', $helper );
37
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
38
+		$this->view->addHelper('param', $helper);
39 39
 
40
-		$response = $this->object->get( $this->view->request(), $this->view->response() );
41
-		$result = json_decode( (string) $response->getBody(), true );
40
+		$response = $this->object->get($this->view->request(), $this->view->response());
41
+		$result = json_decode((string) $response->getBody(), true);
42 42
 
43 43
 
44
-		$this->assertEquals( 200, $response->getStatusCode() );
45
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
44
+		$this->assertEquals(200, $response->getStatusCode());
45
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
46 46
 
47
-		$this->assertEquals( 1, $result['meta']['total'] );
48
-		$this->assertEquals( 1, count( $result['data'] ) );
49
-		$this->assertEquals( 'catalog', $result['data'][0]['type'] );
50
-		$this->assertEquals( 6, count( $result['data'][0]['relationships']['text'] ) );
51
-		$this->assertEquals( 6, count( $result['included'] ) );
47
+		$this->assertEquals(1, $result['meta']['total']);
48
+		$this->assertEquals(1, count($result['data']));
49
+		$this->assertEquals('catalog', $result['data'][0]['type']);
50
+		$this->assertEquals(6, count($result['data'][0]['relationships']['text']));
51
+		$this->assertEquals(6, count($result['included']));
52 52
 
53
-		$this->assertArrayNotHasKey( 'errors', $result );
53
+		$this->assertArrayNotHasKey('errors', $result);
54 54
 	}
55 55
 
56 56
 
57 57
 	public function testGetTree()
58 58
 	{
59 59
 		$params = array(
60
-			'id' => $this->getCatalogItem( 'root' )->getId(),
60
+			'id' => $this->getCatalogItem('root')->getId(),
61 61
 			'include' => 'catalog,text'
62 62
 		);
63
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
64
-		$this->view->addHelper( 'param', $helper );
63
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
64
+		$this->view->addHelper('param', $helper);
65 65
 
66
-		$response = $this->object->get( $this->view->request(), $this->view->response() );
67
-		$result = json_decode( (string) $response->getBody(), true );
66
+		$response = $this->object->get($this->view->request(), $this->view->response());
67
+		$result = json_decode((string) $response->getBody(), true);
68 68
 
69
-		$this->assertEquals( 200, $response->getStatusCode() );
70
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
69
+		$this->assertEquals(200, $response->getStatusCode());
70
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
71 71
 
72
-		$this->assertEquals( 1, $result['meta']['total'] );
73
-		$this->assertEquals( 'catalog', $result['data']['type'] );
74
-		$this->assertEquals( 2, count( $result['data']['relationships']['catalog'] ) );
75
-		$this->assertEquals( 7, count( $result['included'] ) );
72
+		$this->assertEquals(1, $result['meta']['total']);
73
+		$this->assertEquals('catalog', $result['data']['type']);
74
+		$this->assertEquals(2, count($result['data']['relationships']['catalog']));
75
+		$this->assertEquals(7, count($result['included']));
76 76
 
77
-		$this->assertArrayNotHasKey( 'errors', $result );
77
+		$this->assertArrayNotHasKey('errors', $result);
78 78
 	}
79 79
 
80 80
 
81 81
 	public function testPatch()
82 82
 	{
83
-		$stub = $this->getCatalogMock( array( 'getItem', 'moveItem', 'saveItem' ) );
83
+		$stub = $this->getCatalogMock(array('getItem', 'moveItem', 'saveItem'));
84 84
 
85
-		$stub->expects( $this->once() )->method( 'moveItem' );
86
-		$stub->expects( $this->once() )->method( 'saveItem' )
87
-			->will( $this->returnValue( $stub->createItem() ) );
88
-		$stub->expects( $this->exactly( 2 ) )->method( 'getItem' ) // 2x due to decorator
89
-			->will( $this->returnValue( $stub->createItem() ) );
85
+		$stub->expects($this->once())->method('moveItem');
86
+		$stub->expects($this->once())->method('saveItem')
87
+			->will($this->returnValue($stub->createItem()));
88
+		$stub->expects($this->exactly(2))->method('getItem') // 2x due to decorator
89
+			->will($this->returnValue($stub->createItem()));
90 90
 
91 91
 
92
-		$params = array( 'id' => '-1' );
93
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
94
-		$this->view->addHelper( 'param', $helper );
92
+		$params = array('id' => '-1');
93
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
94
+		$this->view->addHelper('param', $helper);
95 95
 
96 96
 		$body = '{"data": {"parentid": "1", "targetid": 2, "type": "catalog", "attributes": {"catalog.label": "test"}}}';
97
-		$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) );
97
+		$request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body));
98 98
 
99
-		$response = $this->object->patch( $request, $this->view->response() );
100
-		$result = json_decode( (string) $response->getBody(), true );
99
+		$response = $this->object->patch($request, $this->view->response());
100
+		$result = json_decode((string) $response->getBody(), true);
101 101
 
102 102
 
103
-		$this->assertEquals( 200, $response->getStatusCode() );
104
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
103
+		$this->assertEquals(200, $response->getStatusCode());
104
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
105 105
 
106
-		$this->assertEquals( 1, $result['meta']['total'] );
107
-		$this->assertArrayHasKey( 'data', $result );
108
-		$this->assertEquals( 'catalog', $result['data']['type'] );
106
+		$this->assertEquals(1, $result['meta']['total']);
107
+		$this->assertArrayHasKey('data', $result);
108
+		$this->assertEquals('catalog', $result['data']['type']);
109 109
 
110
-		$this->assertArrayNotHasKey( 'included', $result );
111
-		$this->assertArrayNotHasKey( 'errors', $result );
110
+		$this->assertArrayNotHasKey('included', $result);
111
+		$this->assertArrayNotHasKey('errors', $result);
112 112
 	}
113 113
 
114 114
 
115 115
 	public function testPost()
116 116
 	{
117
-		$stub = $this->getCatalogMock( array( 'getItem', 'insertItem' ) );
117
+		$stub = $this->getCatalogMock(array('getItem', 'insertItem'));
118 118
 
119
-		$stub->expects( $this->any() )->method( 'getItem' )
120
-			->will( $this->returnValue( $stub->createItem() ) );
121
-		$stub->expects( $this->once() )->method( 'insertItem' );
119
+		$stub->expects($this->any())->method('getItem')
120
+			->will($this->returnValue($stub->createItem()));
121
+		$stub->expects($this->once())->method('insertItem');
122 122
 
123 123
 
124 124
 		$body = '{"data": {"type": "catalog", "attributes": {"catalog.code": "test", "catalog.label": "Test catalog"}}}';
125
-		$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) );
125
+		$request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body));
126 126
 
127
-		$response = $this->object->post( $request, $this->view->response() );
128
-		$result = json_decode( (string) $response->getBody(), true );
127
+		$response = $this->object->post($request, $this->view->response());
128
+		$result = json_decode((string) $response->getBody(), true);
129 129
 
130 130
 
131
-		$this->assertEquals( 201, $response->getStatusCode() );
132
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
131
+		$this->assertEquals(201, $response->getStatusCode());
132
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
133 133
 
134
-		$this->assertEquals( 1, $result['meta']['total'] );
135
-		$this->assertArrayHasKey( 'data', $result );
136
-		$this->assertEquals( 'catalog', $result['data']['type'] );
134
+		$this->assertEquals(1, $result['meta']['total']);
135
+		$this->assertArrayHasKey('data', $result);
136
+		$this->assertEquals('catalog', $result['data']['type']);
137 137
 
138
-		$this->assertArrayNotHasKey( 'included', $result );
139
-		$this->assertArrayNotHasKey( 'errors', $result );
138
+		$this->assertArrayNotHasKey('included', $result);
139
+		$this->assertArrayNotHasKey('errors', $result);
140 140
 	}
141 141
 
142 142
 
143
-	protected function getCatalogItem( $code )
143
+	protected function getCatalogItem($code)
144 144
 	{
145
-		$manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( $this->context );
145
+		$manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager($this->context);
146 146
 		$search = $manager->createSearch();
147
-		$search->setConditions( $search->compare( '==', 'catalog.code', $code ) );
148
-		$items = $manager->searchItems( $search );
147
+		$search->setConditions($search->compare('==', 'catalog.code', $code));
148
+		$items = $manager->searchItems($search);
149 149
 
150
-		if( ( $item = reset( $items ) ) === false ) {
151
-			throw new \RuntimeException( sprintf( 'No catalog item with code "%1$s" found', $code ) );
150
+		if (($item = reset($items)) === false) {
151
+			throw new \RuntimeException(sprintf('No catalog item with code "%1$s" found', $code));
152 152
 		}
153 153
 
154 154
 		return $item;
155 155
 	}
156 156
 
157 157
 
158
-	protected function getCatalogMock( array $methods )
158
+	protected function getCatalogMock(array $methods)
159 159
 	{
160 160
 		$name = 'ClientJsonAdmStandard';
161
-		$this->context->getConfig()->set( 'mshop/catalog/manager/name', $name );
161
+		$this->context->getConfig()->set('mshop/catalog/manager/name', $name);
162 162
 
163
-		$stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Catalog\\Manager\\Standard' )
164
-			->setConstructorArgs( array( $this->context ) )
165
-			->setMethods( $methods )
163
+		$stub = $this->getMockBuilder('\\Aimeos\\MShop\\Catalog\\Manager\\Standard')
164
+			->setConstructorArgs(array($this->context))
165
+			->setMethods($methods)
166 166
 			->getMock();
167 167
 
168
-		\Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Catalog\\Manager\\' . $name, $stub );
168
+		\Aimeos\MShop\Product\Manager\Factory::injectManager('\\Aimeos\\MShop\\Catalog\\Manager\\' . $name, $stub);
169 169
 
170 170
 		return $stub;
171 171
 	}
Please login to merge, or discard this patch.