Code Duplication    Length = 49-49 lines in 3 locations

src/Request/Carts/Command/CartSetLocaleAction.php 1 location

@@ 18-66 (lines=49) @@
15
 * @method CartSetLocaleAction setAction(string $action = null)
16
 * @method string getLocale()
17
 */
18
class CartSetLocaleAction 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 CartSetLocaleAction
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

src/Request/Customers/Command/CustomerSetLocaleAction.php 1 location

@@ 18-66 (lines=49) @@
15
 * @method CustomerSetLocaleAction setAction(string $action = null)
16
 * @method string getLocale()
17
 */
18
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

src/Request/Orders/Command/OrderSetLocaleAction.php 1 location

@@ 18-66 (lines=49) @@
15
 * @method OrderSetLocaleAction setAction(string $action = null)
16
 * @method string getLocale()
17
 */
18
class OrderSetLocaleAction 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 OrderSetLocaleAction
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