Issues (35)

src/Traits/CMSNicetiesTraitForCanMethods.php (3 issues)

1
<?php
2
3
namespace Sunnysideup\CMSNiceties\Traits;
4
5
use SilverStripe\ORM\ArrayList;
6
use SilverStripe\Security\Permission;
7
use SilverStripe\Security\Security;
8
9
trait CMSNicetiesTraitForCanMethods
10
{
11
    public function canCreate($member = null, $context = [])
12
    {
13
        if (! $member) {
14
            $member = Security::getCurrentUser();
15
        }
16
17
        if ($this->hasMethod('canEditingOwnerObject')) {
0 ignored issues
show
It seems like hasMethod() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

17
        if ($this->/** @scrutinizer ignore-call */ hasMethod('canEditingOwnerObject')) {
Loading history...
18
            $obj = $this->canEditingOwnerObject();
0 ignored issues
show
The method canEditingOwnerObject() does not exist on Sunnysideup\CMSNiceties\...etiesTraitForCanMethods. Did you maybe mean canEdit()? ( Ignorable by Annotation )

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

18
            /** @scrutinizer ignore-call */ 
19
            $obj = $this->canEditingOwnerObject();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
            if ($obj instanceof ArrayList) {
20
                $outcome = true;
21
                foreach ($obj as $item) {
22
                    if (! $item->canCreate($member, $context)) {
23
                        $outcome = false;
24
25
                        break;
26
                    }
27
                }
28
29
                if ($outcome) {
30
                    return parent::canCreate($member, $context);
31
                }
32
33
                return false;
34
            }
35
36
            return $obj->canCreate($member, $context);
37
        }
38
39
        $groupCodes = $this->hasMethod('canEditingGroupsCodes') ? $this->canEditingGroupsCodes() : [
0 ignored issues
show
The method canEditingGroupsCodes() does not exist on Sunnysideup\CMSNiceties\...etiesTraitForCanMethods. Did you maybe mean canEdit()? ( Ignorable by Annotation )

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

39
        $groupCodes = $this->hasMethod('canEditingGroupsCodes') ? $this->/** @scrutinizer ignore-call */ canEditingGroupsCodes() : [

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
            'CMS_ACCESS_CMSMain',
41
        ];
42
        $groupCodes = array_merge(['ADMIN'], $groupCodes);
43
44
        foreach ($groupCodes as $groupCode) {
45
            if (Permission::checkMember($member, $groupCode)) {
46
                return parent::canCreate($member, $context);
47
            }
48
        }
49
50
        return false;
51
    }
52
53
    public function canEdit($member = null)
54
    {
55
        return $this->canCreate($member);
56
    }
57
58
    public function canDelete($member = null)
59
    {
60
        return $this->canCreate($member);
61
    }
62
}
63