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

UserProfilePageController::init()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 3
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
namespace UserManagement\Page;
3
4
use PageController;
0 ignored issues
show
Bug introduced by
The type PageController 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\Member;
6
use SilverStripe\Security\Security;
7
use UserManagement\Forms\ProfileForm;
8
use SilverStripe\SiteConfig\SiteConfig;
9
10
/**
11
 * Class UserProfilePageController
12
 *
13
 * @package user-management
14
 */
15
class UserProfilePageController extends PageController
16
{
17
    private static $url_segment = 'my-profile';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
18
19
    private static $allowed_actions = array('ProfileForm');
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
20
21
    private $member = false;
22
23
24
    public function init()
25
    {
26
        parent::init();
27
28
        $this->member = Security::getCurrentUser();
29
30
        if (!$this->member or !$this->member->exists()) {
31
            $config = SiteConfig::current_site_config();
32
            if ($config->LoginUrl()->URLSegment) {
33
                return $this->redirect($config->LoginUrl()->URLSegment);
34
            }
35
        }
36
    }
37
38
    public function ProfileForm()
39
    {
40
        $form =  new ProfileForm($this, 'ProfileForm');
41
        if ($this->member) {
42
            $form->loadDataFrom($this->member);
0 ignored issues
show
Bug introduced by
$this->member of type true is incompatible with the type SilverStripe\ORM\DataObject|array expected by parameter $data of SilverStripe\Forms\Form::loadDataFrom(). ( Ignorable by Annotation )

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

42
            $form->loadDataFrom(/** @scrutinizer ignore-type */ $this->member);
Loading history...
43
        }
44
        return $form;
45
    }
46
}
47