Skip to content

Commit f687b20

Browse files
committed
Fix errors reported by phpstan and psalm.
1 parent 9a550b2 commit f687b20

File tree

8 files changed

+56
-51
lines changed

8 files changed

+56
-51
lines changed

.editorconfig

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ end_of_line = crlf
1515

1616
[*.yml]
1717
indent_style = space
18-
indent_size = 2
18+
indent_size = 2
19+
20+
[*.neon]
21+
indent_style = tab

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
php-version: '7.4'
8585
extensions: mbstring, intl
8686
coverage: none
87-
tools: psalm:^4.6, phpstan:^0.12
87+
tools: psalm:^4.7, phpstan:^0.12
8888

8989
- name: Composer Install
9090
run: composer require cakephp/cakephp-codesniffer:^4.2

phpstan.neon

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
parameters:
2-
level: 6
3-
checkMissingIterableValueType: false
4-
checkGenericClassInNonGenericObjectType: false
5-
ignoreErrors:
6-
-
7-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:callFinder\\(\\)\\.$#"
8-
count: 1
9-
path: src/Datasource/Query.php
2+
level: 6
3+
checkMissingIterableValueType: false
4+
checkGenericClassInNonGenericObjectType: false
5+
paths:
6+
- src/
7+
ignoreErrors:
8+
-
9+
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:callFinder\\(\\)\\.$#"
10+
count: 1
11+
path: src/Datasource/Query.php
1012

11-
-
12-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:getName\\(\\)\\.$#"
13-
count: 1
14-
path: src/Datasource/Query.php
13+
-
14+
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:getName\\(\\)\\.$#"
15+
count: 1
16+
path: src/Datasource/Query.php
1517

16-
-
17-
message: "#^Cannot call method total\\(\\) on Cake\\\\Datasource\\\\ResultSetInterface\\|int\\<1, max\\>\\|int\\<min, \\-1\\>\\|true\\.$#"
18-
count: 1
19-
path: src/Datasource/Query.php
18+
-
19+
message: "#^Cannot call method total\\(\\) on Cake\\\\Datasource\\\\ResultSetInterface\\|int\\<min, \\-1\\>\\|int\\<1, max\\>\\|true\\.$#"
20+
count: 1
21+
path: src/Datasource/Query.php

psalm.xml

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<DocblockTypeContradiction errorLevel="info" />
2323
<RedundantConditionGivenDocblockType errorLevel="info" />
2424

25+
<UnsafeInstantiation errorLevel="info" />
26+
2527
<UnresolvableInclude errorLevel="info" />
2628
</issueHandlers>
2729
</psalm>

src/Datasource/Marshaller.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,9 @@ public function mergeMany($entities, array $data, array $options = []): array
284284
})
285285
->toArray();
286286

287-
/** @psalm-suppress NullArrayOffset */
287+
/** @psalm-suppress NullArrayOffset, InvalidArrayOffset */
288288
$new = $indexed[null] ?? [];
289-
/**
290-
* @psalm-suppress PossiblyNullArrayOffset
291-
* @psalm-suppress NullArrayOffset
292-
*/
289+
/** @psalm-suppress PossiblyNullArrayOffset, InvalidArrayOffset */
293290
unset($indexed[null]);
294291
$output = [];
295292

src/Datasource/Query.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -328,22 +328,22 @@ public function action(int $action)
328328
*
329329
* Pages should start at 1.
330330
*
331-
* @param int $page The page number you want.
331+
* @param int $num The page number you want.
332332
* @param int $limit The number of rows you want in the page. If null
333333
* the current limit clause will be used.
334334
* @return $this
335335
*/
336-
public function page(int $page, ?int $limit = null)
336+
public function page(int $num, ?int $limit = null)
337337
{
338-
if ($page < 1) {
338+
if ($num < 1) {
339339
throw new InvalidArgumentException('Pages must start at 1.');
340340
}
341341

342342
if ($limit !== null) {
343343
$this->limit($limit);
344344
}
345345

346-
$this->_parts['page'] = $page;
346+
$this->_parts['page'] = $num;
347347

348348
return $this;
349349
}
@@ -558,6 +558,7 @@ protected function _execute(): ResultSetInterface
558558
return new $decorator($this->__resultSet);
559559
}
560560

561+
/** @var \Cake\Datasource\ResultSetInterface */
561562
return $this->__resultSet = $this->_webservice->execute($this);
562563
}
563564

