ViewWidget::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 15
ccs 7
cts 7
cp 1
crap 1
rs 9.9666
1
<?php
2
/**
3
 * This file is part of the sauls/widget package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Component\Widget;
14
15
use Sauls\Component\Widget\View\Traits\ViewAwareTrait;
16
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
use function Sauls\Component\Helper\array_merge;
20
21
abstract class ViewWidget extends Widget implements ViewWidgetInterface
22
{
23
    use ViewAwareTrait;
24
25 6
    public function render(): string
26
    {
27 6
        return $this->view->render(
28 6
            $this->getOption('viewFile'),
29 6
            array_merge(
30 6
                $this->getOption('viewData'),
31 6
                $this->process()
32
            )
33
        );
34
    }
35
36
    abstract protected function process(): array;
37
38
    /**
39
     * @throws \Exception
40
     */
41 7
    protected function configureOptions(OptionsResolver $resolver): void
42
    {
43
        $resolver
44 7
            ->setDefined(
45
                [
46 7
                    'viewFile',
47
                    'viewData',
48
                ]
49
            )
50 7
            ->addAllowedTypes('viewFile', ['string'])
51 7
            ->addAllowedTypes('viewData', ['array'])
52 7
            ->setDefaults(
53
                [
54 7
                    'viewFile' => '',
55
                    'viewData' => [],
56
                ]
57
            );
58 7
    }
59
}
60