Completed
Push — master ( cefc4c...542ee6 )
by Daniel
06:07 queued 01:38
created

BooleanType::createView()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 6
Ratio 46.15 %

Importance

Changes 0
Metric Value
dl 6
loc 13
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 3
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\ContentType\Standard\View;
6
7
use Psi\Component\ContentType\View\View;
8
use Psi\Component\ContentType\View\ViewFactory;
9
use Psi\Component\ContentType\View\ViewInterface;
10
11
class BooleanType extends ScalarType
12
{
13
    public function createView(ViewFactory $factory, $data, array $options): ViewInterface
14
    {
15 View Code Duplication
        if (null !== $data && !is_bool($data)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
            throw new \InvalidArgumentException(sprintf(
17
                'Boolean view only accepts boolean values! Got "%s"',
18
                is_object($data) ? get_class($data) : gettype($data)
19
            ));
20
        }
21
22
        $data = $data ? 'true' : 'false';
23
24
        return new ScalarView($data, $options['tag'], $options['raw']);
25
    }
26
}
27