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

MissingMethodErrorObserver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A notify() 0 10 2
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