Skip to content

Commit ef05879

Browse files
committed
implemented phpstan
Signed-off-by: MarioRadu <[email protected]>
1 parent 42eb847 commit ef05879

16 files changed

+59
-63
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
"laminas/laminas-development-mode": "^3.12.0",
8383
"laminas/laminas-http": "^2.19.0",
8484
"mezzio/mezzio-tooling": "^2.9.0",
85+
"phpstan/phpstan": "^2.0",
86+
"phpstan/phpstan-doctrine": "^2.0",
87+
"phpstan/phpstan-phpunit": "^2.0",
8588
"phpunit/phpunit": "^10.5.10",
8689
"roave/security-advisories": "dev-latest",
8790
"symfony/var-dumper": "^7.1",

phpstan.neon

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
includes:
2+
- vendor/phpstan/phpstan-doctrine/extension.neon
3+
- vendor/phpstan/phpstan-phpunit/extension.neon
4+
parameters:
5+
level: 5
6+
paths:
7+
- src
8+
- test
9+
treatPhpDocTypesAsCertain: false
10+
ignoreErrors:
11+
-
12+
message: '#Call to an undefined method.*setAllowOverride#'
13+
path: test/Functional/AbstractFunctionalTest.php
14+
-
15+
message: '#Call to an undefined method.*setService#'
16+
path: test/Functional/AbstractFunctionalTest.php

src/Admin/src/Service/AdminService.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ public function deleteAdmin(Admin $admin): void
6464

6565
public function exists(string $identity = ''): bool
6666
{
67-
try {
68-
return $this->findOneBy(['identity' => $identity]) instanceof Admin;
69-
} catch (NotFoundException) {
70-
return false;
71-
}
67+
return $this->adminRepository->findOneBy(['identity' => $identity]) instanceof Admin;
7268
}
7369

7470
public function existsOther(string $identity = '', string $uuid = ''): bool

src/App/src/Entity/OAuthAccessToken.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Api\App\Repository\OAuthAccessTokenRepository;
88
use DateTimeImmutable;
99
use Doctrine\Common\Collections\ArrayCollection;
10-
use Doctrine\Common\Collections\Collection;
1110
use Doctrine\Common\Collections\Criteria;
1211
use Doctrine\ORM\Mapping as ORM;
1312
use Lcobucci\JWT\Configuration;
@@ -46,7 +45,7 @@ class OAuthAccessToken implements AccessTokenEntityInterface
4645
#[ORM\JoinTable(name: "oauth_access_token_scopes")]
4746
#[ORM\JoinColumn(name: "access_token_id", referencedColumnName: "id")]
4847
#[ORM\InverseJoinColumn(name: "scope_id", referencedColumnName: "id")]
49-
protected Collection $scopes;
48+
protected ArrayCollection $scopes;
5049

5150
#[ORM\Column(name: 'expires_at', type: "datetime_immutable")]
5251
private DateTimeImmutable $expiresAt;

src/App/src/Entity/OAuthAuthCode.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Api\App\Repository\OAuthAuthCodeRepository;
88
use DateTimeImmutable;
99
use Doctrine\Common\Collections\ArrayCollection;
10-
use Doctrine\Common\Collections\Collection;
1110
use Doctrine\Common\Collections\Criteria;
1211
use Doctrine\ORM\Mapping as ORM;
1312
use League\OAuth2\Server\Entities\AuthCodeEntityInterface;
@@ -39,7 +38,7 @@ class OAuthAuthCode implements AuthCodeEntityInterface
3938
#[ORM\JoinTable(name: "oauth_auth_code_scopes")]
4039
#[ORM\JoinColumn(name: "auth_code_id", referencedColumnName: "id")]
4140
#[ORM\InverseJoinColumn(name: "scope_id", referencedColumnName: "id")]
42-
protected Collection $scopes;
41+
protected ArrayCollection $scopes;
4342

4443
#[ORM\Column(type: "datetime_immutable", nullable: true)]
4544
private DateTimeImmutable $expiresDatetime;
@@ -57,7 +56,7 @@ public function setId(int $id): self
5756
return $this;
5857
}
5958

60-
public function getId(): ?int
59+
public function getId(): int
6160
{
6261
return $this->id;
6362
}
@@ -74,9 +73,9 @@ public function getClient(): ClientEntityInterface
7473
return $this->client;
7574
}
7675

77-
public function getIdentifier(): ?int
76+
public function getIdentifier(): string
7877
{
79-
return $this->getId();
78+
return (string) $this->getId();
8079
}
8180

