MissingMethodErrorObserver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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