Conditions | 11 |
Paths | 9 |
Total Lines | 28 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
41 | public function parseContextual($value) |
||
42 | { |
||
43 | if (is_null($value) && $this->isNullable()) { |
||
44 | return $value; |
||
45 | } |
||
46 | |||
47 | if (!is_string($value)) { |
||
48 | throw new SchemaAttributeParseException($this, "Provided value '$value' is not an string"); |
||
49 | } |
||
50 | |||
51 | if ($this->limit > 0 && strlen($value) > $this->limit) { |
||
52 | if (!$this->truncate) { |
||
53 | throw new SchemaAttributeParseException($this, "Provided value '$value' is exceeding the limit of {$this->limit} characters"); |
||
54 | } |
||
55 | |||
56 | $value = substr($value, 0, $this->limit); |
||
57 | } |
||
58 | |||
59 | $len = strlen($value); |
||
60 | if ($this->min > 0 && $len < $this->min) { |
||
61 | throw new SchemaAttributeParseException($this, "Provided value '$value' is shorter than the minimum of {$this->min} characters"); |
||
62 | } |
||
63 | |||
64 | if ($this->max > 0 && $len > $this->max) { |
||
65 | throw new SchemaAttributeParseException($this, "Provided value '$value' is longer than the maximum of {$this->max} characters"); |
||
66 | } |
||
67 | |||
68 | return $value; |
||
69 | } |
||
70 | } |