MissingMethodErrorObserver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A notify() 0 11 2
1
<?php
2
3
namespace RMiller\BehatSpec\Extension\PhpSpecExtension\ErrorObserver;
4
5
use Behat\Testwork\Call\Exception\FatalThrowableError;
6
use RMiller\BehatSpec\Extension\ErrorExtension\Observer\ErrorObserver;
7
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\ExemplifyRunner;
8
9
class MissingMethodErrorObserver implements ErrorObserver
10
{
11
    private $exemplifyRunner;
12
13
    public function __construct(ExemplifyRunner $exemplifyRunner)
14
    {
15
        $this->exemplifyRunner = $exemplifyRunner;
16
    }
17
18
    public function notify(FatalThrowableError $error)
19
    {
20
        if (strpos($error->getMessage(), 'Call to undefined method') === false) {
21
            return;
22
        }
23
24
        $missing = trim(substr($error->getMessage(), strlen('Fatal error: Call to undefined method')));
25
        list($class, $method) = explode('::', $missing);
26
27
        $this->exemplifyRunner->runExemplifyCommand($class, substr($method, 0, -2));
28
    }
29
}
30