Passed
Push — master ( 0456bd...25822b )
by Mihail
07:10
created

ActionYandexToken::yandexToken()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 2
nop 0
dl 0
loc 15
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
6
use Apps\Model\Admin\Main\FormYandexToken;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Helper\Date;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionYandexToken
15
 * @package Apps\Controller\Admin\Main
16
 * @property Request $request
17
 * @property Response $response
18
 * @property View $view
19
 */
20
trait ActionYandexToken
21
{
22
    /**
23
     * @return string|null
24
     * @throws \Ffcms\Core\Exception\SyntaxException
25
     */
26
    public function yandexToken(): ?string
27
    {
28
        $cfg = App::$Properties->getAll('Yandex');
29
30
        $model = new FormYandexToken($cfg);
0 ignored issues
show
Bug introduced by zenn
It seems like $cfg can also be of type null; however, parameter $configs of Apps\Model\Admin\Main\Fo...dexToken::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        $model = new FormYandexToken(/** @scrutinizer ignore-type */ $cfg);
Loading history...
31
        if ($model->send() && $model->validate()) {
32
            $model->make();
33
            App::$Session->getFlashBag()->add('success', __('Token saved successful. Valid until: %date%', [
34
                'date' => Date::convertToDatetime(time() + $model->expires, Date::FORMAT_TO_DAY)
35
            ]));
36
            $this->response->redirect('main/yandexcounter');
37
        }
38
39
        return $this->view->render('main/yandex_token', [
40
            'model' => $model
41
        ]);
42
    }
43
}