src/Model/Endpoint.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public function getPrimaryKey()
414414
{
415415
if ($this->_primaryKey === null) {
416416
$schema = $this->getSchema();
417-
$key = (array)$schema->primaryKey();
417+
$key = $schema->primaryKey();
418418
if (count($key) === 1) {
419419
$key = $key[0];
420420
}
@@ -886,53 +886,53 @@ public function exists($conditions): bool
886886
* returns the same resource after a successful save or false in case
887887
* of any error.
888888
*
889-
* @param \Cake\Datasource\EntityInterface $resource the resource to be saved
889+
* @param \Cake\Datasource\EntityInterface $entity the resource to be saved
890890
* @param array|\ArrayAccess $options The options to use when saving.
891891
* @return \Cake\Datasource\EntityInterface|false
892892
*/
893-
public function save(EntityInterface $resource, $options = [])
893+
public function save(EntityInterface $entity, $options = [])
894894
{
895895
$options = new ArrayObject((array)$options + [
896896
'checkRules' => true,
897897
'checkExisting' => false,
898898
]);
899899

900-
if ($resource->getErrors()) {
900+
if ($entity->getErrors()) {
901901
return false;
902902
}
903903

904-
if ($resource->isNew() === false && !$resource->isDirty()) {
905-
return $resource;
904+
if ($entity->isNew() === false && !$entity->isDirty()) {
905+
return $entity;
906906
}
907907

908908
$primaryColumns = (array)$this->getPrimaryKey();
909909

910-
if ($options['checkExisting'] && $primaryColumns && $resource->isNew() && $resource->has($primaryColumns)) {
910+
if ($options['checkExisting'] && $primaryColumns && $entity->isNew() && $entity->has($primaryColumns)) {
911911
$alias = $this->getAlias();
912912
$conditions = [];
913-
foreach ($resource->extract($primaryColumns) as $k => $v) {
913+
foreach ($entity->extract($primaryColumns) as $k => $v) {
914914
$conditions["$alias.$k"] = $v;
915915
}
916-
$resource->setNew(!$this->exists($conditions));
916+
$entity->setNew(!$this->exists($conditions));
917917
}
918918

919-
$mode = $resource->isNew() ? RulesChecker::CREATE : RulesChecker::UPDATE;
920-
if ($options['checkRules'] && !$this->checkRules($resource, $mode, $options)) {
919+
$mode = $entity->isNew() ? RulesChecker::CREATE : RulesChecker::UPDATE;
920+
if ($options['checkRules'] && !$this->checkRules($entity, $mode, $options)) {
921921
return false;
922922
}
923923

924-
$event = $this->dispatchEvent('Model.beforeSave', compact('resource', 'options'));
924+
$event = $this->dispatchEvent('Model.beforeSave', compact('entity', 'options'));
925925

926926
if ($event->isStopped()) {
927927
return $event->getResult();
928928
}
929929

930-
$data = $resource->extract($this->getSchema()->columns(), true);
930+
$data = $entity->extract($this->getSchema()->columns(), true);
931931

932-
if ($resource->isNew()) {
932+
if ($entity->isNew()) {
933933
$query = $this->query()->create();
934934
} else {
935-
$query = $this->query()->update()->where($resource->extract($primaryColumns));
935+
$query = $this->query()->update()->where($entity->extract($primaryColumns));
936936
}
937937
$query->set($data);
938938

@@ -941,14 +941,14 @@ public function save(EntityInterface $resource, $options = [])
941941
return false;
942942
}
943943

944-
if ($resource->isNew() && ($result instanceof EntityInterface)) {
944+
if ($entity->isNew() && ($result instanceof EntityInterface)) {
945945
return $result;
946946
}
947947

948948
/** @psalm-var class-string<\Cake\Datasource\EntityInterface> $className */
949-
$className = get_class($resource);
949+
$className = get_class($entity);
950950

951-
return new $className($resource->toArray(), [
951+
return new $className($entity->toArray(), [
952952
'markNew' => false,
953953
'markClean' => true,
954954
]);
@@ -957,14 +957,14 @@ public function save(EntityInterface $resource, $options = [])
957957
/**
958958
* Delete a single resource.
959959
*
960-
* @param \Cake\Datasource\EntityInterface $resource The resource to remove.
960+
* @param \Cake\Datasource\EntityInterface $entity The resource to remove.
961961
* @param array|\ArrayAccess $options The options for the delete.
962962
* @return bool
963963
*/
964-
public function delete(EntityInterface $resource, $options = []): bool
964+
public function delete(EntityInterface $entity, $options = []): bool
965965
{
966966
$primaryKeys = (array)$this->getPrimaryKey();
967-
$values = $resource->extract($primaryKeys);
967+
$values = $entity->extract($primaryKeys);
968968

969969
return (bool)$this->query()->delete()->where(array_combine($primaryKeys, $values))->execute();
970970
}

src/Model/EndpointLocator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class EndpointLocator extends AbstractLocator
2020
* Set an Endpoint instance to the locator.
2121
*
2222
* @param string $alias The alias to set.
23-
* @param \Muffin\Webservice\Model\Endpoint $object The table to set.
23+
* @param \Muffin\Webservice\Model\Endpoint $repository The repository to set.
2424
* @return \Muffin\Webservice\Model\Endpoint
2525
* @psalm-suppress MoreSpecificImplementedParamType
2626
* @psalm-suppress MoreSpecificReturnType
2727
*/
28-
public function set(string $alias, RepositoryInterface $object): Endpoint
28+
public function set(string $alias, RepositoryInterface $repository): Endpoint
2929
{
30-
return $this->instances[$alias] = $object;
30+
return $this->instances[$alias] = $repository;
3131
}
3232

3333
/**

0 commit comments

Comments
 (0)