Completed
Push — master ( 158f00...4ee9ec )
by San
06:17 queued 02:55
created

ClassResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsClass() 0 4 1
B resolveClass() 0 24 2
1
<?php
2
3
namespace Behatch\Context\ContextClass;
4
5
use Behat\Behat\Context\ContextClass\ClassResolver as BaseClassResolver;
6
7
class ClassResolver implements BaseClassResolver
8
{
9
    public function supportsClass($contextClass)
10
    {
11
        return (strpos($contextClass, 'behatch:') === 0);
12
    }
13
14
    public function resolveClass($contextClass)
15
    {
16
        if (strpos($contextClass, 'behatch:context:') === false) {
17
            list(, $className) = explode(':', $contextClass);
18
19
            $className = ucfirst($className);
20
21
            @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
22
                sprintf(
23
                    'Deprecated context alias use behatch:context:%s instead',
24
                    strtolower($className)
25
                ),
26
                E_USER_DEPRECATED
27
            );
28
29
            return "\\Sanpi\\Behatch\\Context\\{$className}Context";
30
        } else {
31
            $className = preg_replace_callback('/(^\w|:\w)/', function ($matches) {
32
                return str_replace(':', '\\', strtoupper($matches[0]));
33
            }, $contextClass);
34
35
            return $className . 'Context';
36
        }
37
    }
38
}
39