NOSQLManagerTrait::generateForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace NOSQL\Services\Base;
3
4
use NOSQL\Services\Helpers\NOSQLApiHelper;
5
use PSFS\base\dto\JsonResponse;
6
use PSFS\base\types\AuthAdminController;
7
use PSFS\base\types\helpers\ApiFormHelper;
8
9
/**
10
 * Trait NOSQLManagetTrait
11
 * @package NOSQL\Services\base
12
 */
13
trait NOSQLManagerTrait {
14
    /**
15
     * @label Returns form data for any nosql document
16
     * @POST
17
     * @visible false
18
     * @route /admin/api/form/{__DOMAIN__}/{__API__}/nosql
19
     * @return \PSFS\base\dto\JsonResponse(data=\PSFS\base\dto\Form)
20
     * @throws \Exception
21
     */
22
    public function getForm()
23
    {
24
        $form = NOSQLApiHelper::parseForm($this->getModel()->getSchema());
0 ignored issues
show
Bug introduced by
It seems like getModel() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
        $form = NOSQLApiHelper::parseForm($this->/** @scrutinizer ignore-call */ getModel()->getSchema());
Loading history...
25
        $form->actions = ApiFormHelper::checkApiActions(get_called_class(), $this->getDomain(), $this->getApi());
0 ignored issues
show
Bug introduced by
It seems like getDomain() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
        $form->actions = ApiFormHelper::checkApiActions(get_called_class(), $this->/** @scrutinizer ignore-call */ getDomain(), $this->getApi());
Loading history...
Bug introduced by
It seems like getApi() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
        $form->actions = ApiFormHelper::checkApiActions(get_called_class(), $this->getDomain(), $this->/** @scrutinizer ignore-call */ getApi());
Loading history...
26
27
        return $this->_json(new JsonResponse($form->toArray(), TRUE), 200);
0 ignored issues
show
Bug introduced by
It seems like _json() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

27
        return $this->/** @scrutinizer ignore-call */ _json(new JsonResponse($form->toArray(), TRUE), 200);
Loading history...
28
    }
29
30
    protected function generateForm() {
31
32
    }
33
34
    /**
35
     * @label {__API__} NOSQL Manager
36
     * @GET
37
     * @route /admin/{__DOMAIN__}/{__API__}/manager
38
     * @return string HTML
39
     */
40
    public function admin() {
41
        $domain = $this->getDomain();
42
        $api = $this->getApi();
43
        $data = array(
44
            "api" => $api,
45
            "domain" => $this->getDomain(),
46
            "listLabel" => self::API_LIST_NAME_FIELD,
0 ignored issues
show
Bug introduced by
The constant NOSQL\Services\Base\NOSQ...it::API_LIST_NAME_FIELD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
47
            'modelId' => self::NOSQL_MODEL_PRIMARY_KEY,
0 ignored issues
show
Bug introduced by
The constant NOSQL\Services\Base\NOSQ...NOSQL_MODEL_PRIMARY_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
48
            'formUrl' => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('admin-api-form-' . $domain . '-' . $api . '-nosql'), TRUE)),
0 ignored issues
show
Bug introduced by
It seems like getRoute() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

48
            'formUrl' => preg_replace('/\/\{(.*)\}$/i', '', $this->/** @scrutinizer ignore-call */ getRoute(strtolower('admin-api-form-' . $domain . '-' . $api . '-nosql'), TRUE)),
Loading history...
49
            "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower($domain . '-' . 'api-' . $api . "-pk"), TRUE)),
50
        );
51
        return AuthAdminController::getInstance()->render('api.admin.html.twig', $data, [], '');
52
    }
53
}