Skip to content

Commit b4778ba

Browse files
committed
add PHPStan
1 parent dcf4c44 commit b4778ba

10 files changed

Lines changed: 135 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,6 @@ jobs:
8282

8383
- name: Run PHP CodeSniffer
8484
run: vendor/bin/phpcs --report=checkstyle | cs2pr
85+
86+
- name: Run PHPStan
87+
run: vendor/bin/phpstan analyse -c phpstan.neon --error-format=checkstyle | cs2pr

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"mobiledetect/mobiledetectlib": "^4.8.03"
1818
},
1919
"require-dev": {
20+
"cakedc/cakephp-phpstan": "^4.0",
2021
"cakephp/bake": "^3.0.0",
2122
"cakephp/cakephp-codesniffer": "^5.0",
2223
"cakephp/debug_kit": "^5.0.0",
@@ -61,6 +62,8 @@
6162
"cs-fix": "phpcbf --colors -p",
6263
"test": "phpunit --colors=always",
6364
"annotate": "bin/cake annotate all",
64-
"illuminate": "bin/cake illuminate code"
65+
"illuminate": "bin/cake illuminate code",
66+
"phpstan": "phpstan analyse",
67+
"phpstan-baseline": "phpstan --generate-baseline"
6568
}
6669
}

composer.lock

Lines changed: 111 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/.env.ddev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ export DATABASE_URL="mysql://db:db@db:3306/db"
3636
# Uncomment these to define logging configuration via environment variables.
3737
#export LOG_DEBUG_URL="file:///path/to/logs/?levels[]=notice&levels[]=info&levels[]=debug&file=debug"
3838
#export LOG_ERROR_URL="file:///path/to/logs/?levels[]=warning&levels[]=error&levels[]=critical&levels[]=alert&levels[]=emergency&file=error"
39-
export DEBUG_KIT_SAFE_TLD="site"
4039
export APP_FULL_BASE_URL="https://plugins.cakephp.org.ddev.site"
40+
export DEBUG_KIT_SAFE_TLD="site"

phpstan.neon

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
includes:
2+
- vendor/cakedc/cakephp-phpstan/extension.neon
3+
14
parameters:
2-
level: 8
5+
level: 5
36
treatPhpDocTypesAsCertain: false
4-
checkGenericClassInNonGenericObjectType: false
57
bootstrapFiles:
68
- config/bootstrap.php
79
paths:

src/Command/SyncPackagesCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public function execute(Arguments $args, ConsoleIo $io)
127127
}
128128

129129
// Remove packages that were not touched
130+
/** @var \Cake\ORM\ResultSet<array-key, \App\Model\Entity\Package> $toDeletePackages */
130131
$toDeletePackages = $packagesTable->find()->where(['id NOT IN' => $touchedIds])->all();
131132
foreach ($toDeletePackages as $package) {
132133
if (!$packagesTable->delete($package)) {
@@ -241,7 +242,7 @@ private function hasExplicitCakePhpDependency(array $tags): bool
241242
* @param array $meta The meta array to adjust
242243
* @param string $packageConstraint The meta array which contains the current version strings
243244
* @param string $tagPrefix The prefix which should be used for the tag
244-
* @param array<string, array<int>> $versions The versions to check
245+
* @param array<array-key, array<int>> $versions The versions to check
245246
* @return array
246247
*/
247248
private function appendVersionTags(

src/Controller/PackagesController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function autocomplete(): Response
113113
->withStringBody(json_encode([], JSON_THROW_ON_ERROR));
114114
}
115115

116+
/** @var \Cake\ORM\ResultSet<array-key, \App\Model\Entity\Package> $packages */
116117
$packages = $this->Packages
117118
->find('autocomplete', search: $q)
118119
->all();
@@ -174,8 +175,9 @@ protected function hasActiveFilterValue(mixed $value): bool
174175
}
175176

176177
/**
177-
* @param array<string, string> $tags
178-
* @return array<string, string>
178+
* @param array $tags
179+
* @param string $prefix
180+
* @return array
179181
*/
180182
protected function sortVersionTags(array $tags, string $prefix): array
181183
{

src/Event/AfterGithubIdentify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function implementedEvents(): array
3636
*/
3737
public function afterIdentify(EventInterface $event, User $user): void
3838
{
39-
$token = $user->social_profile->access_token?->getToken();
39+
$token = $user->social_profile->access_token->getToken();
4040
if (!$token) {
4141
return;
4242
}

src/Model/Entity/Package.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ protected function groupVersionTags(array $tags, string $prefix): array
103103
continue;
104104
}
105105

106-
$majorVersion = $matches[1];
106+
$majorVersion = intval($matches[1]);
107107
$groups[$majorVersion][] = $tag;
108108
}
109109

110-
uksort($groups, static function (string $left, string $right): int {
111-
return version_compare($right, $left);
110+
uksort($groups, static function (int $left, int $right): int {
111+
return version_compare((string)$right, (string)$left);
112112
});
113113

114114
foreach ($groups as &$groupedTags) {

src/Model/Table/UsersTable.php

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

44
namespace App\Model\Table;
55

6+
use ADmad\SocialAuth\Model\Entity\SocialProfile;
67
use Cake\Datasource\EntityInterface;
78
use Cake\Http\Session;
89
use Cake\ORM\RulesChecker;
@@ -102,6 +103,7 @@ public function buildRules(RulesChecker $rules): RulesChecker
102103
*/
103104
public function getUser(EntityInterface $profile, Session $session): mixed
104105
{
106+
assert($profile instanceof SocialProfile);
105107
// Make sure here that all the required fields are actually present
106108
if (!$profile->email) {
107109
throw new RuntimeException('Could not find email in social profile.');

0 commit comments

Comments
 (0)