| Conditions | 3 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 29 | 1 | public function write($string) |
|
| 30 | { |
||
| 31 | 1 | $diff = $this->maxLength - $this->stream->getSize(); |
|
| 32 | |||
| 33 | // Begin returning 0 when the underlying stream is too large. |
||
| 34 | 1 | if (0 >= $diff) { |
|
| 35 | 1 | return 0; |
|
| 36 | } |
||
| 37 | |||
| 38 | // Write the stream or a subset of the stream if needed. |
||
| 39 | 1 | if (strlen($string) < $diff) { |
|
| 40 | 1 | return $this->stream->write($string); |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | return $this->stream->write(substr($string, 0, $diff)); |
|
| 44 | } |
||
| 45 | } |
||
| 46 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: