Skip to content

Commit aceaafa

Browse files
committed
(chore) code quality improvements
1 parent 14cddbe commit aceaafa

22 files changed

+132
-78
lines changed

phpstan.neon

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,25 @@ parameters:
22
level: 4
33
autoload_files:
44
- tests/bootstrap.php
5+
ignoreErrors:
6+
-
7+
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
8+
path: 'src/Service/Action/Auth/RegisterAction.php'
9+
-
10+
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
11+
path: 'src/Service/Action/Auth/ResetPasswordAction.php'
12+
-
13+
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
14+
path: 'src/Service/Action/Auth/ResetPasswordRequestAction.php'
15+
-
16+
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
17+
path: 'src/Service/Action/Auth/SocialLoginAction.php'
18+
-
19+
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
20+
path: 'src/Service/Action/Auth/ValidateAccountAction.php'
21+
-
22+
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
23+
path: 'src/Service/Action/Auth/ValidateAccountRequestAction.php'
24+
-
25+
message: '#PHPDoc tag @throws with type PHPUnit.*#'
26+
path: 'src/TestSuite/IntegrationTestCase.php'

src/Controller/ApiController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace CakeDC\Api\Controller;
1515

1616
use Cake\Core\Configure;
17+
use Cake\Http\Response;
1718
use Cake\Utility\Inflector;
1819
use CakeDC\Api\Service\ConfigReader;
1920
use CakeDC\Api\Service\ServiceRegistry;
@@ -45,7 +46,7 @@ public function initialize(): void
4546
/**
4647
* Process api request
4748
*
48-
* @return \Cake\Http\Client\Response|\Cake\Http\Response|null
49+
* @return \Cake\Http\Response|null
4950
*/
5051
public function process()
5152
{
@@ -84,9 +85,9 @@ public function describe(): void
8485
* Process api request
8586
*
8687
* @param array $options Options
87-
* @return \Cake\Http\Client\Response|\Cake\Http\Response|null
88+
* @return \Cake\Http\Response|null
8889
*/
89-
protected function _process(array $options = []): \Cake\Http\Response
90+
protected function _process(array $options = []): ?Response
9091
{
9192
$routesInflectorMethod = Configure::read('Api.routesInflectorMethod', 'underscore');
9293

src/Routing/ApiRouter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace CakeDC\Api\Routing;
1515

16+
use Cake\Routing\Route\Route;
1617
use Cake\Routing\Router;
1718

1819
/**
@@ -32,9 +33,9 @@ class ApiRouter extends Router
3233
/**
3334
* Default route class.
3435
*
35-
* @var bool
36+
* @var string
3637
*/
37-
protected static $_defaultRouteClass = 'Cake\Routing\Route\Route';
38+
protected static $_defaultRouteClass = Route::class;
3839

3940
/**
4041
* Contains the base string that will be applied to all generated URLs

src/Service/Action/Action.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public function implementedEvents(): array
325325
/**
326326
* Returns action input params
327327
*
328-
* @return mixed
328+
* @return array
329329
*/
330330
public function getData(): array
331331
{

src/Service/Action/CrudAction.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ abstract class CrudAction extends Action
4242
*/
4343
protected $_id = null;
4444

45+
/**
46+
* Object Identifier name
47+
*
48+
* @var string
49+
*/
4550
protected $_idName = 'id';
4651

4752
/**
@@ -60,6 +65,11 @@ abstract class CrudAction extends Action
6065
*/
6166
protected $_parentId = null;
6267

68+
/**
69+
* Parent Object Identifier name
70+
*
71+
* @var string
72+
*/
6373
protected $_parentIdName = null;
6474

6575
/**
@@ -117,7 +127,7 @@ public function __construct(array $config = [])
117127
*
118128
* @return \Cake\ORM\Table
119129
*/
120-
public function getTable(): \Cake\ORM\Table
130+
public function getTable(): Table
121131
{
122132
return $this->_table;
123133
}
@@ -148,7 +158,7 @@ public function getService()
148158
*
149159
* @return mixed|string
150160
*/
151-
public function getId(): string
161+
public function getId()
152162
{
153163
return $this->_id;
154164
}
@@ -168,17 +178,17 @@ public function getIdName(): string
168178
*
169179
* @return mixed|string
170180
*/
171-
public function getParentId(): string
181+
public function getParentId()
172182
{
173183
return $this->_parentId;
174184
}
175185

176186
/**
177187
* Parent model id field name getter.
178188
*
179-
* @return mixed|string
189+
* @return string
180190
*/
181-
public function getParentIdName()
191+
public function getParentIdName(): string
182192
{
183193
return $this->_parentIdName;
184194
}
@@ -188,7 +198,7 @@ public function getParentIdName()
188198
*
189199
* @return \Cake\Datasource\EntityInterface
190200
*/
191-
protected function _newEntity(): \Cake\Datasource\EntityInterface
201+
protected function _newEntity(): EntityInterface
192202
{
193203
$entity = $this->getTable()->newEntity([]);
194204

@@ -201,9 +211,9 @@ protected function _newEntity(): \Cake\Datasource\EntityInterface
201211
* @param \Cake\Datasource\EntityInterface $entity An Entity instance.
202212
* @param array $data Entity data.
203213
* @param array $options Patch entity options.
204-
* @return \Cake\Datasource\EntityInterface|mixed
214+
* @return \Cake\Datasource\EntityInterface
205215
*/
206-
protected function _patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
216+
protected function _patchEntity(EntityInterface $entity, array $data, array $options = []): EntityInterface
207217
{
208218
$entity = $this->getTable()->patchEntity($entity, $data, $options);
209219
$event = $this->dispatchEvent('Action.Crud.onPatchEntity', compact('entity'));

src/Service/Action/DescribeAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DescribeAction extends Action
2828
/**
2929
* Apply validation process.
3030
*
31-
* @return bool|array
31+
* @return bool
3232
*/
3333
public function validates(): bool
3434
{

src/Service/Action/DummyAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DummyAction extends Action
2323
/**
2424
* Apply validation process.
2525
*
26-
* @return bool|array
26+
* @return bool
2727
*/
2828
public function validates(): bool
2929
{

src/Service/Action/Extension/Extension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ abstract class Extension
2727

2828
protected $_defaultConfig = [];
2929

30+
/**
31+
* ExtensionRegistry instance.
32+
*
33+
* @var ExtensionRegistry
34+
*/
35+
protected $_registry;
36+
3037
/**
3138
* Extension constructor.
3239
*
@@ -35,6 +42,7 @@ abstract class Extension
3542
*/
3643
public function __construct(ExtensionRegistry $registry, array $config = [])
3744
{
45+
$this->_registry = $registry;
3846
$this->setConfig($config);
3947
}
4048
}

src/Service/Action/Extension/PaginateExtension.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
namespace CakeDC\Api\Service\Action\Extension;
1515

16-
use Cake\Event\Event;
16+
use Cake\Event\EventInterface;
1717
use Cake\Event\EventListenerInterface;
18+
use Cake\ORM\Query;
1819
use CakeDC\Api\Service\Action\Action;
1920

2021
/**
@@ -47,11 +48,12 @@ public function implementedEvents(): array
4748
/**
4849
* Find entities
4950
*
50-
* @param \Cake\Event\Event $event An Event instance
51-
* @return \Cake\ORM\Entity
51+
* @param \Cake\Event\EventInterface $event An Event instance
52+
* @return \Cake\ORM\Query
5253
*/
53-
public function findEntities(Event $event): \Cake\ORM\Query
54+
public function findEntities(EventInterface $event): Query
5455
{
56+
/** @var Action $action */
5557
$action = $event->getSubject();
5658
$query = $event->getData('query');
5759
if ($event->getResult()) {
@@ -106,11 +108,12 @@ protected function _limit(Action $action)
106108
/**
107109
* after find entities
108110
*
109-
* @param \Cake\Event\Event $event An Event instance
111+
* @param \Cake\Event\EventInterface $event An Event instance
110112
* @return void
111113
*/
112-
public function afterFind(Event $event): void
114+
public function afterFind(EventInterface $event): void
113115
{
116+
/** @var Action $action */
114117
$action = $event->getSubject();
115118
$query = $event->getData('query');
116119
$result = $action->getService()->getResult();

src/Service/Action/ExtensionRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(?Action $action = null)
4949
* Should resolve the classname for a given object type.
5050
*
5151
* @param string $class The class to resolve.
52-
* @return string|false The resolved name or false for failure.
52+
* @return string|null The resolved name or false for failure.
5353
*/
5454
protected function _resolveClassName($class): ?string
5555
{

src/Service/Action/Result.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ public function appendPayload(string $key, $value): void
151151
* Gets a result payload.
152152
*
153153
* @param string $key Payload key.
154-
* @return array|mixed Payload
154+
* @return array|null|mixed Payload
155155
*/
156-
public function getPayload(?string $key = null): ?array
156+
public function getPayload(?string $key = null)
157157
{
158158
if ($key === null) {
159159
return $this->_payload;

src/Service/Auth/Auth.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ class Auth
4949
use LogTrait;
5050
use StorageTrait;
5151

52+
/**
53+
* Constant for 'all'
54+
*
55+
* @var string
56+
*/
57+
public const ALL = 'all';
58+
5259
/**
5360
* Actions for which user validation is not required.
5461
*

src/Service/Auth/Authenticate/BaseAuthenticate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ abstract class BaseAuthenticate implements EventListenerInterface
8282
/**
8383
* Password hasher instance.
8484
*
85-
* @var \Cake\Auth\AbstractPasswordHasher
85+
* @var \Cake\Auth\AbstractPasswordHasher|null
8686
*/
8787
protected $_passwordHasher;
8888

@@ -133,7 +133,7 @@ protected function _findUser($username, $password = null)
133133
}
134134

135135
$this->_needsPasswordRehash = $hasher->needsRehash($hashedPassword);
136-
$result->unsetProperty($this->_config['fields']['password']);
136+
$result->unset($this->_config['fields']['password']);
137137
}
138138

139139
return $result->toArray();
@@ -183,7 +183,7 @@ protected function _query($username)
183183
*/
184184
public function passwordHasher()
185185
{
186-
if ($this->_passwordHasher) {
186+
if ($this->_passwordHasher !== null) {
187187
return $this->_passwordHasher;
188188
}
189189

src/Service/Auth/Authenticate/SocialAuthenticate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getUser(ServerRequest $request)
103103
$this->_config['fields']['username'] = 'id';
104104
$this->_config['finder'] = 'all';
105105

106-
$result = $this->_query($socialAccount->user_id)->first();
106+
$result = $this->_query($socialAccount['user_id'])->first();
107107
if (empty($result)) {
108108
return false;
109109
}
@@ -137,7 +137,7 @@ protected function _socialQuery($provider, $token, $tokenSecret)
137137
* Get the api key from the querystring
138138
*
139139
* @param \Cake\Http\ServerRequest $request request
140-
* @return string api key
140+
* @return array api key
141141
*/
142142
public function querystring(ServerRequest $request)
143143
{
@@ -152,7 +152,7 @@ public function querystring(ServerRequest $request)
152152
* Get the api key from the header
153153
*
154154
* @param \Cake\Http\ServerRequest $request request
155-
* @return string api key
155+
* @return array api key
156156
*/
157157
public function header(ServerRequest $request)
158158
{

0 commit comments

Comments
 (0)