Complex classes like Schema 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Schema, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class Schema implements \JsonSerializable, \ArrayAccess { |
||
| 14 | /** |
||
| 15 | * Trigger a notice when extraneous properties are encountered during validation. |
||
| 16 | */ |
||
| 17 | const VALIDATE_EXTRA_PROPERTY_NOTICE = 0x1; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Throw a ValidationException when extraneous properties are encountered during validation. |
||
| 21 | */ |
||
| 22 | const VALIDATE_EXTRA_PROPERTY_EXCEPTION = 0x2; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var array All the known types. |
||
| 26 | * |
||
| 27 | * If this is ever given some sort of public access then remove the static. |
||
| 28 | */ |
||
| 29 | private static $types = [ |
||
| 30 | 'array' => ['a'], |
||
| 31 | 'object' => ['o'], |
||
| 32 | 'integer' => ['i', 'int'], |
||
| 33 | 'string' => ['s', 'str'], |
||
| 34 | 'number' => ['f', 'float'], |
||
| 35 | 'boolean' => ['b', 'bool'], |
||
| 36 | 'timestamp' => ['ts'], |
||
| 37 | 'datetime' => ['dt'], |
||
| 38 | 'null' => ['n'] |
||
| 39 | ]; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string The regular expression to strictly determine if a string is a date. |
||
| 43 | */ |
||
| 44 | private static $DATE_REGEX = '`^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2})?)?`i'; |
||
| 45 | |||
| 46 | private $schema = []; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var int A bitwise combination of the various **Schema::FLAG_*** constants. |
||
| 50 | */ |
||
| 51 | private $flags = 0; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var array An array of callbacks that will filter data in the schema. |
||
| 55 | */ |
||
| 56 | private $filters = []; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var array An array of callbacks that will custom validate the schema. |
||
| 60 | */ |
||
| 61 | private $validators = []; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string|Validation The name of the class or an instance that will be cloned. |
||
| 65 | */ |
||
| 66 | private $validationClass = Validation::class; |
||
| 67 | |||
| 68 | |||
| 69 | /// Methods /// |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Initialize an instance of a new {@link Schema} class. |
||
| 73 | * |
||
| 74 | * @param array $schema The array schema to validate against. |
||
| 75 | */ |
||
| 76 | 191 | public function __construct($schema = []) { |
|
| 79 | |||
| 80 | /** |
||
| 81 | * Grab the schema's current description. |
||
| 82 | * |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | 1 | public function getDescription() { |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Set the description for the schema. |
||
| 91 | * |
||
| 92 | * @param string $description The new description. |
||
| 93 | * @throws \InvalidArgumentException Throws an exception when the provided description is not a string. |
||
| 94 | * @return Schema |
||
| 95 | */ |
||
| 96 | 2 | public function setDescription($description) { |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Get a schema field. |
||
| 108 | * |
||
| 109 | * @param string|array $path The JSON schema path of the field with parts separated by dots. |
||
| 110 | * @param mixed $default The value to return if the field isn't found. |
||
| 111 | * @return mixed Returns the field value or `$default`. |
||
| 112 | */ |
||
| 113 | 4 | public function getField($path, $default = null) { |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Set a schema field. |
||
| 133 | * |
||
| 134 | * @param string|array $path The JSON schema path of the field with parts separated by dots. |
||
| 135 | * @param mixed $value The new value. |
||
| 136 | * @return $this |
||
| 137 | */ |
||
| 138 | 3 | public function setField($path, $value) { |
|
| 161 | |||
| 162 | /** |
||
| 163 | * Get the ID for the schema. |
||
| 164 | * |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | 3 | public function getID() { |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Set the ID for the schema. |
||
| 173 | * |
||
| 174 | * @param string $id The new ID. |
||
| 175 | * @throws \InvalidArgumentException Throws an exception when the provided ID is not a string. |
||
| 176 | * @return Schema |
||
| 177 | */ |
||
| 178 | 1 | public function setID($id) { |
|
| 187 | |||
| 188 | /** |
||
| 189 | * Return the validation flags. |
||
| 190 | * |
||
| 191 | * @return int Returns a bitwise combination of flags. |
||
| 192 | */ |
||
| 193 | 1 | public function getFlags() { |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Set the validation flags. |
||
| 199 | * |
||
| 200 | * @param int $flags One or more of the **Schema::FLAG_*** constants. |
||
| 201 | * @return Schema Returns the current instance for fluent calls. |
||
| 202 | */ |
||
| 203 | 8 | public function setFlags($flags) { |
|
| 211 | |||
| 212 | /** |
||
| 213 | * Whether or not the schema has a flag (or combination of flags). |
||
| 214 | * |
||
| 215 | * @param int $flag One or more of the **Schema::VALIDATE_*** constants. |
||
| 216 | * @return bool Returns **true** if all of the flags are set or **false** otherwise. |
||
| 217 | */ |
||
| 218 | 18 | public function hasFlag($flag) { |
|
| 221 | |||
| 222 | /** |
||
| 223 | * Set a flag. |
||
| 224 | * |
||
| 225 | * @param int $flag One or more of the **Schema::VALIDATE_*** constants. |
||
| 226 | * @param bool $value Either true or false. |
||
| 227 | * @return $this |
||
| 228 | */ |
||
| 229 | 1 | public function setFlag($flag, $value) { |
|
| 237 | |||
| 238 | /** |
||
| 239 | * Merge a schema with this one. |
||
| 240 | * |
||
| 241 | * @param Schema $schema A scheme instance. Its parameters will be merged into the current instance. |
||
| 242 | * @return $this |
||
| 243 | */ |
||
| 244 | 3 | public function merge(Schema $schema) { |
|
| 248 | |||
| 249 | /** |
||
| 250 | * Add another schema to this one. |
||
| 251 | * |
||
| 252 | * Adding schemas together is analogous to array addition. When you add a schema it will only add missing information. |
||
| 253 | * |
||
| 254 | * @param Schema $schema The schema to add. |
||
| 255 | * @param bool $addProperties Whether to add properties that don't exist in this schema. |
||
| 256 | * @return $this |
||
| 257 | */ |
||
| 258 | 3 | public function add(Schema $schema, $addProperties = false) { |
|
| 262 | |||
| 263 | /** |
||
| 264 | * The internal implementation of schema merging. |
||
| 265 | * |
||
| 266 | * @param array &$target The target of the merge. |
||
| 267 | * @param array $source The source of the merge. |
||
| 268 | * @param bool $overwrite Whether or not to replace values. |
||
| 269 | * @param bool $addProperties Whether or not to add object properties to the target. |
||
| 270 | * @return array |
||
| 271 | */ |
||
| 272 | 6 | private function mergeInternal(array &$target, array $source, $overwrite = true, $addProperties = true) { |
|
| 324 | |||
| 325 | // public function overlay(Schema $schema ) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Returns the internal schema array. |
||
| 329 | * |
||
| 330 | * @return array |
||
| 331 | * @see Schema::jsonSerialize() |
||
| 332 | */ |
||
| 333 | 15 | public function getSchemaArray() { |
|
| 336 | |||
| 337 | /** |
||
| 338 | * Parse a short schema and return the associated schema. |
||
| 339 | * |
||
| 340 | * @param array $arr The schema array. |
||
| 341 | * @param mixed ...$args Constructor arguments for the schema instance. |
||
| 342 | * @return static Returns a new schema. |
||
| 343 | */ |
||
| 344 | 160 | public static function parse(array $arr, ...$args) { |
|
| 349 | |||
| 350 | /** |
||
| 351 | * Parse a schema in short form into a full schema array. |
||
| 352 | * |
||
| 353 | * @param array $arr The array to parse into a schema. |
||
| 354 | * @return array The full schema array. |
||
| 355 | * @throws \InvalidArgumentException Throws an exception when an item in the schema is invalid. |
||
| 356 | */ |
||
| 357 | 160 | protected function parseInternal(array $arr) { |
|
| 389 | |||
| 390 | /** |
||
| 391 | * Parse a schema node. |
||
| 392 | * |
||
| 393 | * @param array $node The node to parse. |
||
| 394 | * @param mixed $value Additional information from the node. |
||
| 395 | * @return array Returns a JSON schema compatible node. |
||
| 396 | */ |
||
| 397 | 154 | private function parseNode($node, $value = null) { |
|
| 447 | |||
| 448 | /** |
||
| 449 | * Parse the schema for an object's properties. |
||
| 450 | * |
||
| 451 | * @param array $arr An object property schema. |
||
| 452 | * @return array Returns a schema array suitable to be placed in the **properties** key of a schema. |
||
| 453 | */ |
||
| 454 | 99 | private function parseProperties(array $arr) { |
|
| 480 | |||
| 481 | /** |
||
| 482 | * Parse a short parameter string into a full array parameter. |
||
| 483 | * |
||
| 484 | * @param string $key The short parameter string to parse. |
||
| 485 | * @param array $value An array of other information that might help resolve ambiguity. |
||
| 486 | * @return array Returns an array in the form `[string name, array param, bool required]`. |
||
| 487 | * @throws \InvalidArgumentException Throws an exception if the short param is not in the correct format. |
||
| 488 | */ |
||
| 489 | 154 | public function parseShortParam($key, $value = []) { |
|
| 547 | |||
| 548 | /** |
||
| 549 | * Add a custom filter to change data before validation. |
||
| 550 | * |
||
| 551 | * @param string $fieldname The name of the field to filter, if any. |
||
| 552 | * |
||
| 553 | * If you are adding a filter to a deeply nested field then separate the path with dots. |
||
| 554 | * @param callable $callback The callback to filter the field. |
||
| 555 | * @return $this |
||
| 556 | */ |
||
| 557 | 1 | public function addFilter($fieldname, callable $callback) { |
|
| 561 | |||
| 562 | /** |
||
| 563 | * Add a custom validator to to validate the schema. |
||
| 564 | * |
||
| 565 | * @param string $fieldname The name of the field to validate, if any. |
||
| 566 | * |
||
| 567 | * If you are adding a validator to a deeply nested field then separate the path with dots. |
||
| 568 | * @param callable $callback The callback to validate with. |
||
| 569 | * @return Schema Returns `$this` for fluent calls. |
||
| 570 | */ |
||
| 571 | 2 | public function addValidator($fieldname, callable $callback) { |
|
| 575 | |||
| 576 | /** |
||
| 577 | * Require one of a given set of fields in the schema. |
||
| 578 | * |
||
| 579 | * @param array $required The field names to require. |
||
| 580 | * @param string $fieldname The name of the field to attach to. |
||
| 581 | * @param int $count The count of required items. |
||
| 582 | * @return Schema Returns `$this` for fluent calls. |
||
| 583 | */ |
||
| 584 | 1 | public function requireOneOf(array $required, $fieldname = '', $count = 1) { |
|
| 633 | |||
| 634 | /** |
||
| 635 | * Validate data against the schema. |
||
| 636 | * |
||
| 637 | * @param mixed $data The data to validate. |
||
| 638 | * @param bool $sparse Whether or not this is a sparse validation. |
||
| 639 | * @return mixed Returns a cleaned version of the data. |
||
| 640 | * @throws ValidationException Throws an exception when the data does not validate against the schema. |
||
| 641 | */ |
||
| 642 | 155 | public function validate($data, $sparse = false) { |
|
| 658 | |||
| 659 | /** |
||
| 660 | * Validate data against the schema and return the result. |
||
| 661 | * |
||
| 662 | * @param mixed $data The data to validate. |
||
| 663 | * @param bool $sparse Whether or not to do a sparse validation. |
||
| 664 | * @return bool Returns true if the data is valid. False otherwise. |
||
| 665 | */ |
||
| 666 | 35 | public function isValid($data, $sparse = false) { |
|
| 674 | |||
| 675 | /** |
||
| 676 | * Validate a field. |
||
| 677 | * |
||
| 678 | * @param mixed $value The value to validate. |
||
| 679 | * @param ValidationField $field A validation object to add errors to. |
||
| 680 | * @param bool $sparse Whether or not this is a sparse validation. |
||
| 681 | * @return mixed|Invalid Returns a clean version of the value with all extra fields stripped out or invalid if the value |
||
| 682 | * is completely invalid. |
||
| 683 | */ |
||
| 684 | 155 | protected function validateField($value, ValidationField $field, $sparse = false) { |
|
| 716 | |||
| 717 | /** |
||
| 718 | * Validate an array. |
||
| 719 | * |
||
| 720 | * @param mixed $value The value to validate. |
||
| 721 | * @param ValidationField $field The validation results to add. |
||
| 722 | * @param bool $sparse Whether or not this is a sparse validation. |
||
| 723 | * @return array|Invalid Returns an array or invalid if validation fails. |
||
| 724 | */ |
||
| 725 | 27 | protected function validateArray($value, ValidationField $field, $sparse = false) { |
|
| 780 | |||
| 781 | /** |
||
| 782 | * Validate a boolean value. |
||
| 783 | * |
||
| 784 | * @param mixed $value The value to validate. |
||
| 785 | * @param ValidationField $field The validation results to add. |
||
| 786 | * @return bool|Invalid Returns the cleaned value or invalid if validation fails. |
||
| 787 | */ |
||
| 788 | 25 | protected function validateBoolean($value, ValidationField $field) { |
|
| 797 | |||
| 798 | /** |
||
| 799 | * Validate a date time. |
||
| 800 | * |
||
| 801 | * @param mixed $value The value to validate. |
||
| 802 | * @param ValidationField $field The validation results to add. |
||
| 803 | * @return \DateTimeInterface|Invalid Returns the cleaned value or **null** if it isn't valid. |
||
| 804 | */ |
||
| 805 | 14 | protected function validateDatetime($value, ValidationField $field) { |
|
| 830 | |||
| 831 | /** |
||
| 832 | * Validate a float. |
||
| 833 | * |
||
| 834 | * @param mixed $value The value to validate. |
||
| 835 | * @param ValidationField $field The validation results to add. |
||
| 836 | * @return float|Invalid Returns a number or **null** if validation fails. |
||
| 837 | */ |
||
| 838 | 13 | protected function validateNumber($value, ValidationField $field) { |
|
| 846 | /** |
||
| 847 | * Validate and integer. |
||
| 848 | * |
||
| 849 | * @param mixed $value The value to validate. |
||
| 850 | * @param ValidationField $field The validation results to add. |
||
| 851 | * @return int|Invalid Returns the cleaned value or **null** if validation fails. |
||
| 852 | */ |
||
| 853 | 33 | protected function validateInteger($value, ValidationField $field) { |
|
| 862 | |||
| 863 | /** |
||
| 864 | * Validate an object. |
||
| 865 | * |
||
| 866 | * @param mixed $value The value to validate. |
||
| 867 | * @param ValidationField $field The validation results to add. |
||
| 868 | * @param bool $sparse Whether or not this is a sparse validation. |
||
| 869 | * @return object|Invalid Returns a clean object or **null** if validation fails. |
||
| 870 | */ |
||
| 871 | 88 | protected function validateObject($value, ValidationField $field, $sparse = false) { |
|
| 883 | |||
| 884 | /** |
||
| 885 | * Validate data against the schema and return the result. |
||
| 886 | * |
||
| 887 | * @param array|\ArrayAccess $data The data to validate. |
||
| 888 | * @param ValidationField $field This argument will be filled with the validation result. |
||
| 889 | * @param bool $sparse Whether or not this is a sparse validation. |
||
| 890 | * @return array|Invalid Returns a clean array with only the appropriate properties and the data coerced to proper types. |
||
| 891 | * or invalid if there are no valid properties. |
||
| 892 | */ |
||
| 893 | 86 | protected function validateProperties($data, ValidationField $field, $sparse = false) { |
|
| 958 | |||
| 959 | /** |
||
| 960 | * Validate a string. |
||
| 961 | * |
||
| 962 | * @param mixed $value The value to validate. |
||
| 963 | * @param ValidationField $field The validation results to add. |
||
| 964 | * @return string|Invalid Returns the valid string or **null** if validation fails. |
||
| 965 | */ |
||
| 966 | 60 | protected function validateString($value, ValidationField $field) { |
|
| 1055 | |||
| 1056 | /** |
||
| 1057 | * Validate a unix timestamp. |
||
| 1058 | * |
||
| 1059 | * @param mixed $value The value to validate. |
||
| 1060 | * @param ValidationField $field The field being validated. |
||
| 1061 | * @return int|Invalid Returns a valid timestamp or invalid if the value doesn't validate. |
||
| 1062 | */ |
||
| 1063 | 8 | protected function validateTimestamp($value, ValidationField $field) { |
|
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Validate a null value. |
||
| 1077 | * |
||
| 1078 | * @param mixed $value The value to validate. |
||
| 1079 | * @param ValidationField $field The error collector for the field. |
||
| 1080 | * @return null|Invalid Returns **null** or invalid. |
||
| 1081 | */ |
||
| 1082 | protected function validateNull($value, ValidationField $field) { |
||
| 1089 | |||
| 1090 | /** |
||
| 1091 | * Validate a value against an enum. |
||
| 1092 | * |
||
| 1093 | * @param mixed $value The value to test. |
||
| 1094 | * @param ValidationField $field The validation object for adding errors. |
||
| 1095 | * @return mixed|Invalid Returns the value if it is one of the enumerated values or invalid otherwise. |
||
| 1096 | */ |
||
| 1097 | 153 | protected function validateEnum($value, ValidationField $field) { |
|
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Call all of the filters attached to a field. |
||
| 1119 | * |
||
| 1120 | * @param mixed $value The field value being filtered. |
||
| 1121 | * @param ValidationField $field The validation object. |
||
| 1122 | * @return mixed Returns the filtered value. If there are no filters for the field then the original value is returned. |
||
| 1123 | */ |
||
| 1124 | 155 | protected function callFilters($value, ValidationField $field) { |
|
| 1134 | |||
| 1135 | /** |
||
| 1136 | * Call all of the validators attached to a field. |
||
| 1137 | * |
||
| 1138 | * @param mixed $value The field value being validated. |
||
| 1139 | * @param ValidationField $field The validation object to add errors. |
||
| 1140 | */ |
||
| 1141 | 153 | protected function callValidators($value, ValidationField $field) { |
|
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Specify data which should be serialized to JSON. |
||
| 1164 | * |
||
| 1165 | * This method specifically returns data compatible with the JSON schema format. |
||
| 1166 | * |
||
| 1167 | * @return mixed Returns data which can be serialized by **json_encode()**, which is a value of any type other than a resource. |
||
| 1168 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
| 1169 | * @link http://json-schema.org/ |
||
| 1170 | */ |
||
| 1171 | public function jsonSerialize() { |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Look up a type based on its alias. |
||
| 1209 | * |
||
| 1210 | * @param string $alias The type alias or type name to lookup. |
||
| 1211 | * @return mixed |
||
| 1212 | */ |
||
| 1213 | 150 | protected function getType($alias) { |
|
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Get the class that's used to contain validation information. |
||
| 1227 | * |
||
| 1228 | * @return Validation|string Returns the validation class. |
||
| 1229 | */ |
||
| 1230 | 155 | public function getValidationClass() { |
|
| 1233 | |||
| 1234 | /** |
||
| 1235 | * Set the class that's used to contain validation information. |
||
| 1236 | * |
||
| 1237 | * @param Validation|string $class Either the name of a class or a class that will be cloned. |
||
| 1238 | * @return $this |
||
| 1239 | */ |
||
| 1240 | 1 | public function setValidationClass($class) { |
|
| 1248 | |||
| 1249 | /** |
||
| 1250 | * Create a new validation instance. |
||
| 1251 | * |
||
| 1252 | * @return Validation Returns a validation object. |
||
| 1253 | */ |
||
| 1254 | 155 | protected function createValidation() { |
|
| 1264 | |||
| 1265 | /** |
||
| 1266 | * Check whether or not a value is an array or accessible like an array. |
||
| 1267 | * |
||
| 1268 | * @param mixed $value The value to check. |
||
| 1269 | * @return bool Returns **true** if the value can be used like an array or **false** otherwise. |
||
| 1270 | */ |
||
| 1271 | 88 | private function isArray($value) { |
|
| 1274 | |||
| 1275 | /** |
||
| 1276 | * Cast a value to an array. |
||
| 1277 | * |
||
| 1278 | * @param \Traversable $value The value to convert. |
||
| 1279 | * @return array Returns an array. |
||
| 1280 | */ |
||
| 1281 | private function toArray(\Traversable $value) { |
||
| 1287 | |||
| 1288 | /** |
||
| 1289 | * Return a sparse version of this schema. |
||
| 1290 | * |
||
| 1291 | * A sparse schema has no required properties. |
||
| 1292 | * |
||
| 1293 | * @return Schema Returns a new sparse schema. |
||
| 1294 | */ |
||
| 1295 | 2 | public function withSparse() { |
|
| 1299 | |||
| 1300 | /** |
||
| 1301 | * The internal implementation of `Schema::withSparse()`. |
||
| 1302 | * |
||
| 1303 | * @param array|Schema $schema The schema to make sparse. |
||
| 1304 | * @param \SplObjectStorage $schemas Collected sparse schemas that have already been made. |
||
| 1305 | * @return mixed |
||
| 1306 | */ |
||
| 1307 | 2 | private function withSparseInternal($schema, \SplObjectStorage $schemas) { |
|
| 1335 | |||
| 1336 | /** |
||
| 1337 | * Filter a field's value using built in and custom filters. |
||
| 1338 | * |
||
| 1339 | * @param mixed $value The original value of the field. |
||
| 1340 | * @param ValidationField $field The field information for the field. |
||
| 1341 | * @return mixed Returns the filtered field or the original field value if there are no filters. |
||
| 1342 | */ |
||
| 1343 | 155 | private function filterField($value, ValidationField $field) { |
|
| 1367 | |||
| 1368 | /** |
||
| 1369 | * Whether a offset exists. |
||
| 1370 | * |
||
| 1371 | * @param mixed $offset An offset to check for. |
||
| 1372 | * @return boolean true on success or false on failure. |
||
| 1373 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
| 1374 | */ |
||
| 1375 | 3 | public function offsetExists($offset) { |
|
| 1378 | |||
| 1379 | /** |
||
| 1380 | * Offset to retrieve. |
||
| 1381 | * |
||
| 1382 | * @param mixed $offset The offset to retrieve. |
||
| 1383 | * @return mixed Can return all value types. |
||
| 1384 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
| 1385 | */ |
||
| 1386 | public function offsetGet($offset) { |
||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Offset to set. |
||
| 1392 | * |
||
| 1393 | * @param mixed $offset The offset to assign the value to. |
||
| 1394 | * @param mixed $value The value to set. |
||
| 1395 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
| 1396 | */ |
||
| 1397 | public function offsetSet($offset, $value) { |
||
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Offset to unset. |
||
| 1403 | * |
||
| 1404 | * @param mixed $offset The offset to unset. |
||
| 1405 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
| 1406 | */ |
||
| 1407 | public function offsetUnset($offset) { |
||
| 1410 | |||
| 1411 | /** |
||
| 1412 | * Validate a field against a single type. |
||
| 1413 | * |
||
| 1414 | * @param mixed $value The value to validate. |
||
| 1415 | * @param string $type The type to validate against. |
||
| 1416 | * @param ValidationField $field Contains field and validation information. |
||
| 1417 | * @param bool $sparse Whether or not this should be a sparse validation. |
||
| 1418 | * @return mixed Returns the valid value or `Invalid`. |
||
| 1419 | */ |
||
| 1420 | 155 | protected function validateSingleType($value, $type, ValidationField $field, $sparse) { |
|
| 1455 | |||
| 1456 | /** |
||
| 1457 | * Validate a field against multiple basic types. |
||
| 1458 | * |
||
| 1459 | * The first validation that passes will be returned. If no type can be validated against then validation will fail. |
||
| 1460 | * |
||
| 1461 | * @param mixed $value The value to validate. |
||
| 1462 | * @param string[] $types The types to validate against. |
||
| 1463 | * @param ValidationField $field Contains field and validation information. |
||
| 1464 | * @param bool $sparse Whether or not this should be a sparse validation. |
||
| 1465 | * @return mixed Returns the valid value or `Invalid`. |
||
| 1466 | */ |
||
| 1467 | 23 | private function validateMultipleTypes($value, array $types, ValidationField $field, $sparse) { |
|
| 1530 | } |
||
| 1531 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.