| Total Complexity | 44 |
| Total Lines | 276 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Attribute 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 Attribute, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Attribute implements SerializableInterface |
||
| 18 | { |
||
| 19 | /** @var string */ |
||
| 20 | protected $name; |
||
| 21 | |||
| 22 | /** @var string */ |
||
| 23 | protected $type; |
||
| 24 | |||
| 25 | /** @var bool */ |
||
| 26 | protected $multiValued = false; |
||
| 27 | |||
| 28 | /** @var bool */ |
||
| 29 | protected $required = false; |
||
| 30 | |||
| 31 | /** @var string */ |
||
| 32 | protected $description; |
||
| 33 | |||
| 34 | /** @var Attribute[] */ |
||
| 35 | protected $subAttributes = []; |
||
| 36 | |||
| 37 | /** @var string[] */ |
||
| 38 | protected $canonicalValues = []; |
||
| 39 | |||
| 40 | /** @var bool */ |
||
| 41 | protected $caseExact = false; |
||
| 42 | |||
| 43 | /** @var string */ |
||
| 44 | protected $mutability = ScimConstants::MUTABILITY_READ_WRITE; |
||
| 45 | |||
| 46 | /** @var string */ |
||
| 47 | protected $returned = ScimConstants::RETURNED_ALWAYS; |
||
| 48 | |||
| 49 | /** @var string */ |
||
| 50 | protected $uniqueness = ScimConstants::UNIQUENESS_NONE; |
||
| 51 | |||
| 52 | /** @var string[] */ |
||
| 53 | protected $referenceTypes = []; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $name |
||
| 57 | * @param string $type |
||
| 58 | * @param bool $multiValued |
||
| 59 | * @param bool $required |
||
| 60 | * @param string $description |
||
| 61 | * @param Attribute[] $subAttributes |
||
| 62 | * @param \string[] $canonicalValues |
||
| 63 | * @param bool $caseExact |
||
| 64 | * @param string $mutability |
||
| 65 | * @param string $returned |
||
| 66 | * @param string $uniqueness |
||
| 67 | * @param \string[] $referenceTypes |
||
| 68 | */ |
||
| 69 | public function __construct( |
||
| 70 | $name, |
||
| 71 | $type, |
||
| 72 | $multiValued, |
||
| 73 | $required, |
||
| 74 | $description, |
||
| 75 | array $subAttributes, |
||
| 76 | array $canonicalValues, |
||
| 77 | $caseExact, |
||
| 78 | $mutability, |
||
| 79 | $returned, |
||
| 80 | $uniqueness, |
||
| 81 | array $referenceTypes |
||
| 82 | ) { |
||
| 83 | $this->name = $name; |
||
| 84 | $this->type = $type; |
||
| 85 | $this->multiValued = $multiValued; |
||
| 86 | $this->required = $required; |
||
| 87 | $this->description = $description; |
||
| 88 | $this->subAttributes = $subAttributes; |
||
| 89 | $this->canonicalValues = $canonicalValues; |
||
| 90 | $this->caseExact = $caseExact; |
||
| 91 | $this->mutability = $mutability; |
||
| 92 | $this->returned = $returned; |
||
| 93 | $this->uniqueness = $uniqueness; |
||
| 94 | $this->referenceTypes = $referenceTypes === null ? [] : $referenceTypes; |
||
|
|
|||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @return string |
||
| 99 | */ |
||
| 100 | public function getName() |
||
| 101 | { |
||
| 102 | return $this->name; |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public function getType() |
||
| 109 | { |
||
| 110 | return $this->type; |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return bool |
||
| 115 | */ |
||
| 116 | public function isMultiValued() |
||
| 117 | { |
||
| 118 | return $this->multiValued; |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return bool |
||
| 123 | */ |
||
| 124 | public function isRequired() |
||
| 125 | { |
||
| 126 | return $this->required; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | public function getDescription() |
||
| 133 | { |
||
| 134 | return $this->description; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return Attribute[] |
||
| 139 | */ |
||
| 140 | public function getSubAttributes() |
||
| 141 | { |
||
| 142 | return $this->subAttributes; |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @return \string[] |
||
| 147 | */ |
||
| 148 | public function getCanonicalValues() |
||
| 149 | { |
||
| 150 | return $this->canonicalValues; |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @return bool |
||
| 155 | */ |
||
| 156 | public function isCaseExact() |
||
| 157 | { |
||
| 158 | return $this->caseExact; |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | public function getMutability() |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @return string |
||
| 171 | */ |
||
| 172 | public function getReturned() |
||
| 173 | { |
||
| 174 | return $this->returned; |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @return string |
||
| 179 | */ |
||
| 180 | public function getUniqueness() |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @return \string[] |
||
| 187 | */ |
||
| 188 | public function getReferenceTypes() |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @param string $name |
||
| 195 | * |
||
| 196 | * @return null|Attribute |
||
| 197 | */ |
||
| 198 | public function findAttribute($name) |
||
| 199 | { |
||
| 207 | } |
||
| 208 | |||
| 209 | public function isValueValid($value) |
||
| 222 | } |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @return array |
||
| 227 | */ |
||
| 228 | public function serializeObject() |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @param array $data |
||
| 266 | * |
||
| 267 | * @return Attribute |
||
| 268 | */ |
||
| 269 | public static function deserializeObject(array $data) |
||
| 295 |