Test Failed
Pull Request — master (#88)
by Maximo
06:27
created

AppsController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 82
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A processOutput() 0 11 2
A getById() 0 12 1
A onConstruct() 0 6 1
A delete() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Api\Controllers;
6
7
use Canvas\Models\Apps;
8
use Canvas\Dto\AppsSettings;
9
use Phalcon\Http\Response;
10
11
/**
12
 * Class LanguagesController.
13
 *
14
 * @package Canvas\Api\Controllers
15
 *
16
 */
17
class AppsController extends BaseController
18
{
19
    /*
20
     * fields we accept to create
21
     *
22
     * @var array
23
     */
24
    protected $createFields = [];
25
26
    /*
27
     * fields we accept to create
28
     *
29
     * @var array
30
     */
31
    protected $updateFields = [];
32
33
    /**
34
     * set objects.
35
     *
36
     * @return void
37
     */
38
    public function onConstruct()
39
    {
40
        $this->model = new Apps();
41
        $this->additionalSearchFields = [
42
            ['is_deleted', ':', '0'],
43
            ['id', ':', implode('|', $this->userData->getAssociatedApps())],
44
        ];
45
    }
46
47
    /**
48
     * Format output.
49
     *
50
     * @param [type] $results
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
51
     * @return void
52
     */
53
    protected function processOutput($results)
54
    {
55
        //DTOAppsSettings
56
        $this->dtoConfig->registerMapping(Apps::class, AppsSettings::class)
57
          ->forMember('settings', function (Apps $app) {
58
              return $app->settingsApp->toArray();
59
          });
60
61
        return is_iterable($results) ?
62
                $this->mapper->mapMultiple(iterator_to_array($results), AppsSettings::class)
63
                : $this->mapper->map($results, AppsSettings::class);
64
    }
65
66
    /**
67
     * get item.
68
     *
69
     * @param mixed $id
70
     *
71
     * @method GET
72
     * @url /v1/data/{id}
73
     *
74
     * @return \Phalcon\Http\Response
75
     */
76
    public function getById($id = null): Response
77
    {
78
        //find the info
79
        $record = $this->model->findFirst([
80
            'id = ?0 AND is_deleted = 0',
81
            'bind' => [$id],
82
        ]);
83
84
        //get the results and append its relationships
85
        $result = $this->appendRelationshipsToResult($this->request, $record);
86
87
        return $this->response($this->processOutput($result));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->processOutput($result) targeting Canvas\Api\Controllers\A...roller::processOutput() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
88
    }
89
90
    /**
91
     * Delete a Record.
92
     *
93
     * @throws Exception
94
     * @return Response
95
     */
96
    public function delete($id): Response
97
    {
98
        return $this->response('Cant delete app at the moment');
99
    }
100
}
101