Completed
Push — master ( 82cd1d...312098 )
by Nikolas
163:59 queued 138:22
created

ActionListResource::assembleActions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
namespace rtens\domin\delivery\web\resources;
3
4
use rtens\domin\delivery\web\BreadCrumbsTrail;
5
use rtens\domin\delivery\web\HeadElements;
6
use rtens\domin\delivery\web\WebApplication;
7
8
class ActionListResource {
9
10
    /** @var WebApplication  */
11
    private $app;
12
13
    /** @var BreadCrumbsTrail */
14
    private $crumbs;
15
16
    public function __construct(WebApplication $app, BreadCrumbsTrail $crumbs) {
17
        $this->app = $app;
18
        $this->crumbs = $crumbs;
19
    }
20
21
    /**
22
     * @return string
23
     */
24
    public function handleGet() {
25
        $this->app->prepare();
26
        $this->crumbs->reset();
27
28
        global $model;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
29
        $model = [
30
            'name' => $this->app->name,
31
            'menu' => $this->app->menu->render(),
32
            'action' => $this->assembleActions(),
33
            'headElements' => [
34
                (string)HeadElements::jquery(),
35
                (string)HeadElements::bootstrap(),
36
                (string)HeadElements::bootstrapJs(),
37
            ]
38
        ];
39
40
        ob_start();
41
        include __DIR__ . '/ActionListTemplate.html.php';
42
        return ob_get_clean();
43
    }
44
45
    private function assembleActions() {
46
        $actions = [];
47
        foreach ($this->app->actions->getAllActions() as $id => $action) {
48
            $actions[] = [
49
                'caption' => $action->caption(),
50
                'description' => $this->app->parser->shorten($action->description()),
51
                'link' => ['href' => $id]
52
            ];
53
        }
54
        return $actions;
55
    }
56
}