Completed
Push — master ( 2fcfce...de1d77 )
by Robbie
11s
created

ShareToken::isExpired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ShareDraftContent\Models;
4
5
use Page;
0 ignored issues
show
Bug introduced by
The type Page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\ORM\FieldType\DBDatetime;
8
9
/**
10
 * @method Page Page()
11
 *
12
 * @property int $ValidForDays
13
 * @property string $Token
14
 */
15
class ShareToken extends DataObject
16
{
17
    /**
18
     * @var array
19
     */
20
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
21
        'Token' => 'Varchar(16)',
22
        'ValidForDays' => 'Int',
23
    );
24
25
    /**
26
     * @var array
27
     */
28
    private static $has_one = array(
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
29
        'Page' => Page::class
30
    );
31
32
    /**
33
     * @var string
34
     */
35
    private static $table_name = 'ShareToken';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
36
37
    /**
38
     * Determines whether the token is still valid (from days since it was created).
39
     *
40
     * @return bool
41
     */
42
    public function isExpired()
43
    {
44
        $createdSeconds = strtotime($this->Created);
45
46
        $validForSeconds = (int) $this->ValidForDays * 24 * 60 * 60;
47
48
        $nowSeconds = DBDatetime::now()->getTimestamp();
49
50
        return ($createdSeconds + $validForSeconds) <= $nowSeconds;
51
    }
52
}
53