Completed
Push — master ( ab21ee...9f62da )
by Jakub
01:59
created

ConditionCallback::isAllowed()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 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
class ConditionCallback extends BaseCondition {
12
  /**
13
   * @param callable $parameter
1 ignored issue
show
Documentation introduced by
Should the type for parameter $parameter not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
14
   * @throws \InvalidArgumentException
15
   * @throws \UnexpectedValueException
16
   */
17
  public function isAllowed($parameter = NULL): bool {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after closing parenthesis; found 0
Loading history...
18 1
    if(!is_callable($parameter)) {
19 1
      throw new \InvalidArgumentException("Method " . static::class . "::isAllowed expects callback as parameter.");
20
    }
21 1
    $result = call_user_func($parameter);
22 1
    if(!is_bool($result)) {
23 1
      throw new \UnexpectedValueException("The callback for method " . static::class . "::isAllowed has to return boolean, " . gettype($result) . " returned.");
24
    }
25 1
    return $result;
26
  }
27
}
28
?>