Completed
Push — fix/case-mismatch ( 41d4fe )
by Florian
05:11
created

MissingMethodErrorObserver::notify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace RMiller\PhpSpecExtension\ErrorObserver;
4
5
use RMiller\ErrorExtension\Observer\ErrorObserver;
6
use RMiller\PhpSpecExtension\Process\ExemplifyRunner;
7
8
class MissingMethodErrorObserver implements ErrorObserver
9
{
10
    private $exemplifyRunner;
11
12
    public function __construct(ExemplifyRunner $exemplifyRunner)
13
    {
14
        $this->exemplifyRunner = $exemplifyRunner;
15
    }
16
17
    public function notify(array $error)
18
    {
19
        if (strpos($error['message'], 'Call to undefined method') === false) {
20
            return;
21
        }
22
23
        $missing = trim(substr($error['message'], strlen('Call to undefined method')));
24
        list ($class, $method) = explode('::', $missing);
25
        $this->exemplifyRunner->runExemplifyCommand($class, substr($method, 0, -2));
26
    }
27
}
28