Passed
Push — master ( 1aebda...f0b7fa )
by Saulius
03:44
created

Fqcn   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 7 2
1
<?php
2
/**
3
 * This file is part of the sauls/helpers package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Component\Helper\Operation\ClassOperation;
14
15
class Fqcn implements FqcnInterface
16
{
17 4
    public function execute(string $value): string
18
    {
19 4
        if (preg_match('~([^\\\\]+?)(type)?$~i', $value, $matches)) {
20 4
            return strtolower(preg_replace(
21 4
                ['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'],
22 4
                ['\\1_\\2', '\\1_\\2'],
23 4
                $matches[1]
24
            ));
25
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 19 is false. This is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
26
    }
27
}
28