DownloadsTrait::createForRecipient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace ByTIC\DocumentGenerator\PdfLetters\Models\Downloads;
4
5
use ByTIC\DocumentGenerator\PdfLetters\Models\PdfLetters\PdfLetterTrait;
6
use Nip\Records\Record;
7
use Nip\Records\Traits\AbstractTrait\RecordsTrait as AbstractRecordsTrait;
8
9
/**
10
 * Class DownloadsTrait
11
 * @package ByTIC\DocumentGenerator\PdfLetters\Models\Downloads
12
 *
13
 * @method DownloadTrait|Record getNew
14
 */
15
trait DownloadsTrait
16
{
17
    use AbstractRecordsTrait;
18
19
    /**
20
     * @param Record $recipient
21
     * @param PdfLetterTrait $letter
22
     */
23
    public function createForRecipient($recipient, $letter)
24
    {
25
        $download = $this->getNew();
26
        $download->populateFromLetter($letter);
27
        $download->populateFromRecipient($recipient);
28
        $download->datetime = date('Y-m-d H:i:s');
29
        $download->insert();
0 ignored issues
show
Bug introduced by
It seems like insert() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $download->/** @scrutinizer ignore-call */ 
30
                   insert();
Loading history...
30
    }
31
32
    /**
33
     * @param PdfLetterTrait $letter
34
     * @return bool
35
     */
36 1
    public function shouldTrackLetter($letter)
37
    {
38 1
        $issueDate = $letter->getIssueDate();
39 1
        $now = new \DateTime();
40 1
        $diff = $issueDate->diff($now);
41 1
        if ($diff->days < 60) {
42 1
            return true;
43
        }
44 1
        return false;
45
    }
46
}
47