| Total Complexity | 79 |
| Total Lines | 272 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ScanPolicySettingApiModelNormalizer 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 ScanPolicySettingApiModelNormalizer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class ScanPolicySettingApiModelNormalizer 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\\ScanPolicySettingApiModel'; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function supportsNormalization($data, $format = null) |
||
| 32 | { |
||
| 33 | return $data instanceof \Montross50\NetsparkerCloud\SDK\Model\ScanPolicySettingApiModel; |
||
| 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\ScanPolicySettingApiModel(); |
||
| 42 | if (property_exists($data, 'IsReadonly')) { |
||
| 43 | $object->setIsReadonly($data->{'IsReadonly'}); |
||
| 44 | } |
||
| 45 | if (property_exists($data, 'Id')) { |
||
| 46 | $object->setId($data->{'Id'}); |
||
| 47 | } |
||
| 48 | if (property_exists($data, 'IsShared')) { |
||
| 49 | $object->setIsShared($data->{'IsShared'}); |
||
| 50 | } |
||
| 51 | if (property_exists($data, 'DesktopId')) { |
||
| 52 | $object->setDesktopId($data->{'DesktopId'}); |
||
| 53 | } |
||
| 54 | if (property_exists($data, 'AttackingSettings')) { |
||
| 55 | $object->setAttackingSettings($this->denormalizer->denormalize($data->{'AttackingSettings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\AttackingSettingModel', 'json', $context)); |
||
| 56 | } |
||
| 57 | if (property_exists($data, 'AutoCompleteSettings')) { |
||
| 58 | $values = []; |
||
| 59 | foreach ($data->{'AutoCompleteSettings'} as $value) { |
||
| 60 | $values[] = $this->denormalizer->denormalize($value, 'Montross50\\NetsparkerCloud\\SDK\\Model\\AutoCompleteSettingModel', 'json', $context); |
||
| 61 | } |
||
| 62 | $object->setAutoCompleteSettings($values); |
||
| 63 | } |
||
| 64 | if (property_exists($data, 'BruteForceSettings')) { |
||
| 65 | $object->setBruteForceSettings($this->denormalizer->denormalize($data->{'BruteForceSettings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\BruteForceSettingModel', 'json', $context)); |
||
| 66 | } |
||
| 67 | if (property_exists($data, 'CrawlingSettings')) { |
||
| 68 | $object->setCrawlingSettings($this->denormalizer->denormalize($data->{'CrawlingSettings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\CrawlingSettingModel', 'json', $context)); |
||
| 69 | } |
||
| 70 | if (property_exists($data, 'CsrfSettings')) { |
||
| 71 | $object->setCsrfSettings($this->denormalizer->denormalize($data->{'CsrfSettings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\CsrfSettingModel', 'json', $context)); |
||
| 72 | } |
||
| 73 | if (property_exists($data, 'Custom404Settings')) { |
||
| 74 | $object->setCustom404Settings($this->denormalizer->denormalize($data->{'Custom404Settings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\Custom404SettingModel', 'json', $context)); |
||
| 75 | } |
||
| 76 | if (property_exists($data, 'CustomHttpHeaderSettings')) { |
||
| 77 | $values_1 = []; |
||
| 78 | foreach ($data->{'CustomHttpHeaderSettings'} as $value_1) { |
||
| 79 | $values_1[] = $this->denormalizer->denormalize($value_1, 'Montross50\\NetsparkerCloud\\SDK\\Model\\CustomHttpHeaderSetting', 'json', $context); |
||
| 80 | } |
||
| 81 | $object->setCustomHttpHeaderSettings($values_1); |
||
| 82 | } |
||
| 83 | if (property_exists($data, 'Description')) { |
||
| 84 | $object->setDescription($data->{'Description'}); |
||
| 85 | } |
||
| 86 | if (property_exists($data, 'EnableKnowledgebase')) { |
||
| 87 | $object->setEnableKnowledgebase($data->{'EnableKnowledgebase'}); |
||
| 88 | } |
||
| 89 | if (property_exists($data, 'FormValueSettings')) { |
||
| 90 | $values_2 = []; |
||
| 91 | foreach ($data->{'FormValueSettings'} as $value_2) { |
||
| 92 | $values_2[] = $this->denormalizer->denormalize($value_2, 'Montross50\\NetsparkerCloud\\SDK\\Model\\FormValueSettingModel', 'json', $context); |
||
| 93 | } |
||
| 94 | $object->setFormValueSettings($values_2); |
||
| 95 | } |
||
| 96 | if (property_exists($data, 'HttpRequestSettings')) { |
||
| 97 | $object->setHttpRequestSettings($this->denormalizer->denormalize($data->{'HttpRequestSettings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\HttpRequestSettingModel', 'json', $context)); |
||
| 98 | } |
||
| 99 | if (property_exists($data, 'IgnoredEmailPatterns')) { |
||
| 100 | $values_3 = []; |
||
| 101 | foreach ($data->{'IgnoredEmailPatterns'} as $value_3) { |
||
| 102 | $values_3[] = $this->denormalizer->denormalize($value_3, 'Montross50\\NetsparkerCloud\\SDK\\Model\\EmailPatternSetting', 'json', $context); |
||
| 103 | } |
||
| 104 | $object->setIgnoredEmailPatterns($values_3); |
||
| 105 | } |
||
| 106 | if (property_exists($data, 'IgnorePatternSettings')) { |
||
| 107 | $values_4 = []; |
||
| 108 | foreach ($data->{'IgnorePatternSettings'} as $value_4) { |
||
| 109 | $values_4[] = $this->denormalizer->denormalize($value_4, 'Montross50\\NetsparkerCloud\\SDK\\Model\\IgnorePatternSettingModel', 'json', $context); |
||
| 110 | } |
||
| 111 | $object->setIgnorePatternSettings($values_4); |
||
| 112 | } |
||
| 113 | if (property_exists($data, 'JavaScriptSettings')) { |
||
| 114 | $object->setJavaScriptSettings($this->denormalizer->denormalize($data->{'JavaScriptSettings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\JavaScriptSettingsModel', 'json', $context)); |
||
| 115 | } |
||
| 116 | if (property_exists($data, 'Name')) { |
||
| 117 | $object->setName($data->{'Name'}); |
||
| 118 | } |
||
| 119 | if (property_exists($data, 'ProxySettings')) { |
||
| 120 | $object->setProxySettings($this->denormalizer->denormalize($data->{'ProxySettings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ProxySettingsModel', 'json', $context)); |
||
| 121 | } |
||
| 122 | if (property_exists($data, 'ScopeSettings')) { |
||
| 123 | $object->setScopeSettings($this->denormalizer->denormalize($data->{'ScopeSettings'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ScopeSettingModel', 'json', $context)); |
||
| 124 | } |
||
| 125 | if (property_exists($data, 'SecurityCheckGroups')) { |
||
| 126 | $values_5 = []; |
||
| 127 | foreach ($data->{'SecurityCheckGroups'} as $value_5) { |
||
| 128 | $values_5[] = $this->denormalizer->denormalize($value_5, 'Montross50\\NetsparkerCloud\\SDK\\Model\\SecurityCheckGroupModel', 'json', $context); |
||
| 129 | } |
||
| 130 | $object->setSecurityCheckGroups($values_5); |
||
| 131 | } |
||
| 132 | if (property_exists($data, 'SelectedGroups')) { |
||
| 133 | $values_6 = []; |
||
| 134 | foreach ($data->{'SelectedGroups'} as $value_6) { |
||
| 135 | $values_6[] = $value_6; |
||
| 136 | } |
||
| 137 | $object->setSelectedGroups($values_6); |
||
| 138 | } |
||
| 139 | if (property_exists($data, 'SensitiveKeywordSettings')) { |
||
| 140 | $values_7 = []; |
||
| 141 | foreach ($data->{'SensitiveKeywordSettings'} as $value_7) { |
||
| 142 | $values_7[] = $this->denormalizer->denormalize($value_7, 'Montross50\\NetsparkerCloud\\SDK\\Model\\SensitiveKeywordSettingModel', 'json', $context); |
||
| 143 | } |
||
| 144 | $object->setSensitiveKeywordSettings($values_7); |
||
| 145 | } |
||
| 146 | if (property_exists($data, 'SslTlsSettingModel')) { |
||
| 147 | $object->setSslTlsSettingModel($this->denormalizer->denormalize($data->{'SslTlsSettingModel'}, 'Montross50\\NetsparkerCloud\\SDK\\Model\\SslTlsSettingModel', 'json', $context)); |
||
| 148 | } |
||
| 149 | if (property_exists($data, 'WebStorageSettings')) { |
||
| 150 | $values_8 = []; |
||
| 151 | foreach ($data->{'WebStorageSettings'} as $value_8) { |
||
| 152 | $values_8[] = $this->denormalizer->denormalize($value_8, 'Montross50\\NetsparkerCloud\\SDK\\Model\\WebStorageSetting', 'json', $context); |
||
| 153 | } |
||
| 154 | $object->setWebStorageSettings($values_8); |
||
| 155 | } |
||
| 156 | if (property_exists($data, 'ExtensionSettings')) { |
||
| 157 | $values_9 = []; |
||
| 158 | foreach ($data->{'ExtensionSettings'} as $value_9) { |
||
| 159 | $values_9[] = $this->denormalizer->denormalize($value_9, 'Montross50\\NetsparkerCloud\\SDK\\Model\\ExtensionSettingModel', 'json', $context); |
||
| 160 | } |
||
| 161 | $object->setExtensionSettings($values_9); |
||
| 162 | } |
||
| 163 | |||
| 164 | return $object; |
||
| 165 | } |
||
| 166 | |||
| 167 | public function normalize($object, $format = null, array $context = []) |
||
| 293 | } |
||
| 294 | } |
||
| 295 |