Total Complexity | 97 |
Total Lines | 308 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like ScheduledScanModelNormalizer 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 ScheduledScanModelNormalizer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class ScheduledScanModelNormalizer 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\\ScheduledScanModel'; |
||
29 | } |
||
30 | |||
31 | public function supportsNormalization($data, $format = null) |
||
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\ScheduledScanModel(); |
||
42 | if (property_exists($data, 'LastExecutedScanTaskId')) { |
||
43 | $object->setLastExecutedScanTaskId($data->{'LastExecutedScanTaskId'}); |
||
44 | } |
||
45 | if (property_exists($data, 'LastExecutionError')) { |
||
46 | $object->setLastExecutionError($data->{'LastExecutionError'}); |
||
47 | } |
||
48 | if (property_exists($data, 'LastExecutionStatus')) { |
||
49 | $object->setLastExecutionStatus($data->{'LastExecutionStatus'}); |
||
50 | } |
||
51 | if (property_exists($data, 'TimeWindow')) { |
||
52 | $object->setTimeWindow($this->denormalizer->denormalize($data->{'TimeWindow'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ScanTimeWindowModel', 'json', $context)); |
||
53 | } |
||
54 | if (property_exists($data, 'Id')) { |
||
55 | $object->setId($data->{'Id'}); |
||
56 | } |
||
57 | if (property_exists($data, 'OccurencesCount')) { |
||
58 | $object->setOccurencesCount($data->{'OccurencesCount'}); |
||
59 | } |
||
60 | if (property_exists($data, 'Disabled')) { |
||
61 | $object->setDisabled($data->{'Disabled'}); |
||
62 | } |
||
63 | if (property_exists($data, 'EnableScheduling')) { |
||
64 | $object->setEnableScheduling($data->{'EnableScheduling'}); |
||
65 | } |
||
66 | if (property_exists($data, 'Name')) { |
||
67 | $object->setName($data->{'Name'}); |
||
68 | } |
||
69 | if (property_exists($data, 'NextExecutionTime')) { |
||
70 | $object->setNextExecutionTime($data->{'NextExecutionTime'}); |
||
71 | } |
||
72 | if (property_exists($data, 'ScanGroupId')) { |
||
73 | $object->setScanGroupId($data->{'ScanGroupId'}); |
||
74 | } |
||
75 | if (property_exists($data, 'ScanType')) { |
||
76 | $object->setScanType($data->{'ScanType'}); |
||
77 | } |
||
78 | if (property_exists($data, 'ScheduleRunType')) { |
||
79 | $object->setScheduleRunType($data->{'ScheduleRunType'}); |
||
80 | } |
||
81 | if (property_exists($data, 'CustomRecurrence')) { |
||
82 | $object->setCustomRecurrence($this->denormalizer->denormalize($data->{'CustomRecurrence'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ScheduledScanRecurrenceViewModel', 'json', $context)); |
||
83 | } |
||
84 | if (property_exists($data, 'IsTargetUrlRequired')) { |
||
85 | $object->setIsTargetUrlRequired($data->{'IsTargetUrlRequired'}); |
||
86 | } |
||
87 | if (property_exists($data, 'AdditionalWebsites')) { |
||
88 | $object->setAdditionalWebsites($this->denormalizer->denormalize($data->{'AdditionalWebsites'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\AdditionalWebsitesSettingModel', 'json', $context)); |
||
89 | } |
||
90 | if (property_exists($data, 'AgentGroupId')) { |
||
91 | $object->setAgentGroupId($data->{'AgentGroupId'}); |
||
92 | } |
||
93 | if (property_exists($data, 'AgentId')) { |
||
94 | $object->setAgentId($data->{'AgentId'}); |
||
95 | } |
||
96 | if (property_exists($data, 'BasicAuthenticationSetting')) { |
||
97 | $object->setBasicAuthenticationSetting($this->denormalizer->denormalize($data->{'BasicAuthenticationSetting'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\BasicAuthenticationSettingModel', 'json', $context)); |
||
98 | } |
||
99 | if (property_exists($data, 'CanEdit')) { |
||
100 | $object->setCanEdit($data->{'CanEdit'}); |
||
101 | } |
||
102 | if (property_exists($data, 'ClientCertificateAuthentication')) { |
||
103 | $object->setClientCertificateAuthentication($this->denormalizer->denormalize($data->{'ClientCertificateAuthentication'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ClientCertificateAuthenticationViewModel', 'json', $context)); |
||
104 | } |
||
105 | if (property_exists($data, 'Cookies')) { |
||
106 | $object->setCookies($data->{'Cookies'}); |
||
107 | } |
||
108 | if (property_exists($data, 'CrawlAndAttack')) { |
||
109 | $object->setCrawlAndAttack($data->{'CrawlAndAttack'}); |
||
110 | } |
||
111 | if (property_exists($data, 'CreateType')) { |
||
112 | $object->setCreateType($data->{'CreateType'}); |
||
113 | } |
||
114 | if (property_exists($data, 'FindAndFollowNewLinks')) { |
||
115 | $object->setFindAndFollowNewLinks($data->{'FindAndFollowNewLinks'}); |
||
116 | } |
||
117 | if (property_exists($data, 'FormAuthenticationSetting')) { |
||
118 | $object->setFormAuthenticationSetting($this->denormalizer->denormalize($data->{'FormAuthenticationSetting'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\FormAuthenticationSettingModel', 'json', $context)); |
||
119 | } |
||
120 | if (property_exists($data, 'HeaderAuthentication')) { |
||
121 | $object->setHeaderAuthentication($this->denormalizer->denormalize($data->{'HeaderAuthentication'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\HeaderAuthenticationModel', 'json', $context)); |
||
122 | } |
||
123 | if (property_exists($data, 'ImportedLinks')) { |
||
124 | $object->setImportedLinks($this->denormalizer->denormalize($data->{'ImportedLinks'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ImportedLinksSetting', 'json', $context)); |
||
125 | } |
||
126 | if (property_exists($data, 'IsMaxScanDurationEnabled')) { |
||
127 | $object->setIsMaxScanDurationEnabled($data->{'IsMaxScanDurationEnabled'}); |
||
128 | } |
||
129 | if (property_exists($data, 'IsPrimary')) { |
||
130 | $object->setIsPrimary($data->{'IsPrimary'}); |
||
131 | } |
||
132 | if (property_exists($data, 'IsShared')) { |
||
133 | $object->setIsShared($data->{'IsShared'}); |
||
134 | } |
||
135 | if (property_exists($data, 'MaxScanDuration')) { |
||
136 | $object->setMaxScanDuration($data->{'MaxScanDuration'}); |
||
137 | } |
||
138 | if (property_exists($data, 'PolicyId')) { |
||
139 | $object->setPolicyId($data->{'PolicyId'}); |
||
140 | } |
||
141 | if (property_exists($data, 'ProfileId')) { |
||
142 | $object->setProfileId($data->{'ProfileId'}); |
||
143 | } |
||
144 | if (property_exists($data, 'ProfileName')) { |
||
145 | $object->setProfileName($data->{'ProfileName'}); |
||
146 | } |
||
147 | if (property_exists($data, 'ReportPolicyId')) { |
||
148 | $object->setReportPolicyId($data->{'ReportPolicyId'}); |
||
149 | } |
||
150 | if (property_exists($data, 'SaveScanProfile')) { |
||
151 | $object->setSaveScanProfile($data->{'SaveScanProfile'}); |
||
152 | } |
||
153 | if (property_exists($data, 'ScopeSetting')) { |
||
154 | $object->setScopeSetting($this->denormalizer->denormalize($data->{'ScopeSetting'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ScopeSetting', 'json', $context)); |
||
155 | } |
||
156 | if (property_exists($data, 'SelectedAgents')) { |
||
157 | $values = []; |
||
158 | foreach ($data->{'SelectedAgents'} as $value) { |
||
159 | $values[] = $this->denormalizer->denormalize($value, 'Montross50\\NetsparkerCloud\\SDK\\Model\\AgentSelectionModel', 'json', $context); |
||
160 | } |
||
161 | $object->setSelectedAgents($values); |
||
162 | } |
||
163 | if (property_exists($data, 'SelectedScanProfileId')) { |
||
164 | $object->setSelectedScanProfileId($data->{'SelectedScanProfileId'}); |
||
165 | } |
||
166 | if (property_exists($data, 'SelectedScanProfileName')) { |
||
167 | $object->setSelectedScanProfileName($data->{'SelectedScanProfileName'}); |
||
168 | } |
||
169 | if (property_exists($data, 'TargetUrl')) { |
||
170 | $object->setTargetUrl($data->{'TargetUrl'}); |
||
171 | } |
||
172 | if (property_exists($data, 'UrlRewriteSetting')) { |
||
173 | $object->setUrlRewriteSetting($this->denormalizer->denormalize($data->{'UrlRewriteSetting'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\UrlRewriteSetting', 'json', $context)); |
||
174 | } |
||
175 | if (property_exists($data, 'UserId')) { |
||
176 | $object->setUserId($data->{'UserId'}); |
||
177 | } |
||
178 | if (property_exists($data, 'WebsiteGroupId')) { |
||
179 | $object->setWebsiteGroupId($data->{'WebsiteGroupId'}); |
||
180 | } |
||
181 | |||
182 | return $object; |
||
183 | } |
||
184 | |||
185 | public function normalize($object, $format = null, array $context = []) |
||
329 | } |
||
330 | } |
||
331 |