Code Duplication    Length = 65-67 lines in 3 locations

Normalizer/Attribute/PimCatalogDateNormalizer.php 1 location

@@ 13-79 (lines=67) @@
10
 *
11
 * @package Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer
12
 */
13
class PimCatalogDateNormalizer implements NormalizerInterface
14
{
15
    /**
16
     * @param  object                                                $attribute
17
     * @param  null                                                  $format
18
     * @param  array                                                 $context
19
     * @return array|\Symfony\Component\Serializer\Normalizer\scalar
20
     */
21
    public function normalize($attribute, $format = null, array $context = [])
22
    {
23
        /**@var Attribute $attribute * */
24
        $normalizedAttribute = [
25
          'code'       => null,
26
          'type'       => null,
27
          'required'   => null,
28
          'labels'     => null,
29
          'parameters' => null,
30
        ];
31
32
        $availableLocales          = [];
33
        $attributeAvailableLocales = $attribute->getAvailableLocales();
34
        if (!is_null($attributeAvailableLocales)) {
35
            foreach ($attribute->getAvailableLocales() as $availableLocale) {
36
                $availableLocales [] = $availableLocale;
37
            }
38
        }
39
40
        $normalizedAttribute['required']   = $attribute->isRequired();
41
        $normalizedAttribute['type']       = $attribute->getAttributeType();
42
        $normalizedAttribute['code']       = $attribute->getCode();
43
        $normalizedAttribute['parameters'] = [
44
          'scope'             => $attribute->isScopable(),
45
          'localizable'       => $attribute->isLocalizable(),
46
          'unique'            => $attribute->isUnique(),
47
          'locale_specific'   => '',
48
          'available_locales' => $availableLocales,
49
          'default_value'     => null,
50
          'date_min'          => $attribute->getDateMin(),
51
          'date_max'          => $attribute->getDateMax(),
52
        ];
53
54
        if ($attribute->isLocalizable()) {
55
            foreach ($attribute->getTranslations() as $trans) {
56
                $normalizedAttribute['labels'][$trans->getLocale(
57
                )] = $trans->getLabel();
58
            }
59
        } else {
60
            $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel(
61
            );
62
        }
63
64
        return $normalizedAttribute;
65
    }
66
67
    /**
68
     * Checks whether the given class is supported for normalization by this normalizer
69
     *
70
     * @param mixed  $data   Data to normalize.
71
     * @param string $format The format being (de-)serialized from or into.
72
     *
73
     * @return boolean
74
     */
75
    public function supportsNormalization($data, $format = null)
76
    {
77
        return $data instanceof Attribute;
78
    }
79
}
80

Normalizer/Attribute/PimCatalogTextareaNormalizer.php 1 location

@@ 13-78 (lines=66) @@
10
 *
11
 * @package Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer
12
 */
13
class PimCatalogTextareaNormalizer implements NormalizerInterface
14
{
15
    /**
16
     * @param  object                                                $attribute
17
     * @param  null                                                  $format
18
     * @param  array                                                 $context
19
     * @return array|\Symfony\Component\Serializer\Normalizer\scalar
20
     */
21
    public function normalize($attribute, $format = null, array $context = [])
22
    {
23
        /**@var Attribute $attribute * */
24
        $normalizedAttribute       = [
25
          'code'       => null,
26
          'type'       => null,
27
          'required'   => null,
28
          'labels'     => null,
29
          'parameters' => null,
30
        ];
31
        $availableLocales          = [];
32
        $attributeAvailableLocales = $attribute->getAvailableLocales();
33
        if (!is_null($attributeAvailableLocales)) {
34
            foreach ($attribute->getAvailableLocales() as $availableLocale) {
35
                $availableLocales [] = $availableLocale;
36
            }
37
        }
38
39
        $normalizedAttribute['required']   = $attribute->isRequired();
40
        $normalizedAttribute['type']       = $attribute->getAttributeType();
41
        $normalizedAttribute['code']       = $attribute->getCode();
42
        $normalizedAttribute['parameters'] = [
43
          'scope'             => $attribute->isScopable(),
44
          'localizable'       => $attribute->isLocalizable(),
45
          'unique'            => $attribute->isUnique(),
46
          'available_locales' => $availableLocales,
47
          'default_value'     => null,
48
          'max_characters'    => $attribute->getMaxCharacters(),
49
          'wysiwyg' => $attribute->isWysiwygEnabled()
50
51
        ];
52
53
        if ($attribute->isLocalizable()) {
54
            foreach ($attribute->getTranslations() as $trans) {
55
                $normalizedAttribute['labels'][$trans->getLocale(
56
                )] = $trans->getLabel();
57
            }
58
        } else {
59
            $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel(
60
            );
61
        }
62
63
        return $normalizedAttribute;
64
    }
65
66
    /**
67
     * Checks whether the given class is supported for normalization by this normalizer
68
     *
69
     * @param mixed  $data   Data to normalize.
70
     * @param string $format The format being (de-)serialized from or into.
71
     *
72
     * @return boolean
73
     */
74
    public function supportsNormalization($data, $format = null)
75
    {
76
        return $data instanceof Attribute;
77
    }
78
}
79

Normalizer/Attribute/PimCatalogTextNormalizer.php 1 location

@@ 13-77 (lines=65) @@
10
 *
11
 * @package Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer
12
 */
13
class PimCatalogTextNormalizer implements NormalizerInterface
14
{
15
    /**
16
     * @param  object                                                $attribute
17
     * @param  null                                                  $format
18
     * @param  array                                                 $context
19
     * @return array|\Symfony\Component\Serializer\Normalizer\scalar
20
     */
21
    public function normalize($attribute, $format = null, array $context = [])
22
    {
23
        /**@var Attribute $attribute * */
24
        $normalizedAttribute       = [
25
          'code'       => null,
26
          'type'       => null,
27
          'required'   => null,
28
          'labels'     => null,
29
          'parameters' => null,
30
        ];
31
        $availableLocales          = [];
32
        $attributeAvailableLocales = $attribute->getAvailableLocales();
33
        if (!is_null($attributeAvailableLocales)) {
34
            foreach ($attribute->getAvailableLocales() as $availableLocale) {
35
                $availableLocales [] = $availableLocale;
36
            }
37
        }
38
39
        $normalizedAttribute['required']   = $attribute->isRequired();
40
        $normalizedAttribute['type']       = $attribute->getAttributeType();
41
        $normalizedAttribute['code']       = $attribute->getCode();
42
        $normalizedAttribute['parameters'] = [
43
          'scope'             => $attribute->isScopable(),
44
          'localizable'       => $attribute->isLocalizable(),
45
          'unique_value'      => $attribute->isUnique(),
46
          'available_locales' => $availableLocales,
47
          'default_value'     => null,
48
          'max_characters'    => $attribute->getMaxCharacters(),
49
          'validation_rule'   => $attribute->getValidationRule(),
50
        ];
51
52
        if ($attribute->isLocalizable()) {
53
            foreach ($attribute->getTranslations() as $trans) {
54
                $normalizedAttribute['labels'][$trans->getLocale(
55
                )] = $trans->getLabel();
56
            }
57
        } else {
58
            $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel(
59
            );
60
        }
61
62
        return $normalizedAttribute;
63
    }
64
65
    /**
66
     * Checks whether the given class is supported for normalization by this normalizer
67
     *
68
     * @param mixed  $data   Data to normalize.
69
     * @param string $format The format being (de-)serialized from or into.
70
     *
71
     * @return boolean
72
     */
73
    public function supportsNormalization($data, $format = null)
74
    {
75
        return $data instanceof Attribute;
76
    }
77
}
78