ProPlayerValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 21
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A IsUploadSportValid() 0 28 5
1
<?php
2
namespace PhpDraft\Domain\Validators;
3
4
use \Silex\Application;
5
use Symfony\Component\HttpFoundation\Request;
6
use PhpDraft\Domain\Entities\Draft;
7
use PhpDraft\Domain\Entities\RoundTime;
8
use PhpDraft\Domain\Models\PhpDraftResponse;
9
use PhpDraft\Domain\Models\RoundTimeCreateModel;
10
11
class ProPlayerValidator {
12
  private $app;
13
14
  public function __construct(Application $app) {
15
    $this->app = $app;
16
  }
17
18
  //$file is an instance of Symfony\Component\HttpFoundation\File\UploadedFile
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
}