1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Request\Customers\Command; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\Context; |
9
|
|
|
use Commercetools\Core\Request\AbstractAction; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @package Commercetools\Core\Request\Customers\Command |
13
|
|
|
* |
14
|
|
|
* @method string getAction() |
15
|
|
|
* @method CustomerSetLocaleAction setAction(string $action = null) |
16
|
|
|
* @method string getLocale() |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
class CustomerSetLocaleAction extends AbstractAction |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
public function fieldDefinitions() |
21
|
|
|
{ |
22
|
|
|
return [ |
23
|
|
|
'action' => [static::TYPE => 'string'], |
24
|
|
|
'locale' => [static::TYPE => 'string'], |
25
|
|
|
]; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $locale |
30
|
|
|
* @param Context|callable $context |
31
|
|
|
* @return CustomerSetLocaleAction |
32
|
|
|
*/ |
33
|
|
|
public static function ofLocale($locale, $context = null) |
34
|
|
|
{ |
35
|
|
|
return static::of($context)->setLocale($locale); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param array $data |
40
|
|
|
* @param Context|callable $context |
41
|
|
|
*/ |
42
|
|
|
public function __construct(array $data = [], $context = null) |
43
|
|
|
{ |
44
|
|
|
parent::__construct($data, $context); |
45
|
|
|
$this->setAction('setLocale'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function setLocale($locale) |
49
|
|
|
{ |
50
|
|
|
$locale = \Locale::canonicalize($locale); |
51
|
|
|
parent::setLocale($locale); |
|
|
|
|
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function toJson() |
60
|
|
|
{ |
61
|
|
|
$data = parent::toArray(); |
|
|
|
|
62
|
|
|
$data['locale'] = str_replace('_', '-', $data['locale']); |
63
|
|
|
|
64
|
|
|
return $data; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.