Passed
Push — master ( 36d94c...6f4de6 )
by Sathish
01:39
created

LostPasswordPage::requireDefaultRecords()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 2
nop 0
dl 0
loc 18
rs 9.9332
c 0
b 0
f 0
1
<?php
2
namespace UserManagement\Page;
3
4
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...
5
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator;
6
use SilverStripe\ORM\DB;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\Security\Member;
9
10
/**
11
 * Class LostPasswordPage
12
 *
13
 * @package user-management
14
 */
15
class LostPasswordPage extends Page
16
{
17
    private static $table_name = 'UserManagement_LostPasswordPage';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
18
19
    public function canCreate($member = null, $context = array())
20
    {
21
        return !self::get()->exists();
22
    }
23
24
    /**
25
     * Returns the link or the URLSegment to the lost password page on this site
26
     *
27
     * @param boolean $urlSegment Return the URLSegment only
28
     *
29
     * @return mixed
30
     */
31
    public static function find_link($urlSegment = false)
32
    {
33
        $page = self::get_if_forgot_password_page_exists();
34
        return ($urlSegment) ? $page->URLSegment : $page->Link();
35
    }
36
37
    /**
38
     * @return UserRegistrationPage
39
     */
40
    protected static function get_if_forgot_password_page_exists()
41
    {
42
        if ($page = DataObject::get_one(self::class)) {
43
            return $page;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $page returns the type SilverStripe\ORM\DataObject which is incompatible with the documented return type UserManagement\Page\UserRegistrationPage.
Loading history...
44
        }
45
        user_error(_t(__CLASS__ . '.NoPage', 'No LostPasswordPage was found.
46
            Please create one in the CMS!'), E_USER_ERROR);
47
        return null;
48
    }
49
    
50
    /**
51
     * This module always requires a page model.
52
     */
53
    public function requireDefaultRecords()
54
    {
55
        parent::requireDefaultRecords();
56
        if (!self::get()->exists() && $this->config()->create_default_pages) {
57
            /**
58
             * @var LostPasswordPage $page
59
             */
60
            $page = self::create()->update(
61
                [
62
                'Title' => 'Forgot Password',
63
                'URLSegment' => LostPasswordPageController::config()->url_segment,
64
                'ShowInMenus' => 0,
65
                ]
66
            );
67
            $page->write();
68
            $page->publishSingle();
69
            $page->flushCache();
70
            DB::alteration_message('LostPasswordPage page created', 'created');
71
        }
72
    }
73
}
74