Conditions | 16 |
Paths | 14 |
Total Lines | 45 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
63 | private function validateByAttributes(array $object, $schemaId, $attributes, array $ignoreAttributes, ValidationResult $validationResult, $parentPath) |
||
64 | { |
||
65 | foreach ($object as $propertyName => $value) { |
||
66 | if (!$parentPath && isset(self::$commonAttributes[$propertyName])) { |
||
67 | // skip common resource attributes |
||
68 | continue; |
||
69 | } |
||
70 | if (!$parentPath && isset($ignoreAttributes[$propertyName])) { |
||
71 | continue; |
||
72 | } |
||
73 | |||
74 | $attribute = Helper::findAttribute($propertyName, $attributes); |
||
75 | if (!$attribute) { |
||
76 | $validationResult->add($propertyName, $parentPath, $schemaId, 'Attribute is not defined'); |
||
77 | continue; |
||
78 | } |
||
79 | |||
80 | if ($this->isArray($value)) { |
||
81 | if (!$attribute->isMultiValued()) { |
||
82 | $validationResult->add($propertyName, $parentPath, $schemaId, 'Attribute is not defined in schema as multi-valued, but got array'); |
||
83 | continue; |
||
84 | } else { |
||
85 | foreach ($value as $item) { |
||
86 | $this->validateByAttributes($item, $schemaId, $attribute->getSubAttributes(), [], $validationResult, $propertyName); |
||
87 | } |
||
88 | } |
||
89 | } elseif ($this->isObject($value)) { |
||
90 | if ($attribute->isMultiValued()) { |
||
91 | $validationResult->add($propertyName, $parentPath, $schemaId, 'Attribute is defined in schema as multi-valued, but got object'); |
||
92 | continue; |
||
93 | } elseif ($attribute->getType() !== ScimConstants::ATTRIBUTE_TYPE_COMPLEX) { |
||
94 | $validationResult->add($propertyName, $parentPath, $schemaId, 'Attribute is not defined in schema as complex, but got object'); |
||
95 | continue; |
||
96 | } |
||
97 | $this->validateByAttributes($value, $schemaId, $attribute->getSubAttributes(), [], $validationResult, $propertyName); |
||
98 | } else { |
||
99 | if ($attribute->isMultiValued()) { |
||
100 | $validationResult->add($propertyName, $parentPath, $schemaId, 'Attribute is defined in schema as multi-valued, but got scalar'); |
||
101 | continue; |
||
102 | } elseif ($attribute->getType() === ScimConstants::ATTRIBUTE_TYPE_COMPLEX) { |
||
103 | $validationResult->add($propertyName, $parentPath, $schemaId, 'Attribute is defined in schema as complex, but got scalar'); |
||
104 | continue; |
||
105 | } elseif (!$attribute->isValueValid($value)) { |
||
106 | $validationResult->add($propertyName, $parentPath, $schemaId, sprintf('Attribute has invalid value for type "%s"', $attribute->getType())); |
||
107 | continue; |
||
108 | } |
||
133 |