| Total Complexity | 4 | 
| Total Lines | 36 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | <?php | ||
| 4 | trait FileFieldsTrait | ||
| 5 | { | ||
| 6 | /** | ||
| 7 | * Get file fields for API query | ||
| 8 | * @param string $path file path | ||
| 9 | * @return array | ||
| 10 | */ | ||
| 11 | public function getFileFields($path) | ||
| 12 |     { | ||
| 13 |         if (!file_exists($path)) { | ||
| 14 |             throw new \RuntimeException(sprintf('File "%s" does not exist', $path)); | ||
| 15 | } | ||
| 16 | |||
| 17 | $content = file_get_contents($path); | ||
| 18 | |||
| 19 | return [ | ||
| 20 | 'name' => basename($path), | ||
| 21 | 'digest' => sha1($content), | ||
| 22 | 'content' => base64_encode($content) | ||
| 23 | ]; | ||
| 24 | } | ||
| 25 | |||
| 26 | /** | ||
| 27 | * Get multiple file fileds for API query by parsing list of file paths | ||
| 28 | * @param array $files file paths | ||
| 29 | * @return array | ||
| 30 | */ | ||
| 31 | public function getMultipleFileFields(array $files) | ||
| 40 | } | ||
| 41 | } | ||
| 42 |