1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace Gewaer\Api\Controllers; |
||||
6 | |||||
7 | use Gewaer\Models\Companies; |
||||
8 | use Phalcon\Http\Response; |
||||
9 | use Exception; |
||||
10 | |||||
11 | /** |
||||
12 | * Base controller |
||||
13 | * |
||||
14 | */ |
||||
15 | class CompaniesController extends BaseController |
||||
16 | { |
||||
17 | /* |
||||
18 | * fields we accept to create |
||||
19 | * |
||||
20 | * @var array |
||||
21 | */ |
||||
22 | protected $createFields = ['name', 'profile_image', 'website', 'users_id', 'created_at', 'updated_at']; |
||||
23 | |||||
24 | /* |
||||
25 | * fields we accept to create |
||||
26 | * |
||||
27 | * @var array |
||||
28 | */ |
||||
29 | protected $updateFields = ['name', 'profile_image', 'website', 'users_id', 'created_at', 'updated_at']; |
||||
30 | |||||
31 | /** |
||||
32 | * set objects |
||||
33 | * |
||||
34 | * @return void |
||||
35 | */ |
||||
36 | public function onConstruct() |
||||
37 | { |
||||
38 | $this->model = new Companies(); |
||||
39 | |||||
40 | $this->additionalSearchFields = [ |
||||
41 | ['users_id', ':', $this->userData->getId()], |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||
42 | ]; |
||||
43 | } |
||||
44 | |||||
45 | /** |
||||
46 | * Get Uer |
||||
47 | * |
||||
48 | * @param mixed $id |
||||
49 | * |
||||
50 | * @method GET |
||||
51 | * @url /v1/company/{id} |
||||
52 | * |
||||
53 | * @return Phalcon\Http\Response |
||||
0 ignored issues
–
show
|
|||||
54 | */ |
||||
55 | public function getById($id) : Response |
||||
56 | { |
||||
57 | //find the info |
||||
58 | $company = $this->model->findFirst([ |
||||
59 | 'id = ?0 AND is_deleted = 0 and users_id = ?1', |
||||
60 | 'bind' => [$id, $this->userData->getId()], |
||||
0 ignored issues
–
show
The property
userData does not exist on Gewaer\Api\Controllers\CompaniesController . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
61 | ]); |
||||
62 | |||||
63 | //get relationship |
||||
64 | if ($this->request->hasQuery('relationships')) { |
||||
65 | $relationships = $this->request->getQuery('relationships', 'string'); |
||||
66 | |||||
67 | $company = QueryParser::parseRelationShips($relationships, $company); |
||||
0 ignored issues
–
show
The type
Gewaer\Api\Controllers\QueryParser 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
68 | } |
||||
69 | |||||
70 | if ($company) { |
||||
71 | return $this->response($company); |
||||
0 ignored issues
–
show
|
|||||
72 | } else { |
||||
73 | throw new Exception('Record not found'); |
||||
74 | } |
||||
75 | } |
||||
76 | |||||
77 | /** |
||||
78 | * Update a User Info |
||||
79 | * |
||||
80 | * @method PUT |
||||
81 | * @url /v1/company/{id} |
||||
82 | * |
||||
83 | * @return Phalcon\Http\Response |
||||
84 | */ |
||||
85 | public function edit($id) : Response |
||||
86 | { |
||||
87 | $company = $this->model->findFirst([ |
||||
88 | 'id = ?0 AND is_deleted = 0 and users_id = ?1', |
||||
89 | 'bind' => [$id, $this->userData->getId()], |
||||
0 ignored issues
–
show
The property
userData does not exist on Gewaer\Api\Controllers\CompaniesController . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
90 | ]); |
||||
91 | |||||
92 | if ($company) { |
||||
93 | $request = $this->request->getPut(); |
||||
0 ignored issues
–
show
The method
getPut() does not exist on Phalcon\Http\RequestInterface . Did you maybe mean getPost() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
94 | |||||
95 | if (empty($request)) { |
||||
96 | $request = $this->request->getJsonRawBody(true); |
||||
97 | } |
||||
98 | |||||
99 | //update |
||||
100 | if ($company->update($request, $this->updateFields)) { |
||||
101 | return $this->response($company); |
||||
0 ignored issues
–
show
|
|||||
102 | } else { |
||||
103 | //didnt work |
||||
104 | throw new Exception(current($company->getMessages())); |
||||
105 | } |
||||
106 | } else { |
||||
107 | throw new Exception('Record not found'); |
||||
108 | } |
||||
109 | } |
||||
110 | } |
||||
111 |