Completed
Push — master ( e1eaf9...3b6dfb )
by Thanos
01:48
created

LiteralReturn   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A returnLiteral() 0 5 1
A handle() 0 11 2
A canHandle() 0 4 2
1
<?php
2
3
namespace Amock\MockMethod;
4
5
class LiteralReturn extends Handler
6
{
7
    public function handle(): bool
8
    {
9
        if (!$this->canHandle()) {
10
            return false;
11
        }
12
13
        $this->initialStub
14
            ->method($this->methodName)
15
            ->willReturn($this->returnLiteral());
16
17
        return true;
18
    }
19
20
    private function canHandle(): bool
21
    {
22
        return is_string($this->methodMockConfig)
23
            && substr($this->methodMockConfig, 0, 9) === '@literal:';
24
    }
25
26
    private function returnLiteral()
27
    {
28
        eval('$literal = ' . substr($this->methodMockConfig, 9) . ';');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
29
30
        return $literal;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $literal seems to be never defined.
Loading history...
31
    }
32
}
33