UserLoginPage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 86.36%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 54
ccs 19
cts 22
cp 0.8636
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A requireDefaultRecords() 0 18 3
A find_link() 0 4 2
A get_if_login_page_exists() 0 8 2
A canCreate() 0 3 1
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\ORM\DataObject;
6
use SilverStripe\ORM\DB;
7
8
/**
9
 * Class UserLoginPage
10
 *
11
 * @package user-management
12
 */
13
class UserLoginPage extends Page
14
{
15 1
    public function canCreate($member = null, $context = array())
16
    {
17 1
        return !self::get()->exists();
18
    }
19
20
    /**
21
     * Returns the link or the URLSegment to the account page on this site
22
     *
23
     * @param boolean $urlSegment Return the URLSegment only
24
     *
25
     * @return mixed
26
     */
27 1
    public static function find_link($urlSegment = false)
28
    {
29 1
        $page = self::get_if_login_page_exists();
30 1
        return ($urlSegment) ? $page->URLSegment : $page->Link();
31
    }
32
33
    /**
34
     * @return object
35
     */
36 1
    protected static function get_if_login_page_exists()
37
    {
38 1
        if ($page = DataObject::get_one(self::class)) {
39 1
            return $page;
40
        }
41
        user_error(_t(__CLASS__ . '.NoPage', 'No CustomerLoginPage was found. 
42
            Please create one in the CMS!'), E_USER_ERROR);
43
        return null; // just to keep static analysis happy
44
    }
45
    
46
    /**
47
     * This module always requires a page model.
48
     */
49 1
    public function requireDefaultRecords()
50
    {
51 1
        parent::requireDefaultRecords();
52 1
        if (!self::get()->exists() && $this->config()->create_default_pages) {
53
            /**
54
             * @var UserLoginPage $page
55
             */
56 1
            $page = self::create()->update(
57
                [
58 1
                'Title' => 'UserLogin',
59 1
                'URLSegment' => UserLoginPageController::config()->url_segment,
60 1
                'ShowInMenus' => 0,
61
                ]
62
            );
63 1
            $page->write();
64 1
            $page->publishSingle();
65 1
            $page->flushCache();
66 1
            DB::alteration_message('UserLoginPage page created', 'created');
67
        }
68
    }
69
}
70