SsrRender   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 45
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 8 1
A filter() 0 15 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: polidog
5
 * Date: 2017/02/22.
6
 */
7
8
namespace Polidog\SsrBundle\Render;
9
10
use Koriym\Baracoa\BaracoaInterface;
11
use Polidog\SsrBundle\Annotations\Ssr;
12
13
class SsrRender implements SsrRenderInterface
14
{
15
    /**
16
     * @var BaracoaInterface
17
     */
18
    private $baracoa;
19
20
    /**
21
     * SsrRender constructor.
22
     *
23
     * @param BaracoaInterface $baracoa
24
     */
25 1
    public function __construct(BaracoaInterface $baracoa)
26
    {
27 1
        $this->baracoa = $baracoa;
28 1
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function render(Ssr $ssr, array $parameters)
34
    {
35 1
        return $this->baracoa->render(
36 1
            $ssr->getApp(),
37 1
            $this->filter($ssr->getState(), $parameters),
38 1
            $this->filter($ssr->getMetas(), $parameters)
39
        );
40
    }
41
42 1
    private function filter(array $keys, array $parameters)
43
    {
44 1
        if ($keys === ['*']) {
45
            return $parameters;
46
        }
47
48 1
        $errorKeys = array_keys(array_diff(array_values($keys), array_keys($parameters)));
49 1
        if ($errorKeys) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errorKeys of type integer[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
50
            throw new \LogicException(implode(',', $errorKeys));
51
        }
52
53 1
        return array_filter((array) $parameters, function($key) use ($keys) {
54 1
            return in_array($key, $keys);
55 1
        }, ARRAY_FILTER_USE_KEY);
56
    }
57
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
58