| Conditions | 5 |
| Paths | 12 |
| Total Lines | 28 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function IsUploadSportValid($sport, &$file) { |
||
| 20 | $valid = true; |
||
| 21 | $errors = array(); |
||
| 22 | $sports = $this->app['phpdraft.DraftDataRepository']->GetSports(); |
||
| 23 | |||
| 24 | if (empty($sport)) { |
||
| 25 | $errors[] = "One or more missing fields."; |
||
| 26 | $valid = false; |
||
| 27 | } |
||
| 28 | |||
| 29 | if (!array_key_exists($sport, $sports)) { |
||
| 30 | $errors[] = "Sport $sport is an invalid value."; |
||
| 31 | $valid = false; |
||
| 32 | } |
||
| 33 | |||
| 34 | if (!isset($file)) { |
||
| 35 | $valid = false; |
||
| 36 | $errors[] = "Must upload a CSV file"; |
||
| 37 | } else { |
||
| 38 | $fileErrorCode = $file->getError(); |
||
| 39 | |||
| 40 | if ($fileErrorCode > 0) { |
||
| 41 | $valid = false; |
||
| 42 | $errors[] = "Upload error - " . $fileErrorCode; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | return new PhpDraftResponse($valid, $errors); |
||
| 47 | } |
||
| 48 | } |