Total Complexity | 71 |
Total Lines | 240 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like NewScanTaskApiModelNormalizer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use NewScanTaskApiModelNormalizer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class NewScanTaskApiModelNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
||
22 | { |
||
23 | use DenormalizerAwareTrait; |
||
24 | use NormalizerAwareTrait; |
||
25 | |||
26 | public function supportsDenormalization($data, $type, $format = null) |
||
27 | { |
||
28 | return $type === 'Montross50\\NetsparkerCloud\\SDK\\Model\\NewScanTaskApiModel'; |
||
29 | } |
||
30 | |||
31 | public function supportsNormalization($data, $format = null) |
||
32 | { |
||
33 | return $data instanceof \Montross50\NetsparkerCloud\SDK\Model\NewScanTaskApiModel; |
||
34 | } |
||
35 | |||
36 | public function denormalize($data, $class, $format = null, array $context = []) |
||
37 | { |
||
38 | if (!is_object($data)) { |
||
39 | throw new InvalidArgumentException(); |
||
40 | } |
||
41 | $object = new \Montross50\NetsparkerCloud\SDK\Model\NewScanTaskApiModel(); |
||
42 | if (property_exists($data, 'TargetUri')) { |
||
43 | $object->setTargetUri($data->{'TargetUri'}); |
||
44 | } |
||
45 | if (property_exists($data, 'AdditionalWebsites')) { |
||
46 | $values = []; |
||
47 | foreach ($data->{'AdditionalWebsites'} as $value) { |
||
48 | $values[] = $this->denormalizer->denormalize($value, 'Montross50\\NetsparkerCloud\\SDK\\Model\\AdditionalWebsiteModel', 'json', $context); |
||
49 | } |
||
50 | $object->setAdditionalWebsites($values); |
||
51 | } |
||
52 | if (property_exists($data, 'BasicAuthenticationApiModel')) { |
||
53 | $object->setBasicAuthenticationApiModel($this->denormalizer->denormalize($data->{'BasicAuthenticationApiModel'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\BasicAuthenticationSettingModel', 'json', $context)); |
||
54 | } |
||
55 | if (property_exists($data, 'ClientCertificateAuthenticationSetting')) { |
||
56 | $object->setClientCertificateAuthenticationSetting($this->denormalizer->denormalize($data->{'ClientCertificateAuthenticationSetting'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ClientCertificateAuthenticationApiModel', 'json', $context)); |
||
57 | } |
||
58 | if (property_exists($data, 'Cookies')) { |
||
59 | $object->setCookies($data->{'Cookies'}); |
||
60 | } |
||
61 | if (property_exists($data, 'CrawlAndAttack')) { |
||
62 | $object->setCrawlAndAttack($data->{'CrawlAndAttack'}); |
||
63 | } |
||
64 | if (property_exists($data, 'EnableHeuristicChecksInCustomUrlRewrite')) { |
||
65 | $object->setEnableHeuristicChecksInCustomUrlRewrite($data->{'EnableHeuristicChecksInCustomUrlRewrite'}); |
||
66 | } |
||
67 | if (property_exists($data, 'ExcludedLinks')) { |
||
68 | $values_1 = []; |
||
69 | foreach ($data->{'ExcludedLinks'} as $value_1) { |
||
70 | $values_1[] = $this->denormalizer->denormalize($value_1, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ExcludedLinkModel', 'json', $context); |
||
71 | } |
||
72 | $object->setExcludedLinks($values_1); |
||
73 | } |
||
74 | if (property_exists($data, 'DisallowedHttpMethods')) { |
||
75 | $values_2 = []; |
||
76 | foreach ($data->{'DisallowedHttpMethods'} as $value_2) { |
||
77 | $values_2[] = $value_2; |
||
78 | } |
||
79 | $object->setDisallowedHttpMethods($values_2); |
||
80 | } |
||
81 | if (property_exists($data, 'ExcludeLinks')) { |
||
82 | $object->setExcludeLinks($data->{'ExcludeLinks'}); |
||
83 | } |
||
84 | if (property_exists($data, 'FindAndFollowNewLinks')) { |
||
85 | $object->setFindAndFollowNewLinks($data->{'FindAndFollowNewLinks'}); |
||
86 | } |
||
87 | if (property_exists($data, 'FormAuthenticationSettingModel')) { |
||
88 | $object->setFormAuthenticationSettingModel($this->denormalizer->denormalize($data->{'FormAuthenticationSettingModel'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\FormAuthenticationSettingModel', 'json', $context)); |
||
89 | } |
||
90 | if (property_exists($data, 'HeaderAuthentication')) { |
||
91 | $object->setHeaderAuthentication($this->denormalizer->denormalize($data->{'HeaderAuthentication'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\HeaderAuthenticationModel', 'json', $context)); |
||
92 | } |
||
93 | if (property_exists($data, 'ImportedLinks')) { |
||
94 | $values_3 = []; |
||
95 | foreach ($data->{'ImportedLinks'} as $value_3) { |
||
96 | $values_3[] = $value_3; |
||
97 | } |
||
98 | $object->setImportedLinks($values_3); |
||
99 | } |
||
100 | if (property_exists($data, 'ImportedFiles')) { |
||
101 | $values_4 = []; |
||
102 | foreach ($data->{'ImportedFiles'} as $value_4) { |
||
103 | $values_4[] = $this->denormalizer->denormalize($value_4, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ApiFileModel', 'json', $context); |
||
104 | } |
||
105 | $object->setImportedFiles($values_4); |
||
106 | } |
||
107 | if (property_exists($data, 'IsMaxScanDurationEnabled')) { |
||
108 | $object->setIsMaxScanDurationEnabled($data->{'IsMaxScanDurationEnabled'}); |
||
109 | } |
||
110 | if (property_exists($data, 'MaxDynamicSignatures')) { |
||
111 | $object->setMaxDynamicSignatures($data->{'MaxDynamicSignatures'}); |
||
112 | } |
||
113 | if (property_exists($data, 'MaxScanDuration')) { |
||
114 | $object->setMaxScanDuration($data->{'MaxScanDuration'}); |
||
115 | } |
||
116 | if (property_exists($data, 'PolicyId')) { |
||
117 | $object->setPolicyId($data->{'PolicyId'}); |
||
118 | } |
||
119 | if (property_exists($data, 'ReportPolicyId')) { |
||
120 | $object->setReportPolicyId($data->{'ReportPolicyId'}); |
||
121 | } |
||
122 | if (property_exists($data, 'Scope')) { |
||
123 | $object->setScope($data->{'Scope'}); |
||
124 | } |
||
125 | if (property_exists($data, 'SubPathMaxDynamicSignatures')) { |
||
126 | $object->setSubPathMaxDynamicSignatures($data->{'SubPathMaxDynamicSignatures'}); |
||
127 | } |
||
128 | if (property_exists($data, 'TimeWindow')) { |
||
129 | $object->setTimeWindow($this->denormalizer->denormalize($data->{'TimeWindow'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ScanTimeWindowModel', 'json', $context)); |
||
130 | } |
||
131 | if (property_exists($data, 'UrlRewriteAnalyzableExtensions')) { |
||
132 | $object->setUrlRewriteAnalyzableExtensions($data->{'UrlRewriteAnalyzableExtensions'}); |
||
133 | } |
||
134 | if (property_exists($data, 'UrlRewriteBlockSeparators')) { |
||
135 | $object->setUrlRewriteBlockSeparators($data->{'UrlRewriteBlockSeparators'}); |
||
136 | } |
||
137 | if (property_exists($data, 'UrlRewriteMode')) { |
||
138 | $object->setUrlRewriteMode($data->{'UrlRewriteMode'}); |
||
139 | } |
||
140 | if (property_exists($data, 'UrlRewriteRules')) { |
||
141 | $values_5 = []; |
||
142 | foreach ($data->{'UrlRewriteRules'} as $value_5) { |
||
143 | $values_5[] = $this->denormalizer->denormalize($value_5, 'Montross50\\NetsparkerCloud\\SDK\\Model\\UrlRewriteRuleModel', 'json', $context); |
||
144 | } |
||
145 | $object->setUrlRewriteRules($values_5); |
||
146 | } |
||
147 | |||
148 | return $object; |
||
149 | } |
||
150 | |||
151 | public function normalize($object, $format = null, array $context = []) |
||
261 | } |
||
262 | } |
||
263 |