| Total Complexity | 7 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class FormData |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | private array $files = []; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * FromData constructor. |
||
| 22 | * |
||
| 23 | * @param string|array $file_path |
||
| 24 | */ |
||
| 25 | public function __construct(string|array $file_path = []) |
||
| 26 | { |
||
| 27 | if (is_string($file_path)) { |
||
|
|
|||
| 28 | $file_path = [$file_path]; |
||
| 29 | } |
||
| 30 | |||
| 31 | foreach ($file_path as $name => $path) { |
||
| 32 | $this->addFile($name, $path); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Get the field has passed through the class |
||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | public function getFiles(): array |
||
| 42 | { |
||
| 43 | return $this->files ?? []; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * This method will create an array with instances of CURLFile class |
||
| 48 | * |
||
| 49 | * @param string|array $file_path |
||
| 50 | * @return array |
||
| 51 | */ |
||
| 52 | public static function create(string|array $file_path): array |
||
| 53 | { |
||
| 54 | return (new FormData($file_path))->getFiles(); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param string $name |
||
| 59 | * @param string|\CURLFile $file |
||
| 60 | * @return $this |
||
| 61 | */ |
||
| 62 | public function addFile(string $name, string|\CURLFile $file): FormData |
||
| 76 | } |
||
| 77 | |||
| 78 | } |