Controller::ajaxResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Source\Controllers;
4
5
use CoffeeCode\Optimizer\Optimizer;
0 ignored issues
show
Bug introduced by
The type CoffeeCode\Optimizer\Optimizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use CoffeeCode\Router\Router;
0 ignored issues
show
Bug introduced by
The type CoffeeCode\Router\Router was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use League\Plates\Engine;
0 ignored issues
show
Bug introduced by
The type League\Plates\Engine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
abstract class Controller
10
{
11
    /** @var Engine */
12
    protected $view;
13
14
    /** @var Router */
15
    protected $router;
16
17
    /** @var Optimizer */
18
    protected $seo;
19
20
    /**
21
     * @param ? $router
22
     */
23
    public function __construct($router)
24
    {
25
        $this->router = $router;
26
        $this->view = Engine::create(dirname(__DIR__, 2) . '/views', 'php');
27
        $this->view->addData(['router' => $this->router]);
28
29
        $this->seo = new Optimizer();
30
        $this->seo
31
            ->openGraph(site('name'), site('locale'), 'article')
32
            ->publisher(SOCIAL['facebook_page'], SOCIAL['facebook_author'])
33
            ->twitterCard(SOCIAL['twitter_creator'], SOCIAL['twitter_site'], site('domain'))
34
            ->facebook(SOCIAL['facebook_appId']);
35
    }
36
37
    /**
38
     * @param string $param
39
     * @param array $values
40
     * @return string
41
     */
42
    public function ajaxResponse(string $param, array $values): string
43
    {
44
        return json_encode([$param => $values]);
45
    }
46
47
    /**
48
     * @param array $data
49
     * @return void
50
     */
51
    public function send(array $data): void
52
    {
53
        echo json_encode($data);
54
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
55
    }
56
}
57