ConditionCallback   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 7
c 2
b 1
f 1
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A isAllowed() 0 9 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Menu;
5
6
/**
7
 * ConditionCallback
8
 *
9
 * @author Jakub Konečný
10
 */
11 1
final class ConditionCallback extends BaseCondition {
12
  /**
13
   * @param callable $parameter
14
   * @throws \InvalidArgumentException
15
   * @throws \UnexpectedValueException
16
   */
17
  public function isAllowed($parameter = null): bool {
18 1
    if(!is_callable($parameter)) {
19 1
      throw new \InvalidArgumentException("Method " . __METHOD__ . " expects callback as parameter.");
20
    }
21 1
    $result = call_user_func($parameter);
1 ignored issue
show
Bug introduced by
It seems like $parameter can also be of type null; however, parameter $callback of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

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

21
    $result = call_user_func(/** @scrutinizer ignore-type */ $parameter);
Loading history...
22 1
    if(!is_bool($result)) {
23 1
      throw new \UnexpectedValueException("The callback for method " . __METHOD__ . " has to return boolean, " . gettype($result) . " returned.");
0 ignored issues
show
introduced by
Line exceeds 120 characters; contains 146 characters
Loading history...
24
    }
25 1
    return $result;
26
  }
27
}
28
?>