Completed
Push — master ( 6b2914...49adce )
by Aimeos
06:12
created
src/Controller/Common/Product/Import/Csv/Cache/Stocktype/Standard.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
42 42
 	 */
43
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
43
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context)
44 44
 	{
45
-		parent::__construct( $context );
45
+		parent::__construct($context);
46 46
 
47
-		$manager = \Aimeos\MShop\Factory::createManager( $context, 'product/stock/type' );
47
+		$manager = \Aimeos\MShop\Factory::createManager($context, 'product/stock/type');
48 48
 		$search = $manager->createSearch();
49
-		$search->setSlice( 0, 1000 );
49
+		$search->setSlice(0, 1000);
50 50
 
51
-		foreach( $manager->searchItems( $search ) as $id => $item ) {
52
-			$this->types[ $item->getCode() ] = $id;
51
+		foreach ($manager->searchItems($search) as $id => $item) {
52
+			$this->types[$item->getCode()] = $id;
53 53
 		}
54 54
 	}
55 55
 
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	 * @param string|null $type Attribute type
62 62
 	 * @return string|null Stock type ID or null if not found
63 63
 	 */
64
-	public function get( $code, $type = null )
64
+	public function get($code, $type = null)
65 65
 	{
66
-		if( isset( $this->types[$code] ) ) {
66
+		if (isset($this->types[$code])) {
67 67
 			return $this->types[$code];
68 68
 		}
69 69
 	}
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @param \Aimeos\MShop\Common\Item\Iface $item Stock type object
76 76
 	 */
77
-	public function set( \Aimeos\MShop\Common\Item\Iface $item )
77
+	public function set(\Aimeos\MShop\Common\Item\Iface $item)
78 78
 	{
79
-		$this->types[ $item->getCode() ] = $item->getId();
79
+		$this->types[$item->getCode()] = $item->getId();
80 80
 	}
81 81
 }
82 82
\ No newline at end of file
Please login to merge, or discard this patch.
src/Controller/Common/Product/Import/Csv/Processor/Stock/Standard.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
 	 * @param array $mapping Associative list of field position in CSV as key and domain item key as value
43 43
 	 * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor
44 44
 	 */
45
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping,
46
-		\Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null )
45
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping,
46
+		\Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null)
47 47
 	{
48
-		parent::__construct( $context, $mapping, $object );
48
+		parent::__construct($context, $mapping, $object);
49 49
 
50
-		$this->cache = $this->getCache( 'stocktype' );
50
+		$this->cache = $this->getCache('stocktype');
51 51
 	}
52 52
 
53 53
 
@@ -58,53 +58,53 @@  discard block
 block discarded – undo
58 58
 	 * @param array $data List of CSV fields with position as key and data as value
59 59
 	 * @return array List of data which hasn't been imported
60 60
 	 */
