Completed
Pull Request — master (#11)
by
unknown
09:54
created

CompileRenderWhenDirective   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 16
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 6 1
1
<?php
2
3
namespace Spatie\ViewComponents;
4
5
final class CompileRenderWhenDirective
6
{
7
    private $compileRenderDirective;
8
9
    public function __construct(CompileRenderDirective $compileRenderDirective)
10
    {
11
        $this->compileRenderDirective = $compileRenderDirective;
12
    }
13
14
    public function __invoke(string $expression): string
15
    {
16
        $expressionParts = explode(',', $expression, 2);
17
18
        return "<?php if({$expressionParts[0]}): ?> {$this->compileRenderDirective->__invoke($expressionParts[1])} <?php endif; ?>";
19
    }
20
}
21