Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
created

PHP   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 31
c 1
b 0
f 1
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 4
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace sebastianfeldmann\CaptainHook\Runner\Action;
11
12
use sebastianfeldmann\CaptainHook\Config;
13
use sebastianfeldmann\CaptainHook\Console\IO;
14
use sebastianfeldmann\CaptainHook\Exception\ActionExecution;
15
use sebastianfeldmann\CaptainHook\Git\Repository;
16
use sebastianfeldmann\CaptainHook\Hook\Action;
17
18
/**
19
 * Class PHP
20
 *
21
 * @package CaptainHook
22
 * @author  Sebastian Feldmann <[email protected]>
23
 * @link    https://github.com/sebastianfeldmann/captainhook
24
 * @since   Class available since Release 0.9.0
25
 */
26
class PHP implements Action
27
{
28
    /**
29
     * Execute the configured action.
30
     *
31
     * @param  \sebastianfeldmann\CaptainHook\Config         $config
32
     * @param  \sebastianfeldmann\CaptainHook\Console\IO     $io
33
     * @param  \sebastianfeldmann\CaptainHook\Git\Repository $repository
34
     * @param  \sebastianfeldmann\CaptainHook\Config\Action  $action
35
     * @throws \sebastianfeldmann\CaptainHook\Exception\ActionExecution
36
     */
37 4
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action)
38
    {
39 4
        $class = $action->getAction();
40
41
        try {
42
            /* @var \sebastianfeldmann\CaptainHook\Hook\Action $exe */
43 4
            $exe = new $class();
44
45 4
            if (!$exe instanceof Action) {
46 1
                throw new ActionExecution('PHP class ' . $class . ' has to implement the \'Action\' interface');
47
            }
48 3
            $exe->execute($config, $io, $repository, $action);
49
50 3
        } catch (\Exception $e) {
51 2
            throw new ActionExecution('Execution failed: ' . $e->getMessage());
52 1
        } catch (\Error $e) {
1 ignored issue
show
Bug introduced by
The class Error does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
53 1
            throw new ActionExecution('PHP Error: ' . $e->getMessage());
54
        }
55 1
    }
56
}
57