61
-	public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data )
61
+	public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data)
62 62
 	{
63
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/stock' );
63
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/stock');
64 64
 		$manager->begin();
65 65
 
66 66
 		try
67 67
 		{
68
-			$map = $this->getMappedChunk( $data );
69
-			$items = $this->getStockItems( $product->getId() );
68
+			$map = $this->getMappedChunk($data);
69
+			$items = $this->getStockItems($product->getId());
70 70
 
71
-			foreach( $map as $pos => $list )
71
+			foreach ($map as $pos => $list)
72 72
 			{
73
-				if( !array_key_exists( 'product.stock.stocklevel', $list ) ) {
73
+				if (!array_key_exists('product.stock.stocklevel', $list)) {
74 74
 					continue;
75 75
 				}
76 76
 
77
-				$stockType = ( isset( $list['product.stock.type'] ) ? $list['product.stock.type'] : 'default' );
77
+				$stockType = (isset($list['product.stock.type']) ? $list['product.stock.type'] : 'default');
78 78
 
79
-				if( !isset( $list['product.stock.typeid'] ) ) {
80
-					$list['product.stock.typeid'] = $this->cache->get( $stockType );
79
+				if (!isset($list['product.stock.typeid'])) {
80
+					$list['product.stock.typeid'] = $this->cache->get($stockType);
81 81
 				}
82 82
 
83
-				if( isset( $list['product.stock.dateback'] ) && $list['product.stock.dateback'] === '' ) {
83
+				if (isset($list['product.stock.dateback']) && $list['product.stock.dateback'] === '') {
84 84
 					$list['product.stock.dateback'] = null;
85 85
 				}
86 86
 
87
-				if( $list['product.stock.stocklevel'] === '' ) {
87
+				if ($list['product.stock.stocklevel'] === '') {
88 88
 					$list['product.stock.stocklevel'] = null;
89 89
 				}
90 90
 
91 91
 				$list['product.stock.parentid'] = $product->getId();
92 92
 
93
-				if( ( $item = array_pop( $items ) ) === null ) {
93
+				if (($item = array_pop($items)) === null) {
94 94
 					$item = $manager->createItem();
95 95
 				}
96 96
 
97
-				$item->fromArray( $list );
98
-				$manager->saveItem( $item );
97
+				$item->fromArray($list);
98
+				$manager->saveItem($item);
99 99
 			}
100 100
 
101
-			$manager->deleteItems( array_keys( $items ) );
101
+			$manager->deleteItems(array_keys($items));
102 102
 
103
-			$remaining = $this->getObject()->process( $product, $data );
103
+			$remaining = $this->getObject()->process($product, $data);
104 104
 
105 105
 			$manager->commit();
106 106
 		}
107
-		catch( \Exception $e )
107
+		catch (\Exception $e)
108 108
 		{
109 109
 			$manager->rollback();
110 110
 			throw $e;
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
 	 * @param string $prodid Unique product ID
121 121
 	 * @return array Associative list of product stock items
122 122
 	 */
123
-	protected function getStockItems( $prodid )
123
+	protected function getStockItems($prodid)
124 124
 	{
125
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/stock' );
125
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/stock');
126 126
 
127 127
 		$search = $manager->createSearch();
128
-		$search->setConditions( $search->compare( '==', 'product.stock.parentid', $prodid ) );
128
+		$search->setConditions($search->compare('==', 'product.stock.parentid', $prodid));
129 129
 
130
-		return $manager->searchItems( $search );
130
+		return $manager->searchItems($search);
131 131
 	}
132 132
 }
Please login to merge, or discard this patch.
tests/Controller/Common/Product/Import/Csv/Cache/Warehouse/StandardTest.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,43 +14,43 @@
 block discarded – undo
14 14
 
15 15
 	protected function setUp()
16 16
 	{
17
-		\Aimeos\MShop\Factory::setCache( true );
17
+		\Aimeos\MShop\Factory::setCache(true);
18 18
 
19 19
 		$context = \TestHelperCntl::getContext();
20
-		$this->object = new \Aimeos\Controller\Common\Product\Import\Csv\Cache\Stocktype\Standard( $context );
20
+		$this->object = new \Aimeos\Controller\Common\Product\Import\Csv\Cache\Stocktype\Standard($context);
21 21
 	}
22 22
 
23 23
 
24 24
 	protected function tearDown()
25 25
 	{
26
-		\Aimeos\MShop\Factory::setCache( false );
26
+		\Aimeos\MShop\Factory::setCache(false);
27 27
 		\Aimeos\MShop\Factory::clear();
28 28
 	}
29 29
 
30 30
 
31 31
 	public function testGet()
32 32
 	{
33
-		$result = $this->object->get( 'default' );
33
+		$result = $this->object->get('default');
34 34
 
35
-		$this->assertNotEquals( null, $result );
35
+		$this->assertNotEquals(null, $result);
36 36
 	}
37 37
 
38 38
 
39 39
 	public function testGetUnknown()
40 40
 	{
41
-		$this->assertEquals( null, $this->object->get( 'cache-test' ) );
41
+		$this->assertEquals(null, $this->object->get('cache-test'));
42 42
 	}
43 43
 
44 44
 
45 45
 	public function testSet()
46 46
 	{
47
-		$item = \Aimeos\MShop\Factory::createManager( \TestHelperCntl::getContext(), 'product/stock/type' )->createItem();
48
-		$item->setCode( 'cache-test' );
49
-		$item->setId( 1 );
47
+		$item = \Aimeos\MShop\Factory::createManager(\TestHelperCntl::getContext(), 'product/stock/type')->createItem();
48
+		$item->setCode('cache-test');
49
+		$item->setId(1);
50 50
 
51
-		$this->object->set( $item );
52
-		$id = $this->object->get( 'cache-test' );
51
+		$this->object->set($item);
52
+		$id = $this->object->get('cache-test');
53 53
 
54
-		$this->assertEquals( $item->getId(), $id );
54
+		$this->assertEquals($item->getId(), $id);
55 55
 	}
56 56
 }
57 57
\ No newline at end of file
Please login to merge, or discard this patch.