Completed
Push — master ( d28449...58c0cd )
by Aimeos
01:50
created
src/Aimeos/Shop/Command/AccountCommand.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -51,22 +51,22 @@  discard block
 block discarded – undo
51 51
 	 */
52 52
 	public function handle()
53 53
 	{
54
-		if( ( $code = $this->argument( 'email' ) ) === null ) {
55
-			$code = $this->ask( 'E-Mail' );
54
+		if (($code = $this->argument('email')) === null) {
55
+			$code = $this->ask('E-Mail');
56 56
 		}
57 57
 
58
-		if( ( $password = $this->option( 'password' ) ) === null ) {
59
-			$password = $this->secret( 'Password' );
58
+		if (($password = $this->option('password')) === null) {
59
+			$password = $this->secret('Password');
60 60
 		}
61 61
 
62
-		$context = $this->getLaravel()->make( 'Aimeos\Shop\Base\Context' )->get( false, 'command' );
63
-		$context->setEditor( 'aimeos:account' );
62
+		$context = $this->getLaravel()->make('Aimeos\Shop\Base\Context')->get(false, 'command');
63
+		$context->setEditor('aimeos:account');
64 64
 
65
-		$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' );
66
-		$localeItem = $localeManager->bootstrap( $this->argument( 'site' ), '', '', false );
67
-		$context->setLocale( $localeItem );
65
+		$localeManager = \Aimeos\MShop\Factory::createManager($context, 'locale');
66
+		$localeItem = $localeManager->bootstrap($this->argument('site'), '', '', false);
67
+		$context->setLocale($localeItem);
68 68
 
69
-		$this->addGroups( $context, $this->createCustomerItem( $context, $code, $password ) );
69
+		$this->addGroups($context, $this->createCustomerItem($context, $code, $password));
70 70
 	}
71 71
 
72 72
 
@@ -77,33 +77,33 @@  discard block
 block discarded – undo
77 77
 	 * @param string $userid Unique user ID
78 78
 	 * @param string $groupid Unique group ID
79 79
 	 */
80
-	protected function addListItem( \Aimeos\MShop\Context\Item\Iface $context, $userid, $groupid )
80
+	protected function addListItem(\Aimeos\MShop\Context\Item\Iface $context, $userid, $groupid)
81 81
 	{
82
-		$manager = \Aimeos\MShop\Factory::createManager( $context, 'customer/lists' );
83
-		$typeManager = \Aimeos\MShop\Factory::createManager( $context, 'customer/lists/type' );
82
+		$manager = \Aimeos\MShop\Factory::createManager($context, 'customer/lists');
83
+		$typeManager = \Aimeos\MShop\Factory::createManager($context, 'customer/lists/type');
84 84
 
85
-		$typeid = $typeManager->findItem( 'default', array(), 'customer/group' )->getId();
85
+		$typeid = $typeManager->findItem('default', array(), 'customer/group')->getId();
86 86
 
87 87
 		$search = $manager->createSearch();
88 88
 		$expr = array(
89
-			$search->compare( '==', 'customer.lists.parentid', $userid ),
90
-			$search->compare( '==', 'customer.lists.refid', $groupid ),
91
-			$search->compare( '==', 'customer.lists.domain', 'customer/group' ),
92
-			$search->compare( '==', 'customer.lists.typeid', $typeid ),
89
+			$search->compare('==', 'customer.lists.parentid', $userid),
90
+			$search->compare('==', 'customer.lists.refid', $groupid),
91
+			$search->compare('==', 'customer.lists.domain', 'customer/group'),
92
+			$search->compare('==', 'customer.lists.typeid', $typeid),
93 93
 		);
94
-		$search->setConditions( $search->combine( '&&', $expr ) );
95
-		$search->setSlice( 0, 1 );
94
+		$search->setConditions($search->combine('&&', $expr));
95
+		$search->setSlice(0, 1);
96 96
 
97
-		if( count( $manager->searchItems( $search ) ) === 0 )
97
+		if (count($manager->searchItems($search)) === 0)
98 98
 		{
99 99
 			$item = $manager->createItem();
100
-			$item->setDomain( 'customer/group' );
101
-			$item->setParentId( $userid );
102
-			$item->setTypeId( $typeid );
103
-			$item->setRefId( $groupid );
104
-			$item->setStatus( 1 );
100
+			$item->setDomain('customer/group');
101
+			$item->setParentId($userid);
102
+			$item->setTypeId($typeid);
103
+			$item->setRefId($groupid);
104
+			$item->setStatus(1);
105 105
 
106
-			$manager->saveItem( $item, false );
106
+			$manager->saveItem($item, false);
107 107
 		}
108 108
 	}
109 109
 
@@ -114,22 +114,22 @@  discard block
 block discarded – undo
114 114
 	 * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object
115 115
 	 * @param \Aimeos\MShop\Customer\Item\Iface $user Aimeos customer object
116 116
 	 */
117
-	protected function addGroups( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $user )
117
+	protected function addGroups(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $user)
118 118
 	{
119
-		if( $this->option( 'super' ) ) {
120
-			$this->addGroup( $context, $user, 'super' );
119
+		if ($this->option('super')) {
120
+			$this->addGroup($context, $user, 'super');
121 121
 		}
122 122
 
123
-		if( $this->option( 'admin' ) ) {
124
-			$this->addGroup( $context, $user, 'admin' );
123
+		if ($this->option('admin')) {
124
+			$this->addGroup($context, $user, 'admin');
125 125
 		}
126 126
 
127
-		if( $this->option( 'editor' ) ) {
128
-			$this->addGroup( $context, $user, 'editor' );
127
+		if ($this->option('editor')) {
128
+			$this->addGroup($context, $user, 'editor');
129 129
 		}
130 130
 
131
-		if( $this->option( 'api' ) ) {
132
-			$this->addGroup( $context, $user, 'api' );
131
+		if ($this->option('api')) {
132
+			$this->addGroup($context, $user, 'api');
133 133
 		}
134 134
 	}
135 135
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @param \Aimeos\MShop\Customer\Item\Iface $user Aimeos customer object
142 142
 	 * @param string $group Unique customer group code
143 143
 	 */
144
-	protected function addGroup( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $user, $group )
144
+	protected function addGroup(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $user, $group)
145 145
 	{
146 146
 		$msg = 'Add "%1$s" group to user "%2$s" for site "%3$s"';
147
-		$this->info( sprintf( $msg, $group, $user->getCode(), $this->argument( 'site' ) ) );
147
+		$this->info(sprintf($msg, $group, $user->getCode(), $this->argument('site')));
148 148
 
149
-		$groupItem = $this->getGroupItem( $context, $group );
150
-		$this->addListItem( $context, $user->getId(), $groupItem->getId() );
149
+		$groupItem = $this->getGroupItem($context, $group);
150
+		$this->addListItem($context, $user->getId(), $groupItem->getId());
151 151
 	}
152 152
 
153 153
 
@@ -161,23 +161,23 @@  discard block
 block discarded – undo
161 161
 	 * @param string $password New user password
162 162
 	 * @return \Aimeos\MShop\Customer\Item\Iface Aimeos customer item object
163 163
 	 */
164
-	protected function createCustomerItem( \Aimeos\MShop\Context\Item\Iface $context, $email, $password )
164
+	protected function createCustomerItem(\Aimeos\MShop\Context\Item\Iface $context, $email, $password)
165 165
 	{
166
-		$manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' );
166
+		$manager = \Aimeos\MShop\Factory::createManager($context, 'customer');
167 167
 
168 168
 		try {
169
-			$item = $manager->findItem( $email );
170
-		} catch( \Aimeos\MShop\Exception $e ) {
169
+			$item = $manager->findItem($email);
170
+		} catch (\Aimeos\MShop\Exception $e) {
171 171
 			$item = $manager->createItem();
172 172
 		}
173 173
 
174
-		$item->setCode( $email );
175
-		$item->setLabel( $email );
176
-		$item->getPaymentAddress()->setEmail( $email );
177
-		$item->setPassword( $password );
178
-		$item->setStatus( 1 );
174
+		$item->setCode($email);
175
+		$item->setLabel($email);
176
+		$item->getPaymentAddress()->setEmail($email);
177
+		$item->setPassword($password);
178
+		$item->setStatus(1);
179 179
 
180
-		$manager->saveItem( $item );
180
+		$manager->saveItem($item);
181 181
 
182 182
 		return $item;
183 183
 	}
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 	protected function getArguments()
192 192
 	{
193 193
 		return array(
194
-			array( 'email', InputArgument::REQUIRED, 'E-mail address of the account that should be created' ),
195
-			array( 'site', InputArgument::OPTIONAL, 'Site code to create the account for', 'default' ),
194
+			array('email', InputArgument::REQUIRED, 'E-mail address of the account that should be created'),
195
+			array('site', InputArgument::OPTIONAL, 'Site code to create the account for', 'default'),
196 196
 		);
197 197
 	}
198 198
 
@@ -204,21 +204,21 @@  discard block
 block discarded – undo
204 204
 	 * @param string $code Unique customer group code
205 205
 	 * @return \Aimeos\MShop\Customer\Item\Group\Iface Aimeos customer group item object
206 206
 	 */
207
-	protected function getGroupItem( \Aimeos\MShop\Context\Item\Iface $context, $code )
207
+	protected function getGroupItem(\Aimeos\MShop\Context\Item\Iface $context, $code)
208 208
 	{
209
-		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $context )->getSubmanager( 'group' );
209
+		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager($context)->getSubmanager('group');
210 210
 
211 211
 		try
212 212
 		{
213
-			$item = $manager->findItem( $code );
213
+			$item = $manager->findItem($code);
214 214
 		}
215
-		catch( \Aimeos\MShop\Exception $e )
215
+		catch (\Aimeos\MShop\Exception $e)
216 216
 		{
217 217
 			$item = $manager->createItem();
218
-			$item->setLabel( $code );
219
-			$item->setCode( $code );
218
+			$item->setLabel($code);
219
+			$item->setCode($code);
220 220
 
221
-			$manager->saveItem( $item );
221
+			$manager->saveItem($item);
222 222
 		}
223 223
 
224 224
 		return $item;
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
 	protected function getOptions()
234 234
 	{
235 235
 		return array(
236
-			array( 'password', null, InputOption::VALUE_REQUIRED, 'Optional password for the account (will ask for if not given)' ),
237
-			array( 'admin', null, InputOption::VALUE_NONE, 'If account should have administrator privileges' ),
238
-			array( 'api', null, InputOption::VALUE_NONE, 'If account should be able to access the APIs' ),
239
-			array( 'editor', null, InputOption::VALUE_NONE, 'If account should have limited editor privileges' ),
240
-			array( 'viewer', null, InputOption::VALUE_NONE, 'If account should only have view privileges' ),
236
+			array('password', null, InputOption::VALUE_REQUIRED, 'Optional password for the account (will ask for if not given)'),
237
+			array('admin', null, InputOption::VALUE_NONE, 'If account should have administrator privileges'),
238
+			array('api', null, InputOption::VALUE_NONE, 'If account should be able to access the APIs'),
239
+			array('editor', null, InputOption::VALUE_NONE, 'If account should have limited editor privileges'),
240
+			array('viewer', null, InputOption::VALUE_NONE, 'If account should only have view privileges'),
241 241
 		);
242 242
 	}
243 243
 }
Please login to merge, or discard this patch.