Issues (20)

src/Models/ShareToken.php (4 issues)

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