| Conditions | 5 | 
| Paths | 4 | 
| Total Lines | 20 | 
| Code Lines | 11 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | <?php | ||
| 50 | protected function takeScreenshot($imgName = null) | ||
| 51 |     { | ||
| 52 | $data = $this->screenshot(); | ||
| 53 |         if (empty($data)) { | ||
| 54 | return $this; | ||
| 55 | } | ||
| 56 | |||
| 57 |         if (empty($this->screenshotsDir) || !file_exists($this->screenshotsDir)) { | ||
| 58 | return $this; | ||
| 59 | } | ||
| 60 | |||
| 61 |         if (empty($imgName)) { | ||
| 62 | $imgName = count(glob($this->screenshotsDir . '/*.png')) + 1; | ||
| 63 | } | ||
| 64 | |||
| 65 | $path = $this->screenshotsDir . '/' . $imgName . '.png'; | ||
| 66 | file_put_contents($path, $data); | ||
| 67 | |||
| 68 | return $this; | ||
| 69 | } | ||
| 70 | |||
| 82 | 
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.