Completed
Push — master ( 68f946...ae8931 )
by Leo
02:20
created

CustomBlockPermission::canConfigPageAndType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php 
2
3
class CustomBlockPermission extends DataExtension implements PermissionProvider {
4
	public function canConfigPageAndType($member = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
5
		return Permission::check(get_class($this->owner) . '_config_page_and_type');
6
	}
7
	
8
	public function canConfigMemberVisibility($member = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
9
		return Permission::check(get_class($this->owner) . '_config_member_visibility');
10
	}
11
	
12
	public function providePermissions() {
13
		$permissions = array();
14
		foreach ($this->getClassList() as $class) {
15
			foreach (array(
16
				'config_page_and_type',
17
				'config_member_visibility'
18
			) as $name) {
19
				$permissions[$class . '_' . $name] = $class . '_' . $name;
20
			}
21
		}
22
		return $permissions;
23
	}
24
	
25
	private function getClassList() {
26
		$classes = array();
27
		foreach (ClassInfo::subclassesFor('DataObject') as $class => $file) {
0 ignored issues
show
Bug introduced by
The expression \ClassInfo::subclassesFor('DataObject') of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
28
			$extensions = Config::inst()->get($class, 'extensions');
29
			if (!is_null($extensions)) {
30
				if (in_array(get_class($this), $extensions)) {
31
					$classes[] = $class;
32
				}
33
			}
34
		}
35
		return $classes;
36
	}
37
}