Completed
Pull Request — master (#36)
by Daniel
03:38
created

ScalarType::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\ViewInterface;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
use Psi\Component\ContentType\View\TypeInterface;
11
use Psi\Component\ContentType\View\TypeFactory;
12
use Psi\Component\ContentType\View\ViewFactory;
13
14
class ScalarType implements TypeInterface
15
{
16
    public function createView(ViewFactory $factory, $data, array $options): ViewInterface
17
    {
18 View Code Duplication
        if (null !== $data && !is_scalar($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...
19
            throw new \InvalidArgumentException(sprintf(
20
                'Scalar view only accepts scalar values! Got "%s"',
21
                is_object($data) ? get_class($data) : gettype($data)
22
            ));
23
        }
24
25
        return new ScalarView($options['template'], $data);
26
    }
27
28
    public function configureOptions(OptionsResolver $options)
29
    {
30
        $options->setDefault('template', 'psi/scalar');
31
    }
32
}
33