Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Controller/Admin/Main/ActionYandexCounter.php (1 issue)

Checks if the types of the passed arguments in a function/method call are compatible.

Bug Minor
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
6
use Apps\Model\Admin\Main\FormYandexCounter;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\ForbiddenException;
10
use Ffcms\Core\Helper\Type\Any;
11
use Ffcms\Core\Network\Request;
12
use Ffcms\Core\Network\Response;
13
use Ffcms\Yandex\Metrika\Client;
14
15
/**
16
 * Trait ActionYandexCounter
17
 * @package Apps\Controller\Admin\Main
18
 * @property Request $request
19
 * @property Response $response
20
 * @property View $view
21
 */
22
trait ActionYandexCounter
23
{
24
    /**
25
     * Select counter from api ids
26
     * @return string|null
27
     * @throws ForbiddenException
28
     * @throws \Ffcms\Core\Exception\SyntaxException
29
     */
30
    public function yandexCounter(): ?string
31
    {
32
        $configs = App::$Properties->get('oauth', 'Yandex');
33
34
        $client = new Client($configs['token'], 0);
35
        $counters = $client->getCountersList();
36
37
        // check if counters exist
38
        if (!$counters || !Any::isArray($counters) || count($counters) < 1) {
0 ignored issues
show
$counters of type void is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

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

38
        if (!$counters || !Any::isArray($counters) || count(/** @scrutinizer ignore-type */ $counters) < 1) {
Loading history...
39
            throw new ForbiddenException(__('No active counters found'));
40
        }
41
42
        // initialize select model
43
        $model = new FormYandexCounter($counters);
44
        if ($model->send() && $model->validate()) {
45
            $model->make();
46
            App::$Session->getFlashBag()->add('success', __('Yandex.metrika connected successful'));
47
            $this->response->redirect('main/index');
48
        }
49
50
        return $this->view->render('main/yandex_counter', [
51
            'model' => $model
52
        ]);
53
    }
54
}