8281
/**

src/App/src/Entity/OAuthScope.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class OAuthScope implements ScopeEntityInterface
2727
private string $scope = '';
2828

2929
#[ORM\ManyToMany(targetEntity: OAuthAccessToken::class, mappedBy: "scopes")]
30-
protected Collection $accessTokens;
30+
protected ArrayCollection $accessTokens;
3131

3232
#[ORM\ManyToMany(targetEntity: OAuthAuthCode::class, mappedBy: "scopes")]
33-
protected Collection $authCodes;
33+
protected ArrayCollection $authCodes;
3434

3535
public function __construct()
3636
{

src/App/src/Repository/OAuthClientRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getClientEntity($clientIdentifier): ?ClientEntityInterface
5252
public function validateClient($clientIdentifier, $clientSecret, $grantType): bool
5353
{
5454
$client = $this->getClientEntity($clientIdentifier);
55-
if (! $client instanceof ClientEntityInterface) {
55+
if (! $client instanceof OAuthClient) {
5656
return false;
5757
}
5858

src/App/src/UserIdentity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class UserIdentity implements UserInterface
1010
{
1111
protected string $identity;
12-
/** @var iterable<int|string, string> $roles */
12+
/** @var array<int|string, string> $roles */
1313
protected array $roles;
1414
protected array $details;
1515

test/Functional/AbstractFunctionalTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Fig\Http\Message\RequestMethodInterface;
1919
use Fig\Http\Message\StatusCodeInterface;
2020
use Laminas\Diactoros\ServerRequest;
21-
use Laminas\ServiceManager\ServiceManager;
2221
use Mezzio\Application;
2322
use Mezzio\MiddlewareFactory;
2423
use PHPUnit\Framework\TestCase;
@@ -31,7 +30,6 @@
3130

3231
use function array_merge;
3332
use function getenv;
34-
use function method_exists;
3533
use function putenv;
3634
use function realpath;
3735

@@ -41,7 +39,7 @@ class AbstractFunctionalTest extends TestCase
4139
use DatabaseTrait;
4240

4341
protected Application $app;
44-
protected ContainerInterface|ServiceManager $container;
42+
protected ContainerInterface $container;
4543
protected const DEFAULT_PASSWORD = 'dotkernel';
4644

4745
/**
@@ -59,12 +57,8 @@ public function setUp(): void
5957

6058
$this->ensureTestMode();
6159

62-
if (method_exists($this, 'runMigrations')) {
63-
$this->runMigrations();
64-
}
65-
if (method_exists($this, 'runSeeders')) {
66-
$this->runSeeders();
67-
}
60+
$this->runMigrations();
61+
$this->runSeeders();
6862
}
6963

7064
public function tearDown(): void
@@ -132,7 +126,7 @@ protected function getEntityManager(): EntityManagerInterface
132126
return $this->container->get(EntityManagerInterface::class);
133127
}
134128

135-
protected function getContainer(): ContainerInterface|ServiceManager
129+
protected function getContainer(): ContainerInterface
136130
{
137131
return $this->container;
138132
}
@@ -150,7 +144,7 @@ private function ensureTestMode(): void
150144
);
151145
}
152146

153-
if (! $this->getEntityManager()->getConnection()->getParams()['memory'] ?? false) {
147+
if (! ($this->getEntityManager()->getConnection()->getParams()['memory'] ?? false)) {
154148
throw new RuntimeException(
155149
'You are running tests in a non in-memory database. Did you forget to create local.test.php?'
156150
);
@@ -271,7 +265,7 @@ private function createRequest(
271265
string $body = 'php://input',
272266
string $protocol = '1.1'
273267
): ServerRequestInterface {
274-
if (method_exists($this, 'isAuthenticated') && $this->isAuthenticated()) {
268+
if ($this->isAuthenticated()) {
275269
$headers = array_merge($headers, $this->getAuthorizationHeader());
276270
}
277271

test/Unit/Admin/Service/AdminServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
class AdminServiceTest extends TestCase
2222
{
2323
private Subject|MockObject $subject;
24-
private AdminRoleService $adminRoleService;
25-
private AdminRepository $adminRepository;
24+
private AdminRoleService|MockObject $adminRoleService;
25+
private AdminRepository|MockObject $adminRepository;
2626

2727
/**
2828
* @throws \PHPUnit\Framework\MockObject\Exception

0 commit comments

Comments
 (0)