Failed Conditions
Pull Request — 0.2 (#77)
by Rafael
05:21
created

AppsSettingsController::getByKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
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 AppsSettingsController 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
    }
42
43
    /**
44
     * Format output.
45
     *
46
     * @param [type] $results
1 ignored issue
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...
47
     * @return void
48
     */
49
    protected function processOutput($results)
50
    {
51
        //DTOAppsSettings
52
        $this->dtoConfig->registerMapping(Apps::class, AppsSettings::class)
53
          ->forMember('settings', function (Apps $app) {
54
              $settings = [];
55
              foreach ($app->settingsApp->toArray() as $setting) {
56
                  $settings[$setting['name']] = $setting['value'];
57
              }
58
              return $settings;
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 getByKey($key = null): Response
77
    {
78
        //find the info
79
        $record = $this->model->findFirst([
80
            'key = ?0 AND is_deleted = 0',
81
            'bind' => [$key],
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));
1 ignored issue
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