Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
16 / 20
20.00% covered (danger)
20.00%
1 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
TemplatePluginBase
80.00% covered (warning)
80.00%
16 / 20
20.00% covered (danger)
20.00%
1 / 5
10.80
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 existsSmartyError
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
3.03
 getSmartyErrors
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 existsSmartyValues
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 getSmartyValues
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\Mvc\Template\Plugin;
6
7use Smarty\Template;
8use PeServer\Core\Collection\Arr;
9use PeServer\Core\Mvc\Template\Plugin\TemplatePluginArgument;
10use PeServer\Core\Throws\InvalidOperationException;
11
12abstract class TemplatePluginBase
13{
14    #region variable
15
16    protected TemplatePluginArgument $argument;
17
18    #endregion
19
20    protected function __construct(TemplatePluginArgument $argument)
21    {
22        $this->argument = $argument;
23    }
24
25    #region function
26
27    /**
28     * エラーが存在するか。
29     *
30     * @param Template $smartyTemplate
31     * @return boolean
32     */
33    protected function existsSmartyError(Template $smartyTemplate): bool
34    {
35        $smarty = $smartyTemplate->getSmarty();
36
37        if (!isset($smarty->tpl_vars['errors'])) {
38            return false;
39        }
40
41        $errors = $smarty->tpl_vars['errors']->value;
42        if (Arr::isNullOrEmpty($errors)) {
43            return false;
44        }
45
46        return true;
47    }
48
49    /**
50     * Undocumented function
51     *
52     * @param Template $smartyTemplate
53     * @return array<string,string[]>
54     */
55    protected function getSmartyErrors(Template $smartyTemplate): array
56    {
57        if ($this->existsSmartyError($smartyTemplate)) {
58            $smarty = $smartyTemplate->getSmarty();
59
60            return $smarty->tpl_vars['errors']->value;
61        }
62
63        throw new InvalidOperationException();
64    }
65
66    protected function existsSmartyValues(Template $smartyTemplate): bool
67    {
68        $smarty = $smartyTemplate->getSmarty();
69
70        if (!isset($smarty->tpl_vars['values'])) {
71            return false;
72        }
73
74        return true;
75    }
76
77    /**
78     * Undocumented function
79     *
80     * @param Template $smartyTemplate
81     * @return array<string,string|string[]|bool|int|object>
82     */
83    protected function getSmartyValues(Template $smartyTemplate): array
84    {
85        if ($this->existsSmartyValues($smartyTemplate)) {
86            $smarty = $smartyTemplate->getSmarty();
87            return $smarty->tpl_vars['values']->value;
88        }
89
90        throw new InvalidOperationException();
91    }
92
93    #endregion
94}