Completed
Pull Request — development (#673)
by Nick
12:54 queued 04:44
created

UploadFieldNotesDataProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 11 2
1
<?php
2
3
namespace Oc\FieldNotes\Form\DataProvider;
4
5
use Oc\FieldNotes\FieldNoteServiceInterface;
6
use Oc\FieldNotes\Form\UploadFieldNotesType;
7
use Oc\Util\DateUtil;
8
9
class UploadFieldNotesDataProvider
10
{
11
    /**
12
     * @var FieldNoteServiceInterface
0 ignored issues
show
introduced by
FieldNoteServiceInterface => \Oc\FieldNotes\FieldNoteServiceInterface
Loading history...
13
     */
14
    protected $fieldNoteService;
15
16
    /**
17
     * @var int
18
     */
19
    protected $userId;
20
21
    /**
22
     * UploadFieldNotesDataProvider constructor.
23
     *
24
     * @param FieldNoteServiceInterface $fieldNoteService
0 ignored issues
show
introduced by
FieldNoteServiceInterface => \Oc\FieldNotes\FieldNoteServiceInterface
Loading history...
25
     */
26
    public function __construct(FieldNoteServiceInterface $fieldNoteService)
27
    {
28
        $this->fieldNoteService = $fieldNoteService;
29
    }
30
31
    /**
32
     * @param int $userId
33
     *
34
     * @return array
35
     */
36
    public function getData($userId)
37
    {
38
        $date = $this->fieldNoteService->getLatestFieldNoteOrLogDate($userId);
39
        if ($date !== null) {
40
            $date = $date->format(DateUtil::DATE_FORMAT_MYSQL);
41
        }
42
43
        return [
44
            UploadFieldNotesType::FIELD_IGNORE_DATE => $date
45
        ];
46
    }
47
}
48