Passed
Push — feature/136-make-facade-accesi... ( 80b82c...92faa1 )
by Chema
03:31
created

FacadeResolverAwareTrait::classLevelUpNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework;
6
7
use Gacela\Framework\ClassResolver\Facade\FacadeResolver;
8
use function get_class;
9
10
trait FacadeResolverAwareTrait
11
{
12
    private ?AbstractFacade $facade = null;
13
14 1
    protected function getFacade(): AbstractFacade
15
    {
16 1
        if ($this->facade === null) {
17 1
            $this->facade = (new FacadeResolver())
18 1
                ->resolve($this->classLevelUpNamespace());
19
        }
20
21 1
        return $this->facade;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->facade could return the type null which is incompatible with the type-hinted return Gacela\Framework\AbstractFacade. Consider adding an additional type-check to rule them out.
Loading history...
22
    }
23
24
    /**
25
     * @return class-string
1 ignored issue
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
26
     */
27 1
    private function classLevelUpNamespace(): string
28
    {
29 1
        $thisClass = get_class($this);
30
31 1
        return substr($thisClass, 0, (int)strrpos($thisClass, '\\'));
32
    }
33
}
34